diff --git a/.claude/launch.json b/.claude/launch.json index 2ecd649..81df002 100644 --- a/.claude/launch.json +++ b/.claude/launch.json @@ -69,6 +69,12 @@ "dev:admin" ], "port": 5174 + }, + { + "name": "editor-bridge", + "runtimeExecutable": "npm", + "runtimeArgs": ["run", "dev", "-w", "@docwell/editor-bridge", "--", "--port", "5180", "--strictPort"], + "port": 5180 } ] } diff --git a/Packages/editor-bridge/dist/index.html b/Packages/editor-bridge/dist/index.html index f3934fd..6c22fee 100644 --- a/Packages/editor-bridge/dist/index.html +++ b/Packages/editor-bridge/dist/index.html @@ -9,28 +9,28 @@ `)}};fe.empty=new fe(!0);var pe=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function me(e){let t=[];do t.push(he(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function he(e){let t=[];do t.push(ge(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function ge(e){let t=be(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=ve(e,t);else break;return t}function _e(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function ve(e,t){let n=_e(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:_e(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function ye(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function be(e){if(e.eat(`(`)){let t=me(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=ye(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function xe(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new fe(r.indexOf(e.length-1)>-1);for(let e=0;e-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:De(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new ce(this,this.computeAttrs(e),s.from(t),d.setFrom(n))}createChecked(e=null,t,n){return t=s.from(t),this.checkContent(t),new ce(this,this.computeAttrs(e),t,d.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=s.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(s.empty,!0);return i?new ce(this,e,t.append(i),d.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function Ae(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var je=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?Ae(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},Me=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=Oe(e,r.attrs),this.excluded=null;let i=Ee(this.attrs);this.instance=i?new d(this,i):null}create(e=null){return!e&&this.instance?this.instance:new d(this,De(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t-1}},Ne=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=n.from(e.nodes),t.marks=n.from(e.marks||{}),this.nodes=ke.compile(this.spec.nodes,this),this.marks=Me.compile(this.spec.marks,this);let r=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],n=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=r[n]||(r[n]=fe.parse(n,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?Pe(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:Pe(this,n.split(` `))}this.nodeFromJSON=e=>ce.fromJSON(this,e),this.markFromJSON=e=>d.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof ke))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new le(n,n.defaultAttrs,e,d.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function Pe(e,t){let n=[];for(let r=0;r-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function Fe(e){return e.tag!=null}function Ie(e){return e.style!=null}var Le=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(Fe(e))this.tags.push(e);else if(Ie(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new Ke(this,t,!1);return n.addAll(e,d.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Ke(this,t,!0);return n.addAll(e,d.none,t.from,t.to),p.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;re.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r{n(e=Ye(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=Ye(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},Re={address:!0,article:!0,aside:!0,blockquote:!0,body:!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},ze={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Be={ol:!0,ul:!0},Ve=1,He=2,Ue=4;function We(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?Ve:0)|(t===`full`?He:0)}var Ge=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=d.none,this.match=i||(a&Ue?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(s.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ve)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=s.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(s.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&&!Re.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Ke=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=We(null,t.preserveWhitespace,0)|(n?Ue:0);i=r?new Ge(r.type,r.attrs,d.none,!0,t.topMatch||r.type.contentMatch,a):n?new Ge(null,null,d.none,!0,null,a):new Ge(e.schema.topNodeType,null,d.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&He?`full`:this.localPreserveWS||(r.options&Ve)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,` `);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node){if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e!(a.type?a.type.allowsMarkType(t.type):Xe(t.type,e))||(s=t.addToSet(s),!1)),this.nodes.push(new Ge(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=Ve);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function qe(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&Be.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function Je(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function Ye(e){let t={};for(let n in e)t[n]=e[n];return t}function Xe(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n{if(i.length||e.marks.length){let n=0,a=0;for(;n=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&rt($e(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t==`string`?{dom:e.createTextNode(t)}:rt(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=Qe(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return Qe(e.marks)}};function Qe(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function $e(e){return e.document||window.document}var et=new WeakMap;function tt(e){let t=et.get(e);return t===void 0&&et.set(e,t=nt(e)),t}function nt(e){let t=null;function n(e){if(e&&typeof e==`object`){if(Array.isArray(e)){if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;iu)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}if(typeof a==`string`)c.appendChild(e.createTextNode(a));else{let{dom:t,contentDOM:i}=rt(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var it=65535,at=2**16;function ot(e,t){return e+t*at}function st(e){return e&it}function ct(e){return(e-(e&it))/at}var lt=1,ut=2,dt=4,ft=8,pt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&ft)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&dt)>0}},mt=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=st(e);if(!this.inverted)for(let e=0;ee)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:ot(o/3,e-s),f=0;return c&&(f|=e==s?ut:e==u?lt:dt,(t<0?e!=s:e!=u)&&(f|=ft)),new pt(a,f,d)}r+=l-c}return n?e+r:new pt(e+r,0,null)}touches(e,t){let n=0,r=st(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;te)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;nn&&t!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return vt.fromReplace(e,this.from,this.to,i)}invert(t){let n=[];return t.nodesBetween(this.from,this.to,(t,r)=>{if(t.isInline&&t.isAtom){let i=this.mark.addToSet(t.marks);if(!d.sameSet(i,t.marks)){let a=Math.max(this.from,r),o=Math.min(this.to,r+t.nodeSize);St(xt,a,o,this.mark,n);for(let r of t.marks)r.isInSet(i)||St(e,a,o,r,n)}}}),n.length==1?n[0]:new Ct(n)}map(t){let n=t.map(this.from,1),r=t.map(this.to,-1);return n>=r?null:new e(n,r,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};_t.jsonID(`addMark`,bt);var xt=class e extends _t{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new p(yt(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return vt.fromReplace(e,this.from,this.to,n)}invert(e){let t=[];return e.nodesBetween(this.from,this.to,(e,n)=>{e.isInline&&e.isAtom&&this.mark.isInSet(e.marks)&&St(bt,Math.max(this.from,n),Math.min(this.to,n+e.nodeSize),this.mark,t)}),t.length==1?t[0]:new Ct(t)}map(t){let n=t.map(this.from,1),r=t.map(this.to,-1);return n>=r?null:new e(n,r,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};_t.jsonID(`removeMark`,xt);function St(e,t,n,r,i){let a=i.length?i[i.length-1]:null;a&&a instanceof e&&a.to==t&&a.mark.eq(r)?i[i.length-1]=new e(a.from,n,r):i.push(new e(t,n,r))}var Ct=class e extends _t{constructor(e){super(),this.steps=e}apply(e){for(let t of this.steps){let n=t.apply(e);if(!n.doc)return n;e=n.doc}return new vt(e,null)}invert(t){return new e(this.steps.map(e=>e.invert(t)))}map(t){let n=[];for(let e of this.steps){let r=e.map(t);r&&n.push(r)}return n.length?new e(n):null}toJSON(){return{stepType:`markSet`,steps:this.steps.map(e=>e.toJSON())}}static fromJSON(t,n){if(!Array.isArray(n.steps)||!n.steps.every(e=>e.stepType==`addMark`||e.stepType==`removeMark`))throw RangeError(`Invalid JSON for MarkSetStep`);return new e(n.steps.map(e=>_t.fromJSON(t,e)))}};_t.jsonID(`markSet`,Ct);var wt=class e extends _t{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return vt.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return vt.fromReplace(e,this.pos,this.pos+1,new p(s.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;rr.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,p.fromJSON(t,n.slice),n.insert,!!n.structure)}};_t.jsonID(`replaceAround`,Dt);function Ot(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function kt(e,t,n,r){let i=[];e.doc.nodesBetween(t,n,(e,a,o)=>{if(!e.isInline)return;let s=e.marks;!r.isInSet(s)&&o.type.allowsMarkType(r.type)&&St(bt,Math.max(a,t),Math.min(a+e.nodeSize,n),r,i)}),i.forEach(t=>e.step(t))}function At(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline||!e.isAtom)return;a++;let s=null;if(r instanceof Me){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;ee.step(new xt(t.from,t.to,t.style)))}function jt(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],c=t+1;for(let t=0;t=0;t--)e.step(o[t])}function Mt(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function Nt(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(nn;e--)t||r.index(e)>0?(t=!0,d=s.from(r.node(e).copy(d)),f++):l--;let m=s.empty,h=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=s.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new Dt(i,a,i,a,new p(r,0,0),n.length,!0))}function Bt(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&Ut(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&Ht(e,t,n,a),jt(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let c=e.mapping.slice(a),l=c.map(n,1),u=c.map(n+t.nodeSize,1);return e.step(new Dt(l,u,l+1,u-1,new p(s.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&Vt(e,t,n,a),!1}})}function Vt(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function Ht(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(` -`))}})}function Ut(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Wt(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let o=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,o);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new Dt(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new p(s.from(o),0,0),1,!0))}function Gt(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function Kt(e,t,n=1,r){let i=e.doc.resolve(t),a=s.empty,o=s.empty;for(let e=i.depth,t=i.depth-n,c=n-1;e>t;e--,c--){a=s.from(i.node(e).copy(a));let t=r&&r[c];o=s.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new Et(t,t,new p(a.append(o),n,n),!0))}function qt(e,t){let n=e.resolve(t),r=n.index();return Yt(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Jt(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i0?(i=r.node(e+1),o++,a=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),a=r.node(e+1)),i&&!i.isTextblock&&Yt(i,a)&&r.node(e).canReplace(o,o+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function Zt(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);Ht(e,r.node(),r.before(),s)}o.inlineContent&&jt(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new Et(l,c.map(t+n,-1),p.empty,!0)),r===!0){let t=e.doc.resolve(l);Vt(e,t.node(),t.before(),e.steps.length)}return e}function Qt(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,a=r.index(t)+ +(n>0),o=r.node(t),s=!1;if(e==1)s=o.canReplace(a,a,i);else{let e=o.contentMatchAt(a).findWrapping(i.firstChild.type);s=e&&o.canReplaceWith(a,a,e[0])}if(s)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function en(e,t,n=t,r=p.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return tn(i,a,r)?new Et(t,n,r):new nn(i,a,r).fit()}function tn(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var nn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=s.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=s.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new p(i,a,o);return e>-1?new Dt(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new Et(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=on(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:o}=this.frontier[e],c,l=null;if(t==1&&(i?o.matchType(i.type)||(l=o.fillBefore(s.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:l};if(t==2&&i&&(c=o.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:c};if(r&&o.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return dn(e,-1)<=t?!1:(this.unplaced.size>1&&dn(e,1)>n&&n++,this.unplaced=new p(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=on(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new p(rn(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new p(rn(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e1||c==0||e.content.size)&&(d=t,u.push(sn(e.mark(f.allowedMarks(e.marks)),l==1?c:0,l==o.childCount?m:-1)))}let h=l==o.childCount;h||(m=-1),this.placed=an(this.placed,t,s.from(u)),this.frontier[t].match=d,h&&m<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t=0;n--){let{match:t,type:r}=this.frontier[n],i=cn(e,n,r,t,!0);if(!i||i.childCount)continue scan}return{depth:t,fit:a,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=an(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=an(this.placed,this.depth,s.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(s.empty,!0);e.childCount&&(this.placed=an(this.placed,this.frontier.length,e))}};function rn(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(rn(e.firstChild.content,t-1,n)))}function an(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(an(e.lastChild.content,t-1,n)))}function on(e,t){for(let n=0;n1&&(r=r.replaceChild(0,sn(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(s.empty,!0)))),e.copy(r)}function cn(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!ln(n,a.content,o)?s:null}function ln(e,t,n){for(let r=n;r0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=un(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function pn(e,t,n,r,i){if(tr){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(s.empty,!0))}return e}function mn(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=Qt(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new p(s.from(r),0,0))}function hn(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let a=r.sharedDepth(n),o=!1;for(let e=r.depth;e>a;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>a;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let a=gn(r,i);for(let t=0;t0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function gn(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(rt.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var _n=class e extends _t{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return vt.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return vt.fromReplace(e,this.pos,this.pos+1,new p(s.from(r),0,+!t.isLeaf))}getMap(){return mt.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};_t.jsonID(`attr`,_n);var vn=class e extends _t{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return vt.ok(n)}getMap(){return mt.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};_t.jsonID(`docAttr`,vn);var yn=class extends Error{};yn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},yn.prototype=Object.create(Error.prototype),yn.prototype.constructor=yn,yn.prototype.name=`TransformError`;var bn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ht}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new yn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n{e=Math.min(e,i),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=p.empty){let r=en(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new p(s.from(n),0,0))}delete(e,t){return this.replace(e,t,p.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return fn(this,e,t,n),this}replaceRangeWith(e,t,n){return mn(this,e,t,n),this}deleteRange(e,t){return hn(this,e,t),this}lift(e,t){return Pt(this,e,t),this}join(e,t=1){return Zt(this,e,t),this}wrap(e,t){return zt(this,e,t),this}setBlockType(e,t=e,n,r=null){return Bt(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return Wt(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new _n(e,t,n)),this}setDocAttribute(e,t){return this.step(new vn(e,t)),this}addNodeMark(e,t){return this.step(new wt(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof d)t.isInSet(n.marks)&&this.step(new Tt(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new Tt(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return Kt(this,e,t,n),this}addMark(e,t,n){return kt(this,e,t,n),this}removeMark(e,t,n){return At(this,e,t,n),this}clearIncompatible(e,t,n){return jt(this,e,t,n),this}},xn=Object.create(null),w=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Sn(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;r--){let i=t<0?kn(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):kn(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Dn(e.node(0))}static atStart(e){return kn(e,e,0,0,1)||new Dn(e)}static atEnd(e){return kn(e,e,e.content.size,e.childCount,-1)||new Dn(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=xn[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in xn)throw RangeError(`Duplicate use of selection JSON ID `+e);return xn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return T.between(this.$anchor,this.$head).getBookmark()}};w.prototype.visible=!0;var Sn=class{constructor(e,t){this.$from=e,this.$to=t}},Cn=!1;function wn(e){!Cn&&!e.parent.inlineContent&&(Cn=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var T=class e extends w{constructor(e,t=e){wn(e),wn(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return w.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=p.empty){if(super.replace(e,t),t==p.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Tn(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=w.findFrom(n,r,!0)||w.findFrom(n,-r,!0);if(e)n=e.$head;else return w.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(w.findFrom(t,-r,!0)||w.findFrom(t,r,!0)).$anchor,t.pos0?0:1);i>0?o=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=kn(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&E.isSelectable(r))return E.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function An(e,t,n){let r=e.steps.length-1;if(r{o??=r}),e.setSelection(w.near(e.doc.resolve(o),n))}var jn=1,Mn=2,Nn=4,Pn=class extends bn{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|=Mn,this}ensureMarks(e){return d.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&Mn)>0}addStep(e,t){super.addStep(e,t),this.updated&=-3,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||d.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(w.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|=Nn,this}get scrolledIntoView(){return(this.updated&Nn)>0}};function Fn(e,t){return!t||!e?e:e.bind(t)}var In=class{constructor(e,t,n){this.name=e,this.init=Fn(t.init,n),this.apply=Fn(t.apply,n)}},Ln=[new In(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new In(`selection`,{init(e,t){return e.selection||w.atStart(t.doc)},apply(e){return e.selection}}),new In(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new In(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],Rn=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ln.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new In(e.key,e.spec.state,e))})}},zn=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;ne.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new Rn(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=ce.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=w.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function Bn(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=Bn(i,t,{})),n[r]=i}return n}var D=class{constructor(e){this.spec=e,this.props={},e.props&&Bn(e.props,this,this.props),this.key=e.key?e.key.key:Hn(`plugin`)}getState(e){return e[this.key]}},Vn=Object.create(null);function Hn(e){return e in Vn?e+`$`+ ++Vn[e]:(Vn[e]=0,e+`$`)}var Un=class{constructor(e=`key`){this.key=Hn(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},Wn=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Gn(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var Kn=(e,t,n)=>{let r=Gn(e,n);if(!r)return!1;let i=Qn(r);if(!i){let n=r.blockRange(),i=n&&Nt(n);return i!=null&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(gr(e,i,t,-1))return!0;if(r.parent.content.size==0&&(Xn(a,`end`)||E.isSelectable(a)))for(let n=r.depth;;n--){let o=en(e.doc,r.before(n),r.after(n),p.empty);if(o&&o.slice.size1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1},qn=(e,t,n)=>{let r=Gn(e,n);if(!r)return!1;let i=Qn(r);return i?Yn(e,i,t):!1},Jn=(e,t,n)=>{let r=$n(e,n);if(!r)return!1;let i=nr(r);return i?Yn(e,i,t):!1};function Yn(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let a=t.nodeAfter,o=t.pos+1;for(;!a.isTextblock;o++){if(a.type.spec.isolating)return!1;let e=a.firstChild;if(!e)return!1;a=e}let s=en(e.doc,i,o,p.empty);if(!s||s.from!=i||s instanceof Et&&s.slice.size>=o-i)return!1;if(n){let t=e.tr.step(s);t.setSelection(T.create(t.doc,i)),n(t.scrollIntoView())}return!0}function Xn(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Zn=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=Qn(r)}let o=a&&a.nodeBefore;return!o||!E.isSelectable(o)?!1:(t&&t(e.tr.setSelection(E.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function Qn(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function $n(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset{let r=$n(e,n);if(!r)return!1;let i=nr(r);if(!i)return!1;let a=i.nodeAfter;if(gr(e,i,t,1))return!0;if(r.parent.content.size==0&&(Xn(a,`start`)||E.isSelectable(a))){let n=en(e.doc,r.before(),r.after(),p.empty);if(n&&n.slice.size{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset=0;t--){let n=e.node(t);if(e.index(t)+1{let n=e.selection,r=n instanceof E,i;if(r){if(n.node.isTextblock||!qt(e.doc,n.from))return!1;i=n.from}else if(i=Xt(e.doc,n.from,-1),i==null)return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(E.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},ir=(e,t)=>{let n=e.selection,r;if(n instanceof E){if(n.node.isTextblock||!qt(e.doc,n.to))return!1;r=n.to}else if(r=Xt(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},ar=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&Nt(i);return a!=null&&(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},or=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(` -`).scrollIntoView()),!0)};function sr(e){for(let t=0;t{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=sr(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(w.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},lr=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof Dn||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=sr(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index(){let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Gt(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Nt(r);return i!=null&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function dr(e){return(t,n)=>{if(t.selection instanceof E&&t.selection.node.isBlock){let{$from:e}=t.selection;return!e.parentOffset||!Gt(t.doc,e.pos)?!1:(n&&n(t.tr.split(e.pos).scrollIntoView()),!0)}if(!t.selection.$from.depth)return!1;let r=t.tr;!t.selection.empty&&(t.selection instanceof T||t.selection instanceof Dn)&&r.deleteSelection();let{$from:i}=r.selection,a=r.steps.length,o=[],s,c,l=!1,u=!1;for(let t=i.depth;;t--)if(i.node(t).isBlock){l=i.end(t)==i.pos+(i.depth-t),u=i.start(t)==i.pos-(i.depth-t),c=sr(i.node(t-1).contentMatchAt(i.indexAfter(t-1)));let n=e&&e(i.parent,l,i);o.unshift(n||(l&&c?{type:c}:null)),s=t;break}else{if(t==1)return!1;o.unshift(null)}let d=i.pos,f=Gt(r.doc,d,o.length,o);if(f||=(o[0]=c?{type:c}:null,Gt(r.doc,d,o.length,o)),!f)return!1;if(r.split(d,o.length,o),!l&&u&&i.node(s).type!=c){let e=r.mapping.slice(a),t=e.map(i.before(s)),n=r.doc.resolve(t);c&&i.node(s-1).canReplaceWith(n.index(),n.index()+1,c)&&r.setNodeMarkup(e.map(i.before(s)),c)}return n&&n(r.scrollIntoView()),!0}}var fr=dr(),pr=(e,t)=>{let{$from:n,to:r}=e.selection,i,a=n.sharedDepth(r);return a!=0&&(i=n.before(a),t&&t(e.tr.setSelection(E.create(e.doc,i))),!0)},mr=(e,t)=>(t&&t(e.tr.setSelection(new Dn(e.doc))),!0);function hr(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||qt(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function gr(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,o,c,l=i.type.spec.isolating||a.type.spec.isolating;if(!l&&hr(e,t,n))return!0;let u=!l&&t.parent.canReplace(t.index(),t.index()+1);if(u&&(o=(c=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&c.matchType(o[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,c=s.empty;for(let e=o.length-1;e>=0;e--)c=s.from(o[e].create(null,c));c=s.from(i.copy(c));let l=e.tr.step(new Dt(t.pos-1,r,t.pos,r,new p(c,1,0),o.length,!0)),u=l.doc.resolve(r+2*o.length);u.nodeAfter&&u.nodeAfter.type==i.type&&qt(l.doc,u.pos)&&l.join(u.pos),n(l.scrollIntoView())}return!0}let d=a.type.spec.isolating||r>0&&l?null:w.findFrom(t,1),f=d&&d.$from.blockRange(d.$to),m=f&&Nt(f);if(m!=null&&m>=t.depth)return n&&n(e.tr.lift(f,m).scrollIntoView()),!0;if(u&&Xn(a,`start`,!0)&&Xn(i,`end`)){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let c=a,l=1;for(;!c.isTextblock;c=c.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,c.content)){if(n){let r=s.empty;for(let e=o.length-1;e>=0;e--)r=s.from(o[e].copy(r));n(e.tr.step(new Dt(t.pos-o.length,t.pos+a.nodeSize,t.pos+l,t.pos+a.nodeSize-l,new p(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function _r(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(T.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var vr=_r(-1),yr=_r(1);function br(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&Ft(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function xr(e,t=null){return function(n,r){let i=!1;for(let r=0;r{if(i)return!1;if(r.isTextblock&&!r.hasMarkup(e,t)){if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new oe(e,e,t.depth),t.endIndex=0;e--)a=s.from(n[e].type.create(n[e].attrs,a));e.step(new Dt(t.start-(r?2:0),t.end,t.start,t.end,new p(a,0,0),n.length,!0));let o=0;for(let e=0;e-1}function jr(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&Ar(e,t.firstChild.type));return a?n?Ar(e,r.node(a.depth-1).type)?Mr(t,n,a):Nr(t,n,a):!0:!1}}function Mr(e,t,n){let r=e.tr,i=n.end,a=n.$to.end(n.depth),o=n.parent.child(n.endIndex-1).type;ia;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let c=n.startIndex==0,l=n.endIndex==i.childCount,u=a.node(-1),d=a.index(-1);if(!u.canReplace(d+ +!c,d+1,o.content.append(l?s.empty:s.from(i))))return!1;let f=a.pos,m=f+o.nodeSize;return r.step(new Dt(f-+!!c,m+ +!!l,f+1,m-1,new p((c?s.empty:s.from(i.copy(s.empty))).append(l?s.empty:s.from(i.copy(s.empty))),+!c,+!l),+!c)),t(r.scrollIntoView()),!0}function Pr(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&Ar(e,t.firstChild.type));if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let c=a.parent,l=c.child(o-1);if(!Ar(e,l.type))return!1;if(n){let e=l.lastChild&&l.lastChild.type==c.type,r=s.from(e?l.lastChild.lastChild.type.create():null),i=new p(s.from(l.type.create(null,s.from(c.type.create(null,r)))),e?3:1,0),o=a.start,u=a.end;n(t.tr.step(new Dt(o-(e?3:1),u,o,u,i,1,!0)).scrollIntoView())}return!0}}var Fr=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},Ir=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},Lr=null,Rr=function(e,t,n){let r=Lr||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},zr=function(){Lr=null},Br=function(e,t,n,r){return n&&(Hr(e,t,n,r,-1)||Hr(e,t,n,r,1))},Vr=/^(img|br|input|textarea|hr)$/i;function Hr(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Ur(e))){let n=e.parentNode;if(!n||!O(n)||Yr(e)||Vr.test(e.nodeName)||e.contentEditable==`false`)return!1;t=Fr(e)+(i<0?0:1),e=n}else if(O(e)){let n=e.childNodes[t+(i<0?-1:0)];if(O(n)&&n.contentEditable==`false`){if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1}else e=n,t=i<0?Ur(e):0}else return!1}}function Ur(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function O(e){return e.nodeType==1}function Wr(e){return e.nodeType==3}function Gr(e,t){return t?e.contains(O(t)?t:t.parentNode):!1}function Kr(e,t){for(;;){if(Wr(e)&&t)return e;if(O(e)&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=Ur(e)}else if(e.parentNode&&!Yr(e))t=Fr(e),e=e.parentNode;else return null}}function qr(e,t){for(;;){if(Wr(e)&&t2),mi=pi||(ei?/Mac/.test(ei.platform):!1),hi=ei?/Win/.test(ei.platform):!1,gi=/Android \d/.test(ni),_i=!!ti&&`webkitFontSmoothing`in ti.documentElement.style,vi=_i?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function yi(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function bi(e,t){return typeof e==`number`?e:e[t]}function xi(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function Si(e,t,n){if(!Li(t)&&t.left==0)return;let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(!O(o)){o=Ir(o);continue}let e=o==a.body,n=e?yi(a):xi(o),s=0,c=0;if(t.topn.bottom-bi(r,`bottom`)&&(c=t.bottom-t.top>n.bottom-n.top?t.top+bi(i,`top`)-n.top:t.bottom-n.bottom+bi(i,`bottom`)),t.leftn.right-bi(r,`right`)&&(s=t.right-n.right+bi(i,`right`)),s||c){if(e)a.defaultView.scrollBy(s,c);else{let e=o.scrollLeft,n=o.scrollTop;c&&(o.scrollTop+=c),s&&(o.scrollLeft+=s);let r=o.scrollLeft-e,i=o.scrollTop-n;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}}let l=e?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(l))break;o=l==`absolute`?o.offsetParent:Ir(o)}}function Ci(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:wi(e.dom)}}function wi(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=Ir(r));return t}function Ti({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;Ei(n,r==0?0:r-t)}function Ei(e,t){for(let n=0;n=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right=(p.left+p.right)/2));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&Wr(n)?Ai(n,i):!n||r?{node:e,offset:a}:ki(n,i)}function Ai(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}function ji(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function Mi(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,a)}function Pi(e,t,n,r){let i=-1;for(let n=t,a=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(O(t.dom)&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!a&&o.left>r.left||o.top>r.top?i=t.posBefore:(!a&&o.right-1?i:e.docView.posFromDOM(t,n,-1)}function Fi(e,t,n){let r=e.childNodes.length;if(r&&n.topt.top&&i++}let n;_i&&i&&O(r)&&O(n=r.childNodes[i-1])&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&O(r.lastChild)&&t.top>r.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:i!=0&&O(r)&&r.childNodes[i-1].nodeName==`BR`||(s=Pi(e,r,i,t))}s??=Ni(e,o,t);let c=e.docView.nearestDesc(o,!0);return{pos:s,inside:c?c.posAtStart-c.border:-1}}function Li(e){return e.top=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,Vi(Ri(Rr(r,e,t),a),a<0)}}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==Ur(r))){let e=r.childNodes[i-1];if(O(e))return Hi(e.getBoundingClientRect(),!1)}if(a==null&&i=0)}if(a==null&&i&&(n<0||i==Ur(r))){let e=r.childNodes[i-1],t=Wr(e)?Rr(e,Ur(e)-+!o):O(e)&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return Vi(Ri(t,1),!1)}if(a==null&&i=0)}function Vi(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function Hi(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function Ui(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Wi(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return Ui(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=Bi(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(O(e))t=e.getClientRects();else if(Wr(e))t=Rr(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;ei.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var Gi=/[\u0590-\u08ac]/;function Ki(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!Gi.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:Ui(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:a,anchorOffset:o}=e.domSelectionRange(),c=s.caretBidiLevel;s.modify(`move`,n,`character`);let l=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:u,focusOffset:d}=e.domSelectionRange(),f=u&&!Gr(l,u)||t==u&&i==d;try{s.collapse(a,o),t&&(t!=a||i!=o)&&s.extend&&s.extend(t,i)}catch{}return c!=null&&(s.caretBidiLevel=c),f}):r.pos==r.start()||r.pos==r.end()}var qi=null,Ji=null,Yi=!1;function Xi(e,t,n){return qi==t&&Ji==n?Yi:(qi=t,Ji=n,Yi=n==`up`||n==`down`?Wi(e,t,n):Ki(e,t,n))}var Zi=0,Qi=1,$i=2,ea=3,ta=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=Zi,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tFr(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){let n=e.compareDocumentPosition(this.contentDOM);r=n&16?t>Array.from(e.childNodes).findIndex(e=>e.contains(this.contentDOM)):!(n&4)}else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node)){if(n&&(a=i.nodeDOM)&&!(O(a)?Gr(a,e):a==e))n=!1;else return i}}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(;n>0;n--){let e=this.children[n-1];if(e.size||!(e instanceof ca||e instanceof na&&e.side>=0))break}if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Fr(e.dom)+1:0}}{let e,r=!0;for(;e=n=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=Fr(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;es&&at){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r=n:en){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?$i:Qi,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=ea:i.markDirty(e-r,t-r);return}i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?$i:ea}n=a}this.dirty=$i}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?$i:Qi;t.dirty{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){let e=O(a)?a:document.createElement(`span`);e!=a&&(e.appendChild(a),a=e),e.hasAttribute(`contenteditable`)||(e.contentEditable=`false`),e.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==Zi&&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}},ra=class extends ta{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},ia=class e extends ta{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return o&&o.dom||(o=Ze.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&ea||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ea&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Zi){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty0&&(a=Ta(a,0,t,r));for(let e=0;e{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(!Wr(u))throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=Ze.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=ga(u,r,n),l?c=new la(t,n,r,i,u,d||null,f,l):n.isText?new sa(t,n,r,i,u,f):new e(t,n,r,i,u,d||null,f)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(t.preserveWhitespace=`full`),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let e=this.children.length-1;e>=0;e--){let n=this.children[e];if(this.dom.contains(n.dom.parentNode)){t.contentElement=n.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(t=>O(t)&&e.indexOf(t.parentNode)<0&&this.dom.contains(t));n?t.contentElement=n:t.getContent=()=>s.empty}}return t}matchesNode(e,t,n){return this.dirty==Zi&&e.eq(this.node)&&_a(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new ya(this,a&&a.node,e),c=this.node.inlineContent,l=c&&this.node.isBlock;Sa(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?d.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,u,d)=>{s.syncToMarks(t.marks,n,e,d),l&&t.isAtom&&!t.isText&&s.addHackNode(`IMG`,s.top);let f;s.findNodeMatch(t,a,u,d)||o&&e.state.selection.from>r&&e.state.selection.to-1&&s.updateNodeAt(t,a,u,f,e)||s.updateNextNode(t,a,u,e,d,r)||s.addNode(t,a,u,e,r),r+=t.nodeSize,c&&(l=t.isAtom&&!t.isText)}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==$i)&&(a&&this.protectLocalComposition(e,a),ua(this.contentDOM,this.children,e),pi&&Ca(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof T)||nt+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=wa(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let a=new ra(this,i,t,r);e.input.compositionNodes.push(a),this.children=Ta(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==ea||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Zi}updateOuterDeco(e){if(_a(e,this.outerDeco))return;let t=!O(this.nodeDOM),n=this.dom;this.dom=ma(this.dom,this.nodeDOM,pa(this.outerDeco,this.node,t),pa(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){O(this.nodeDOM)&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){O(this.nodeDOM)&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function oa(e,t,n,r,i){ga(r,t,e);let a=new aa(void 0,e,t,n,r,r,r);return a.contentDOM&&a.updateChildren(i,0),a}var sa=class e extends aa{constructor(e,t,n,r,i,a){super(e,t,n,r,i,null,a)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==ea||this.dirty!=Zi&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Zi||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=Zi,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=ea)}get domAtom(){return!1}isText(e){return this.node.text==e}},ca=class extends ta{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Zi&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},la=class extends aa{constructor(e,t,n,r,i,a,o,s){super(e,t,n,r,i,a,o),this.spec=s}update(e,t,n,r){if(this.dirty==ea)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function ua(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a>1,o=Math.min(a,e.length);for(;i-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=ia.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof ia)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function xa(e,t){return e.type.side-t.type.side}function Sa(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;na;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function Ca(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function wa(e,t,n,r){for(let i=0,a=0;i=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function Ta(e,t,n,r,i){let a=[];for(let o=0,s=0;o=n||u<=t?a.push(c):(ln&&a.push(c.slice(n-l,c.size,r)))}return a}function Ea(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(Xr(n)){for(c=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&E.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&Jr(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new E(o==e?s:r.resolve(e))}else if(ci&&t==`key`&&o>e.state.selection.to&&O(n.focusNode)&&n.focusOffset==n.focusNode.childNodes.length&&i&&i.posAtStart>e.state.selection.to)for(let e=n.focusNode;;e=e.parentNode){if(getComputedStyle(e).overflow!=`visible`){l=w.findFrom(r.resolve(i.posAtStart),1);break}if(e==i.dom||e.nextSibling||!e.parentNode||!O(e.parentNode))break}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!Da(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function Pa(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,Fr(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oi&&si<=11&&(n.disabled=!0,n.disabled=!1)}function Fa(e,t){if(t instanceof E){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(Ia(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else Ia(e)}function Ia(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function La(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||T.between(t,n,r)}function Ra(e){return e.editable&&!e.hasFocus()?!1:za(e)}function za(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return Gr(e.dom,t.anchorNode)&&(e.editable||Gr(e.dom,t.focusNode))}catch{return!1}}function Ba(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return Br(t.node,t.offset,n.anchorNode,n.anchorOffset)}function Va(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&w.findFrom(a,t)}function Ha(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Ua(e,t,n){let r=e.state.selection;if(r instanceof T){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return Ha(e,new T(r.$anchor,a))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=Va(e.state,t);return n&&n instanceof E?Ha(e,n):!1}if(!mi||n.indexOf(`m`)<0){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?E.isSelectable(i)?Ha(e,new E(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):Ha(e,new T(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1}}else if(r instanceof E&&r.node.isInline)return Ha(e,new T(t>0?r.$to:r.$from));else{let n=Va(e.state,t);return n?Ha(e,n):!1}}function Wa(e,t){let n=e.pmViewDesc;return n?n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`):O(e)&&e.contentEditable==`false`}function Ga(e,t){return t<0?Ka(e):qa(e)}function Ka(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(ci&&O(n)&&r0){if(!O(n))break;let e=n.childNodes[r-1];if(Wa(e,-1))i=n,a=--r;else if(Wr(e))n=e,r=n.nodeValue.length;else break}else if(Ja(n))break;else{let t=n.previousSibling;for(;t&&Wa(t,-1);)i=n.parentNode,a=Fr(t),t=t.previousSibling;if(t)n=t,r=Ur(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?Za(e,n,r):i&&Za(e,i,a)}function qa(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=Ur(n),a,o;for(;;)if(r{e.state==a&&Oa(e)},50)}function Qa(e,t){let n=e.state.doc.resolve(t);if(!(ui||hi)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i1)return n.leftr.top&&i1)return n.left>r.left?`ltr`:`rtl`}}let r=e.dom;for(let t=n.depth;t>0;t--)if(n.node(t).isBlock){r=e.nodeDOM(n.before(t))||r;break}return getComputedStyle(r).direction==`rtl`?`rtl`:`ltr`}function $a(e,t,n){let r=e.state.selection;if(r instanceof T&&!r.empty||n.indexOf(`s`)>-1||mi&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=Va(e.state,t);if(n&&n instanceof E)return Ha(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof Dn?w.near(n,t):w.findFrom(n,t);return o?Ha(e,o):!1}return!1}function eo(e,t){if(!(e.state.selection instanceof T))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function to(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function no(e){if(!fi||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&O(t)&&n==0&&t.firstChild&&O(t.firstChild)&&t.firstChild.contentEditable==`false`){let n=t.firstChild;to(e,n,`true`),setTimeout(()=>to(e,n,`false`),20)}return!1}function ro(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function io(e,t){let n=t.keyCode,r=ro(t);if(n==8||mi&&n==72&&r==`c`)return eo(e,-1)||Ga(e,-1);if(n==46&&!t.shiftKey||mi&&n==68&&r==`c`)return eo(e,1)||Ga(e,1);if(n==13||n==27)return!0;if(n==37||mi&&n==66&&r==`c`){let t=n==37?Qa(e,e.state.selection.from)==`ltr`?-1:1:-1;return Ua(e,t,r)||Ga(e,t)}if(n==39||mi&&n==70&&r==`c`){let t=n==39?Qa(e,e.state.selection.from)==`ltr`?1:-1:1;return Ua(e,t,r)||Ga(e,t)}return n==38||mi&&n==80&&r==`c`?$a(e,-1,r)||Ga(e,-1):n==40||mi&&n==78&&r==`c`?no(e)||$a(e,1,r)||Ga(e,1):!(r!=(mi?`m`:`c`)||n!=66&&n!=73&&n!=89&&n!=90)}function ao(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||Ze.fromSchema(e.state.schema),s=go(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&O(l)&&(u=ho[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&O(l)&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,` +`))}})}function Ut(e,t,n){let r=e.resolve(t),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function Wt(e,t,n,r,i){let a=e.doc.nodeAt(t);if(!a)throw RangeError(`No node at given position`);n||=a.type;let o=n.create(r,null,i||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,o);if(!n.validContent(a.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new Dt(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new p(s.from(o),0,0),1,!0))}function Gt(e,t,n=1,r){let i=e.resolve(t),a=i.depth-n,o=r&&r[r.length-1]||i.parent;if(a<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>a;e--,t--){let n=i.node(e),a=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(a,n.childCount),s=r&&r[t+1];s&&(o=o.replaceChild(0,s.type.create(s.attrs)));let c=r&&r[t]||n;if(!n.canReplace(a+1,n.childCount)||!c.type.validContent(o))return!1}let s=i.indexAfter(a),c=r&&r[0];return i.node(a).canReplaceWith(s,s,c?c.type:i.node(a+1).type)}function Kt(e,t,n=1,r){let i=e.doc.resolve(t),a=s.empty,o=s.empty;for(let e=i.depth,t=i.depth-n,c=n-1;e>t;e--,c--){a=s.from(i.node(e).copy(a));let t=r&&r[c];o=s.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new Et(t,t,new p(a.append(o),n,n),!0))}function qt(e,t){let n=e.resolve(t),r=n.index();return Yt(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function Jt(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i0?(i=r.node(e+1),o++,a=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),a=r.node(e+1)),i&&!i.isTextblock&&Yt(i,a)&&r.node(e).canReplace(o,o+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function Zt(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,a=e.doc.resolve(t-n),o=a.node().type;if(i&&o.inlineContent){let e=o.whitespace==`pre`,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let s=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);Ht(e,r.node(),r.before(),s)}o.inlineContent&&jt(e,t+n-1,o,a.node().contentMatchAt(a.index()),r==null);let c=e.mapping.slice(s),l=c.map(t-n);if(e.step(new Et(l,c.map(t+n,-1),p.empty,!0)),r===!0){let t=e.doc.resolve(l);Vt(e,t.node(),t.before(),e.steps.length)}return e}function Qt(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,a=r.index(t)+ +(n>0),o=r.node(t),s=!1;if(e==1)s=o.canReplace(a,a,i);else{let e=o.contentMatchAt(a).findWrapping(i.firstChild.type);s=e&&o.canReplaceWith(a,a,e[0])}if(s)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function en(e,t,n=t,r=p.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),a=e.resolve(n);return tn(i,a,r)?new Et(t,n,r):new nn(i,a,r).fit()}function tn(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var nn=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=s.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=s.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,a=n.depth,o=r.depth;for(;a&&o&&i.childCount==1;)i=i.firstChild.content,a--,o--;let s=new p(i,a,o);return e>-1?new Dt(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new Et(n.pos,r.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=on(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let i=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:a,match:o}=this.frontier[e],c,l=null;if(t==1&&(i?o.matchType(i.type)||(l=o.fillBefore(s.from(i),!1)):r&&a.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:l};if(t==2&&i&&(c=o.findWrapping(i.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:c};if(r&&o.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced;return dn(e,-1)<=t?!1:(this.unplaced.size>1&&dn(e,1)>n&&n++,this.unplaced=new p(e,t+1,n),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=on(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new p(rn(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new p(rn(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e1||c==0||e.content.size)&&(d=t,u.push(sn(e.mark(f.allowedMarks(e.marks)),l==1?c:0,l==o.childCount?m:-1)))}let h=l==o.childCount;h||(m=-1),this.placed=an(this.placed,t,s.from(u)),this.frontier[t].match=d,h&&m<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t=0;n--){let{match:t,type:r}=this.frontier[n],i=cn(e,n,r,t,!0);if(!i||i.childCount)continue scan}return{depth:t,fit:a,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=an(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=an(this.placed,this.depth,s.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(s.empty,!0);e.childCount&&(this.placed=an(this.placed,this.frontier.length,e))}};function rn(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(rn(e.firstChild.content,t-1,n)))}function an(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(an(e.lastChild.content,t-1,n)))}function on(e,t){for(let n=0;n1&&(r=r.replaceChild(0,sn(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(s.empty,!0)))),e.copy(r)}function cn(e,t,n,r,i){let a=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==a.childCount&&!n.compatibleContent(a.type))return null;let s=r.fillBefore(a.content,!0,o);return s&&!ln(n,a.content,o)?s:null}function ln(e,t,n){for(let r=n;r0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?s=e:i.before(e)==t&&o.splice(1,0,-e)}let c=o.indexOf(s),l=[],u=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(l.push(n),t==r.openStart)break;e=n.content}for(let e=u-1;e>=0;e--){let t=l[e],n=un(t.type);if(n&&!t.sameMarkup(i.node(Math.abs(s)-1)))u=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let s=(t+u+1)%(r.openStart+1),d=l[s];if(d)for(let t=0;t=0&&(e.replace(t,n,r),!(e.steps.length>d));s--){let e=o[s];e<0||(t=i.before(e),n=a.after(e))}}function pn(e,t,n,r,i){if(tr){let t=i.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(s.empty,!0))}return e}function mn(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let i=Qt(e.doc,t,r.type);i!=null&&(t=n=i)}e.replaceRange(t,n,new p(s.from(r),0,0))}function hn(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&r.parentOffset==0&&i.parentOffset==0){let a=r.sharedDepth(n),o=!1;for(let e=r.depth;e>a;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>a;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let a=gn(r,i);for(let t=0;t0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(t-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return e.delete(r.before(a),n);e.delete(t,n)}function gn(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(rt.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}var _n=class e extends _t{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return vt.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return vt.fromReplace(e,this.pos,this.pos+1,new p(s.from(r),0,+!t.isLeaf))}getMap(){return mt.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};_t.jsonID(`attr`,_n);var vn=class e extends _t{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return vt.ok(n)}getMap(){return mt.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};_t.jsonID(`docAttr`,vn);var yn=class extends Error{};yn=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},yn.prototype=Object.create(Error.prototype),yn.prototype.constructor=yn,yn.prototype.name=`TransformError`;var bn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ht}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new yn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n{e=Math.min(e,i),t=Math.max(t,a)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=p.empty){let r=en(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new p(s.from(n),0,0))}delete(e,t){return this.replace(e,t,p.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return fn(this,e,t,n),this}replaceRangeWith(e,t,n){return mn(this,e,t,n),this}deleteRange(e,t){return hn(this,e,t),this}lift(e,t){return Pt(this,e,t),this}join(e,t=1){return Zt(this,e,t),this}wrap(e,t){return zt(this,e,t),this}setBlockType(e,t=e,n,r=null){return Bt(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return Wt(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new _n(e,t,n)),this}setDocAttribute(e,t){return this.step(new vn(e,t)),this}addNodeMark(e,t){return this.step(new wt(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof d)t.isInSet(n.marks)&&this.step(new Tt(e,t));else{let r=n.marks,i,a=[];for(;i=t.isInSet(r);)a.push(new Tt(e,i)),r=i.removeFromSet(r);for(let e=a.length-1;e>=0;e--)this.step(a[e])}return this}split(e,t=1,n){return Kt(this,e,t,n),this}addMark(e,t,n){return kt(this,e,t,n),this}removeMark(e,t,n){return At(this,e,t,n),this}clearIncompatible(e,t,n){return jt(this,e,t,n),this}},xn=Object.create(null),w=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Sn(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;r--){let i=t<0?kn(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):kn(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Dn(e.node(0))}static atStart(e){return kn(e,e,0,0,1)||new Dn(e)}static atEnd(e){return kn(e,e,e.content.size,e.childCount,-1)||new Dn(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=xn[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in xn)throw RangeError(`Duplicate use of selection JSON ID `+e);return xn[e]=t,t.prototype.jsonID=e,t}getBookmark(){return T.between(this.$anchor,this.$head).getBookmark()}};w.prototype.visible=!0;var Sn=class{constructor(e,t){this.$from=e,this.$to=t}},Cn=!1;function wn(e){!Cn&&!e.parent.inlineContent&&(Cn=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var T=class e extends w{constructor(e,t=e){wn(e),wn(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return w.near(r);let i=t.resolve(n.map(this.anchor));return new e(i.parent.inlineContent?i:r,r)}replace(e,t=p.empty){if(super.replace(e,t),t==p.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Tn(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let i=t.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let e=w.findFrom(n,r,!0)||w.findFrom(n,-r,!0);if(e)n=e.$head;else return w.near(n,r)}return t.parent.inlineContent||(i==0?t=n:(t=(w.findFrom(t,-r,!0)||w.findFrom(t,r,!0)).$anchor,t.pos0?0:1);i>0?o=0;o+=i){let r=t.child(o);if(!r.isAtom){let t=kn(e,r,n+i,i<0?r.childCount:0,i,a);if(t)return t}else if(!a&&E.isSelectable(r))return E.create(e,n-(i<0?r.nodeSize:0));n+=r.nodeSize*i}return null}function An(e,t,n){let r=e.steps.length-1;if(r{o??=r}),e.setSelection(w.near(e.doc.resolve(o),n))}var jn=1,Mn=2,Nn=4,Pn=class extends bn{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|=Mn,this}ensureMarks(e){return d.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&Mn)>0}addStep(e,t){super.addStep(e,t),this.updated&=-3,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||d.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(w.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|=Nn,this}get scrolledIntoView(){return(this.updated&Nn)>0}};function Fn(e,t){return!t||!e?e:e.bind(t)}var In=class{constructor(e,t,n){this.name=e,this.init=Fn(t.init,n),this.apply=Fn(t.apply,n)}},Ln=[new In(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new In(`selection`,{init(e,t){return e.selection||w.atStart(t.doc)},apply(e){return e.selection}}),new In(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new In(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],Rn=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ln.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new In(e.key,e.spec.state,e))})}},zn=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;ne.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let i=new Rn(t.schema,t.plugins),a=new e(i);return i.fields.forEach(e=>{if(e.name==`doc`)a.doc=ce.fromJSON(t.schema,n.doc);else if(e.name==`selection`)a.selection=w.fromJSON(a.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(a.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let i in r){let o=r[i],s=o.spec.state;if(o.key==e.name&&s&&s.fromJSON&&Object.prototype.hasOwnProperty.call(n,i)){a[e.name]=s.fromJSON.call(o,t,n[i],a);return}}a[e.name]=e.init(t,a)}}),a}};function Bn(e,t,n){for(let r in e){let i=e[r];i instanceof Function?i=i.bind(t):r==`handleDOMEvents`&&(i=Bn(i,t,{})),n[r]=i}return n}var D=class{constructor(e){this.spec=e,this.props={},e.props&&Bn(e.props,this,this.props),this.key=e.key?e.key.key:Hn(`plugin`)}getState(e){return e[this.key]}},Vn=Object.create(null);function Hn(e){return e in Vn?e+`$`+ ++Vn[e]:(Vn[e]=0,e+`$`)}var O=class{constructor(e=`key`){this.key=Hn(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},Un=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function Wn(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`backward`,e):n.parentOffset>0)?null:n}var Gn=(e,t,n)=>{let r=Wn(e,n);if(!r)return!1;let i=Zn(r);if(!i){let n=r.blockRange(),i=n&&Nt(n);return i!=null&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let a=i.nodeBefore;if(hr(e,i,t,-1))return!0;if(r.parent.content.size==0&&(Yn(a,`end`)||E.isSelectable(a)))for(let n=r.depth;;n--){let o=en(e.doc,r.before(n),r.after(n),p.empty);if(o&&o.slice.size1)break}return a.isAtom&&i.depth==r.depth-1?(t&&t(e.tr.delete(i.pos-a.nodeSize,i.pos).scrollIntoView()),!0):!1},Kn=(e,t,n)=>{let r=Wn(e,n);if(!r)return!1;let i=Zn(r);return i?Jn(e,i,t):!1},qn=(e,t,n)=>{let r=Qn(e,n);if(!r)return!1;let i=tr(r);return i?Jn(e,i,t):!1};function Jn(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let a=t.nodeAfter,o=t.pos+1;for(;!a.isTextblock;o++){if(a.type.spec.isolating)return!1;let e=a.firstChild;if(!e)return!1;a=e}let s=en(e.doc,i,o,p.empty);if(!s||s.from!=i||s instanceof Et&&s.slice.size>=o-i)return!1;if(n){let t=e.tr.step(s);t.setSelection(T.create(t.doc,i)),n(t.scrollIntoView())}return!0}function Yn(e,t,n=!1){for(let r=e;r;r=t==`start`?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}var Xn=(e,t,n)=>{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`backward`,e):r.parentOffset>0)return!1;a=Zn(r)}let o=a&&a.nodeBefore;return!o||!E.isSelectable(o)?!1:(t&&t(e.tr.setSelection(E.create(e.doc,a.pos-o.nodeSize)).scrollIntoView()),!0)};function Zn(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function Qn(e,t){let{$cursor:n}=e.selection;return!n||(t?!t.endOfTextblock(`forward`,e):n.parentOffset{let r=Qn(e,n);if(!r)return!1;let i=tr(r);if(!i)return!1;let a=i.nodeAfter;if(hr(e,i,t,1))return!0;if(r.parent.content.size==0&&(Yn(a,`start`)||E.isSelectable(a))){let n=en(e.doc,r.before(),r.after(),p.empty);if(n&&n.slice.size{let{$head:r,empty:i}=e.selection,a=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock(`forward`,e):r.parentOffset=0;t--){let n=e.node(t);if(e.index(t)+1{let n=e.selection,r=n instanceof E,i;if(r){if(n.node.isTextblock||!qt(e.doc,n.from))return!1;i=n.from}else if(i=Xt(e.doc,n.from,-1),i==null)return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(E.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},rr=(e,t)=>{let n=e.selection,r;if(n instanceof E){if(n.node.isTextblock||!qt(e.doc,n.to))return!1;r=n.to}else if(r=Xt(e.doc,n.to,1),r==null)return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0},ir=(e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),a=i&&Nt(i);return a!=null&&(t&&t(e.tr.lift(i,a).scrollIntoView()),!0)},ar=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(t&&t(e.tr.insertText(` +`).scrollIntoView()),!0)};function or(e){for(let t=0;t{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),a=n.indexAfter(-1),o=or(i.contentMatchAt(a));if(!o||!i.canReplaceWith(a,a,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(w.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},cr=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof Dn||r.parent.inlineContent||i.parent.inlineContent)return!1;let a=or(i.parent.contentMatchAt(i.indexAfter()));if(!a||!a.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index(){let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(Gt(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&Nt(r);return i!=null&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function ur(e){return(t,n)=>{if(t.selection instanceof E&&t.selection.node.isBlock){let{$from:e}=t.selection;return!e.parentOffset||!Gt(t.doc,e.pos)?!1:(n&&n(t.tr.split(e.pos).scrollIntoView()),!0)}if(!t.selection.$from.depth)return!1;let r=t.tr;!t.selection.empty&&(t.selection instanceof T||t.selection instanceof Dn)&&r.deleteSelection();let{$from:i}=r.selection,a=r.steps.length,o=[],s,c,l=!1,u=!1;for(let t=i.depth;;t--)if(i.node(t).isBlock){l=i.end(t)==i.pos+(i.depth-t),u=i.start(t)==i.pos-(i.depth-t),c=or(i.node(t-1).contentMatchAt(i.indexAfter(t-1)));let n=e&&e(i.parent,l,i);o.unshift(n||(l&&c?{type:c}:null)),s=t;break}else{if(t==1)return!1;o.unshift(null)}let d=i.pos,f=Gt(r.doc,d,o.length,o);if(f||=(o[0]=c?{type:c}:null,Gt(r.doc,d,o.length,o)),!f)return!1;if(r.split(d,o.length,o),!l&&u&&i.node(s).type!=c){let e=r.mapping.slice(a),t=e.map(i.before(s)),n=r.doc.resolve(t);c&&i.node(s-1).canReplaceWith(n.index(),n.index()+1,c)&&r.setNodeMarkup(e.map(i.before(s)),c)}return n&&n(r.scrollIntoView()),!0}}var dr=ur(),fr=(e,t)=>{let{$from:n,to:r}=e.selection,i,a=n.sharedDepth(r);return a!=0&&(i=n.before(a),t&&t(e.tr.setSelection(E.create(e.doc,i))),!0)},pr=(e,t)=>(t&&t(e.tr.setSelection(new Dn(e.doc))),!0);function mr(e,t,n){let r=t.nodeBefore,i=t.nodeAfter,a=t.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&t.parent.canReplace(a-1,a)?(n&&n(e.tr.delete(t.pos-r.nodeSize,t.pos).scrollIntoView()),!0):!t.parent.canReplace(a,a+1)||!(i.isTextblock||qt(e.doc,t.pos))?!1:(n&&n(e.tr.join(t.pos).scrollIntoView()),!0)}function hr(e,t,n,r){let i=t.nodeBefore,a=t.nodeAfter,o,c,l=i.type.spec.isolating||a.type.spec.isolating;if(!l&&mr(e,t,n))return!0;let u=!l&&t.parent.canReplace(t.index(),t.index()+1);if(u&&(o=(c=i.contentMatchAt(i.childCount)).findWrapping(a.type))&&c.matchType(o[0]||a.type).validEnd){if(n){let r=t.pos+a.nodeSize,c=s.empty;for(let e=o.length-1;e>=0;e--)c=s.from(o[e].create(null,c));c=s.from(i.copy(c));let l=e.tr.step(new Dt(t.pos-1,r,t.pos,r,new p(c,1,0),o.length,!0)),u=l.doc.resolve(r+2*o.length);u.nodeAfter&&u.nodeAfter.type==i.type&&qt(l.doc,u.pos)&&l.join(u.pos),n(l.scrollIntoView())}return!0}let d=a.type.spec.isolating||r>0&&l?null:w.findFrom(t,1),f=d&&d.$from.blockRange(d.$to),m=f&&Nt(f);if(m!=null&&m>=t.depth)return n&&n(e.tr.lift(f,m).scrollIntoView()),!0;if(u&&Yn(a,`start`,!0)&&Yn(i,`end`)){let r=i,o=[];for(;o.push(r),!r.isTextblock;)r=r.lastChild;let c=a,l=1;for(;!c.isTextblock;c=c.firstChild)l++;if(r.canReplace(r.childCount,r.childCount,c.content)){if(n){let r=s.empty;for(let e=o.length-1;e>=0;e--)r=s.from(o[e].copy(r));n(e.tr.step(new Dt(t.pos-o.length,t.pos+a.nodeSize,t.pos+l,t.pos+a.nodeSize-l,new p(r,o.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function gr(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,a=i.depth;for(;i.node(a).isInline;){if(!a)return!1;a--}return i.node(a).isTextblock?(n&&n(t.tr.setSelection(T.create(t.doc,e<0?i.start(a):i.end(a)))),!0):!1}}var _r=gr(-1),vr=gr(1);function yr(e,t=null){return function(n,r){let{$from:i,$to:a}=n.selection,o=i.blockRange(a),s=o&&Ft(o,e,t);return s?(r&&r(n.tr.wrap(o,s).scrollIntoView()),!0):!1}}function br(e,t=null){return function(n,r){let i=!1;for(let r=0;r{if(i)return!1;if(r.isTextblock&&!r.hasMarkup(e,t)){if(r.type==e)i=!0;else{let t=n.doc.resolve(a),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&t.startIndex==0){if(t.$from.index(t.depth-1)==0)return!1;let e=o.resolve(t.start-2);a=new oe(e,e,t.depth),t.endIndex=0;e--)a=s.from(n[e].type.create(n[e].attrs,a));e.step(new Dt(t.start-(r?2:0),t.end,t.start,t.end,new p(a,0,0),n.length,!0));let o=0;for(let e=0;e-1}function Ar(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&kr(e,t.firstChild.type));return a?n?kr(e,r.node(a.depth-1).type)?jr(t,n,a):Mr(t,n,a):!0:!1}}function jr(e,t,n){let r=e.tr,i=n.end,a=n.$to.end(n.depth),o=n.parent.child(n.endIndex-1).type;ia;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let a=r.doc.resolve(n.start),o=a.nodeAfter;if(r.mapping.map(n.end)!=n.start+a.nodeAfter.nodeSize)return!1;let c=n.startIndex==0,l=n.endIndex==i.childCount,u=a.node(-1),d=a.index(-1);if(!u.canReplace(d+ +!c,d+1,o.content.append(l?s.empty:s.from(i))))return!1;let f=a.pos,m=f+o.nodeSize;return r.step(new Dt(f-+!!c,m+ +!!l,f+1,m-1,new p((c?s.empty:s.from(i.copy(s.empty))).append(l?s.empty:s.from(i.copy(s.empty))),+!c,+!l),+!c)),t(r.scrollIntoView()),!0}function Nr(e){return function(t,n){let{$from:r,$to:i}=t.selection,a=r.blockRange(i,t=>t.childCount>0&&kr(e,t.firstChild.type));if(!a)return!1;let o=a.startIndex;if(o==0)return!1;let c=a.parent,l=c.child(o-1);if(!kr(e,l.type))return!1;if(n){let e=l.lastChild&&l.lastChild.type==c.type,r=s.from(e?l.lastChild.lastChild.type.create():null),i=new p(s.from(l.type.create(null,s.from(c.type.create(null,r)))),e?3:1,0),o=a.start,u=a.end;n(t.tr.step(new Dt(o-(e?3:1),u,o,u,i,1,!0)).scrollIntoView())}return!0}}var Pr=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},Fr=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},Ir=null,Lr=function(e,t,n){let r=Ir||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},Rr=function(){Ir=null},zr=function(e,t,n,r){return n&&(Vr(e,t,n,r,-1)||Vr(e,t,n,r,1))},Br=/^(img|br|input|textarea|hr)$/i;function Vr(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Hr(e))){let n=e.parentNode;if(!n||!k(n)||Jr(e)||Br.test(e.nodeName)||e.contentEditable==`false`)return!1;t=Pr(e)+(i<0?0:1),e=n}else if(k(e)){let n=e.childNodes[t+(i<0?-1:0)];if(k(n)&&n.contentEditable==`false`){if(n.pmViewDesc?.ignoreForSelection)t+=i;else return!1}else e=n,t=i<0?Hr(e):0}else return!1}}function Hr(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function k(e){return e.nodeType==1}function Ur(e){return e.nodeType==3}function Wr(e,t){return t?e.contains(k(t)?t:t.parentNode):!1}function Gr(e,t){for(;;){if(Ur(e)&&t)return e;if(k(e)&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=Hr(e)}else if(e.parentNode&&!Jr(e))t=Pr(e),e=e.parentNode;else return null}}function Kr(e,t){for(;;){if(Ur(e)&&t2),pi=fi||($r?/Mac/.test($r.platform):!1),mi=$r?/Win/.test($r.platform):!1,hi=/Android \d/.test(ti),gi=!!ei&&`webkitFontSmoothing`in ei.documentElement.style,_i=gi?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function vi(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function yi(e,t){return typeof e==`number`?e:e[t]}function bi(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function xi(e,t,n){if(!Ii(t)&&t.left==0)return;let r=e.someProp(`scrollThreshold`)||0,i=e.someProp(`scrollMargin`)||5,a=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(!k(o)){o=Fr(o);continue}let e=o==a.body,n=e?vi(a):bi(o),s=0,c=0;if(t.topn.bottom-yi(r,`bottom`)&&(c=t.bottom-t.top>n.bottom-n.top?t.top+yi(i,`top`)-n.top:t.bottom-n.bottom+yi(i,`bottom`)),t.leftn.right-yi(r,`right`)&&(s=t.right-n.right+yi(i,`right`)),s||c){if(e)a.defaultView.scrollBy(s,c);else{let e=o.scrollLeft,n=o.scrollTop;c&&(o.scrollTop+=c),s&&(o.scrollLeft+=s);let r=o.scrollLeft-e,i=o.scrollTop-n;t={left:t.left-r,top:t.top-i,right:t.right-r,bottom:t.bottom-i}}}let l=e?`fixed`:getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(l))break;o=l==`absolute`?o.offsetParent:Fr(o)}}function Si(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,i;for(let a=(t.left+t.right)/2,o=n+1;o=n-20){r=t,i=s.top;break}}return{refDOM:r,refTop:i,stack:Ci(e.dom)}}function Ci(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=Fr(r));return t}function wi({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;Ti(n,r==0?0:r-t)}function Ti(e,t){for(let n=0;n=s){o=Math.max(p.bottom,o),s=Math.min(p.top,s);let e=p.left>t.left?p.left-t.left:p.right=(p.left+p.right)/2));continue}}else p.top>t.top&&!c&&p.left<=t.left&&p.right>=t.left&&(c=u,l={left:Math.max(p.left,Math.min(p.right,t.left)),top:p.top});!n&&(t.left>=p.right&&t.top>=p.top||t.left>=p.left&&t.top>=p.bottom)&&(a=d+1)}}return!n&&c&&(n=c,i=l,r=0),n&&Ur(n)?ki(n,i):!n||r?{node:e,offset:a}:Oi(n,i)}function ki(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let a=0;a=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}function Ai(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function ji(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,a)}function Ni(e,t,n,r){let i=-1;for(let n=t,a=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(k(t.dom)&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!a&&o.left>r.left||o.top>r.top?i=t.posBefore:(!a&&o.right-1?i:e.docView.posFromDOM(t,n,-1)}function Pi(e,t,n){let r=e.childNodes.length;if(r&&n.topt.top&&i++}let n;gi&&i&&k(r)&&k(n=r.childNodes[i-1])&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&i--,r==e.dom&&i==r.childNodes.length-1&&k(r.lastChild)&&t.top>r.lastChild.getBoundingClientRect().bottom?s=e.state.doc.content.size:i!=0&&k(r)&&r.childNodes[i-1].nodeName==`BR`||(s=Ni(e,r,i,t))}s??=Mi(e,o,t);let c=e.docView.nearestDesc(o,!0);return{pos:s,inside:c?c.posAtStart-c.border:-1}}function Ii(e){return e.top=0&&i==r.nodeValue.length?(e--,a=1):n<0?e--:t++,Bi(Li(Lr(r,e,t),a),a<0)}}if(!e.state.doc.resolve(t-(a||0)).parent.inlineContent){if(a==null&&i&&(n<0||i==Hr(r))){let e=r.childNodes[i-1];if(k(e))return Vi(e.getBoundingClientRect(),!1)}if(a==null&&i=0)}if(a==null&&i&&(n<0||i==Hr(r))){let e=r.childNodes[i-1],t=Ur(e)?Lr(e,Hr(e)-+!o):k(e)&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return Bi(Li(t,1),!1)}if(a==null&&i=0)}function Bi(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function Vi(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function Hi(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}function Ui(e,t,n){let r=t.selection,i=n==`up`?r.$from:r.$to;return Hi(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=zi(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(k(e))t=e.getClientRects();else if(Ur(e))t=Lr(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;ei.top+1&&(n==`up`?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})}var Wi=/[\u0590-\u08ac]/;function Gi(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,a=!i,o=i==r.parent.content.size,s=e.domSelection();return s?!Wi.test(r.parent.textContent)||!s.modify?n==`left`||n==`backward`?a:o:Hi(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:a,anchorOffset:o}=e.domSelectionRange(),c=s.caretBidiLevel;s.modify(`move`,n,`character`);let l=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:u,focusOffset:d}=e.domSelectionRange(),f=u&&!Wr(l,u)||t==u&&i==d;try{s.collapse(a,o),t&&(t!=a||i!=o)&&s.extend&&s.extend(t,i)}catch{}return c!=null&&(s.caretBidiLevel=c),f}):r.pos==r.start()||r.pos==r.end()}var Ki=null,qi=null,Ji=!1;function Yi(e,t,n){return Ki==t&&qi==n?Ji:(Ki=t,qi=n,Ji=n==`up`||n==`down`?Ui(e,t,n):Gi(e,t,n))}var Xi=0,Zi=1,Qi=2,$i=3,ea=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=Xi,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(e){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tPr(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM)){let n=e.compareDocumentPosition(this.contentDOM);r=n&16?t>Array.from(e.childNodes).findIndex(e=>e.contains(this.contentDOM)):!(n&4)}else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),a;if(i&&(!t||i.node)){if(n&&(a=i.nodeDOM)&&!(k(a)?Wr(a,e):a==e))n=!1;else return i}}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;te){r=e-t;break}t=a}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(;n>0;n--){let e=this.children[n-1];if(e.size||!(e instanceof sa||e instanceof ta&&e.side>=0))break}if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,e&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?Pr(e.dom)+1:0}}{let e,r=!0;for(;e=n=i&&t<=s-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=a;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=Pr(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(s>t||o==this.children.length-1)){t=s;for(let e=o+1;es&&at){let e=o;o=s,s=e}let n=document.createRange();n.setEnd(s.node,s.offset),n.setStart(o.node,o.offset),c.removeAllRanges(),c.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r=n:en){let r=n+i.border,o=a-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==a?Qi:Zi,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=$i:i.markDirty(e-r,t-r);return}i.dirty=i.dom==i.contentDOM&&i.dom.parentNode==this.contentDOM&&!i.children.length?Qi:$i}n=a}this.dirty=Qi}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?Qi:Zi;t.dirty{if(!i)return r;if(i.parent)return i.parent.posBeforeChild(i)})),!t.type.spec.raw){let e=k(a)?a:document.createElement(`span`);e!=a&&(e.appendChild(a),a=e),e.hasAttribute(`contenteditable`)||(e.contentEditable=`false`),e.classList.add(`ProseMirror-widget`)}super(e,[],a,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return this.dirty==Xi&&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}},na=class extends ea{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},ra=class e extends ea{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(t,n,r,i){let a=i.nodeViews[n.type.name],o=a&&a(n,i,r);return o&&o.dom||(o=Ze.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&$i||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=$i&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Xi){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty0&&(a=wa(a,0,t,r));for(let e=0;e{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),u=l&&l.dom,d=l&&l.contentDOM;if(n.isText){if(!u)u=document.createTextNode(n.text);else if(!Ur(u))throw RangeError(`Text must be rendered as a DOM text node`)}else if(!u){let e=Ze.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:u,contentDOM:d}=e)}!d&&!n.isText&&u.nodeName!=`BR`&&(u.hasAttribute(`contenteditable`)||(u.contentEditable=`false`),n.type.spec.draggable&&(u.draggable=!0));let f=u;return u=ha(u,r,n),l?c=new ca(t,n,r,i,u,d||null,f,l):n.isText?new oa(t,n,r,i,u,f):new e(t,n,r,i,u,d||null,f)}parseRule(e){if(this.node.type.spec.reparseInView)return null;let t={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(t.preserveWhitespace=`full`),!this.contentDOM)t.getContent=()=>this.node.content;else if(!this.contentLost)t.contentElement=this.contentDOM;else{for(let e=this.children.length-1;e>=0;e--){let n=this.children[e];if(this.dom.contains(n.dom.parentNode)){t.contentElement=n.dom.parentNode;break}}if(!t.contentElement){let n=e&&e.find(t=>k(t)&&e.indexOf(t.parentNode)<0&&this.dom.contains(t));n?t.contentElement=n:t.getContent=()=>s.empty}}return t}matchesNode(e,t,n){return this.dirty==Xi&&e.eq(this.node)&&ga(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,a=i&&i.pos>-1?i:null,o=i&&i.pos<0,s=new va(this,a&&a.node,e),c=this.node.inlineContent,l=c&&this.node.isBlock;xa(this.node,this.innerDeco,(t,i,a)=>{t.spec.marks?s.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!a&&s.syncToMarks(i==this.node.childCount?d.none:this.node.child(i).marks,n,e,i),s.placeWidget(t,e,r)},(t,a,u,d)=>{s.syncToMarks(t.marks,n,e,d),l&&t.isAtom&&!t.isText&&s.addHackNode(`IMG`,s.top);let f;s.findNodeMatch(t,a,u,d)||o&&e.state.selection.from>r&&e.state.selection.to-1&&s.updateNodeAt(t,a,u,f,e)||s.updateNextNode(t,a,u,e,d,r)||s.addNode(t,a,u,e,r),r+=t.nodeSize,c&&(l=t.isAtom&&!t.isText)}),s.syncToMarks([],n,e,0),this.node.isTextblock&&s.addTextblockHacks(),s.destroyRest(),(s.changed||this.dirty==Qi)&&(a&&this.protectLocalComposition(e,a),la(this.contentDOM,this.children,e),fi&&Sa(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof T)||nt+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(this.node.inlineContent){let e=i.nodeValue,a=Ca(this.node.content,e,n-t,r-t);return a<0?null:{node:i,pos:a,text:e}}return{node:i,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let a=new na(this,i,t,r);e.input.compositionNodes.push(a),this.children=wa(this.children,n,n+r.length,e,a)}update(e,t,n,r){return this.dirty==$i||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Xi}updateOuterDeco(e){if(ga(e,this.outerDeco))return;let t=!k(this.nodeDOM),n=this.dom;this.dom=pa(this.dom,this.nodeDOM,fa(this.outerDeco,this.node,t),fa(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){k(this.nodeDOM)&&(this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){k(this.nodeDOM)&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function aa(e,t,n,r,i){ha(r,t,e);let a=new ia(void 0,e,t,n,r,r,r);return a.contentDOM&&a.updateChildren(i,0),a}var oa=class e extends ia{constructor(e,t,n,r,i,a){super(e,t,n,r,i,null,a)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==$i||this.dirty!=Xi&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Xi||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=Xi,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let i=this.node.cut(t,n),a=document.createTextNode(i.text);return new e(this.parent,i,this.outerDeco,this.innerDeco,a,a)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=$i)}get domAtom(){return!1}isText(e){return this.node.text==e}},sa=class extends ea{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Xi&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},ca=class extends ia{constructor(e,t,n,r,i,a,o,s){super(e,t,n,r,i,a,o),this.spec=s}update(e,t,n,r){if(this.dirty==$i)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function la(e,t,n){let r=e.firstChild,i=!1;for(let a=0;a>1,o=Math.min(a,e.length);for(;i-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=ra.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let i=-1,a;if(r>=this.preMatch.index&&(a=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&a.matchesNode(e,t,n))i=this.top.children.indexOf(a,this.index);else for(let r=this.index,a=Math.min(this.top.children.length,r+5);r0;){let s;for(;;)if(r){let e=n.children[r-1];if(e instanceof ra)n=e,r=e.children.length;else{s=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let c=s.node;if(c){if(c!=e.child(i-1))break;--i,a.set(s,i),o.push(s)}}return{index:i,matched:a,matches:o.reverse()}}function ba(e,t){return e.type.side-t.type.side}function xa(e,t,n,r){let i=t.locals(e),a=0;if(i.length==0){for(let n=0;na;)s.push(i[o++]);let m=a+f.nodeSize;if(f.isText){let e=m;o!e.inline):s.slice();r(f,h,t.forChild(a,f),p),a=m}}function Sa(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function Ca(e,t,n,r){for(let i=0,a=0;i=n){if(a>=r&&c.slice(r-t.length-s,r-s)==t)return r-t.length;let e=s=0&&e+t.length+s>=n)return s+e;if(n==r&&c.length>=r+t.length-s&&c.slice(r-s,r-s+t.length)==t)return r}}return-1}function wa(e,t,n,r,i){let a=[];for(let o=0,s=0;o=n||u<=t?a.push(c):(ln&&a.push(c.slice(n-l,c.size,r)))}return a}function Ta(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&i.size==0,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let s=r.resolve(o),c,l;if(Yr(n)){for(c=o;i&&!i.node;)i=i.parent;if(i&&i.node.isAtom&&E.isSelectable(i.node)&&i.parent&&!(i.node.isInline&&qr(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;l=new E(o==e?s:r.resolve(e))}else if(si&&t==`key`&&o>e.state.selection.to&&k(n.focusNode)&&n.focusOffset==n.focusNode.childNodes.length&&i&&i.posAtStart>e.state.selection.to)for(let e=n.focusNode;;e=e.parentNode){if(getComputedStyle(e).overflow!=`visible`){l=w.findFrom(r.resolve(i.posAtStart),1);break}if(e==i.dom||e.nextSibling||!e.parentNode||!k(e.parentNode))break}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r{(n.anchorNode!=r||n.anchorOffset!=i)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!Ea(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function Na(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r=n.nodeName==`IMG`;r?t.collapse(n.parentNode,Pr(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&ai&&oi<=11&&(n.disabled=!0,n.disabled=!1)}function Pa(e,t){if(t instanceof E){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(Fa(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else Fa(e)}function Fa(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function Ia(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||T.between(t,n,r)}function La(e){return e.editable&&!e.hasFocus()?!1:Ra(e)}function Ra(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return Wr(e.dom,t.anchorNode)&&(e.editable||Wr(e.dom,t.focusNode))}catch{return!1}}function za(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return zr(t.node,t.offset,n.anchorNode,n.anchorOffset)}function Ba(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&w.findFrom(a,t)}function Va(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Ha(e,t,n){let r=e.state.selection;if(r instanceof T){if(n.indexOf(`s`)>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return Va(e,new T(r.$anchor,a))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=Ba(e.state,t);return n&&n instanceof E?Va(e,n):!1}if(!pi||n.indexOf(`m`)<0){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,a;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return i.isAtom||(a=e.docView.descAt(o))&&!a.contentDOM?E.isSelectable(i)?Va(e,new E(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):Va(e,new T(e.state.doc.resolve(t<0?o:o+i.nodeSize))):!1}}else if(r instanceof E&&r.node.isInline)return Va(e,new T(t>0?r.$to:r.$from));else{let n=Ba(e.state,t);return n?Va(e,n):!1}}function Ua(e,t){let n=e.pmViewDesc;return n?n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`):k(e)&&e.contentEditable==`false`}function Wa(e,t){return t<0?Ga(e):Ka(e)}function Ga(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,a,o=!1;for(si&&k(n)&&r0){if(!k(n))break;let e=n.childNodes[r-1];if(Ua(e,-1))i=n,a=--r;else if(Ur(e))n=e,r=n.nodeValue.length;else break}else if(qa(n))break;else{let t=n.previousSibling;for(;t&&Ua(t,-1);)i=n.parentNode,a=Pr(t),t=t.previousSibling;if(t)n=t,r=Hr(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}o?Xa(e,n,r):i&&Xa(e,i,a)}function Ka(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i=Hr(n),a,o;for(;;)if(r{e.state==a&&Da(e)},50)}function Za(e,t){let n=e.state.doc.resolve(t);if(!(li||mi)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i1)return n.leftr.top&&i1)return n.left>r.left?`ltr`:`rtl`}}let r=e.dom;for(let t=n.depth;t>0;t--)if(n.node(t).isBlock){r=e.nodeDOM(n.before(t))||r;break}return getComputedStyle(r).direction==`rtl`?`rtl`:`ltr`}function Qa(e,t,n){let r=e.state.selection;if(r instanceof T&&!r.empty||n.indexOf(`s`)>-1||pi&&n.indexOf(`m`)>-1)return!1;let{$from:i,$to:a}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=Ba(e.state,t);if(n&&n instanceof E)return Va(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,o=r instanceof Dn?w.near(n,t):w.findFrom(n,t);return o?Va(e,o):!1}return!1}function $a(e,t){if(!(e.state.selection instanceof T))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let r=e.state.tr;return t<0?r.delete(n.pos-a.nodeSize,n.pos):r.delete(n.pos,n.pos+a.nodeSize),e.dispatch(r),!0}return!1}function eo(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function to(e){if(!di||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&k(t)&&n==0&&t.firstChild&&k(t.firstChild)&&t.firstChild.contentEditable==`false`){let n=t.firstChild;eo(e,n,`true`),setTimeout(()=>eo(e,n,`false`),20)}return!1}function no(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function ro(e,t){let n=t.keyCode,r=no(t);if(n==8||pi&&n==72&&r==`c`)return $a(e,-1)||Wa(e,-1);if(n==46&&!t.shiftKey||pi&&n==68&&r==`c`)return $a(e,1)||Wa(e,1);if(n==13||n==27)return!0;if(n==37||pi&&n==66&&r==`c`){let t=n==37?Za(e,e.state.selection.from)==`ltr`?-1:1:-1;return Ha(e,t,r)||Wa(e,t)}if(n==39||pi&&n==70&&r==`c`){let t=n==39?Za(e,e.state.selection.from)==`ltr`?1:-1:1;return Ha(e,t,r)||Wa(e,t)}return n==38||pi&&n==80&&r==`c`?Qa(e,-1,r)||Wa(e,-1):n==40||pi&&n==78&&r==`c`?to(e)||Qa(e,1,r)||Wa(e,1):!(r!=(pi?`m`:`c`)||n!=66&&n!=73&&n!=89&&n!=90)}function io(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:a}=t;for(;i>1&&a>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,a--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let o=e.someProp(`clipboardSerializer`)||Ze.fromSchema(e.state.schema),s=ho(),c=s.createElement(`div`);c.appendChild(o.serializeFragment(r,{document:s}));let l=c.firstChild,u,d=0;for(;l&&k(l)&&(u=mo[l.nodeName.toLowerCase()]);){for(let e=u.length-1;e>=0;e--){let t=s.createElement(u[e]);for(;c.firstChild;)t.appendChild(c.firstChild);c.appendChild(t),d++}l=c.firstChild}return l&&k(l)&&l.setAttribute(`data-pm-slice`,`${i} ${a}${d?` -${d}`:``} ${JSON.stringify(n)}`),{dom:c,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,` -`),slice:t}}function oo(e,t,n,r,i){let a=i.parent.type.spec.code,o,c;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return c=new p(s.from(e.state.schema.text(t.replace(/\r\n?/g,` -`))),0,0),e.someProp(`transformPasted`,t=>{c=t(c,e,!0)}),c;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)c=n;else{let n=i.marks(),{schema:r}=e.state,a=Ze.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=yo(n),_i&&bo(o);let u=o&&o.querySelector(`[data-pm-slice]`),d=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute(`data-pm-slice`)||``);if(d&&d[3])for(let e=+d[3];e>0;e--){let e=o.firstChild;for(;e&&!O(e);)e=e.nextSibling;if(!e)break;o=e}if(c||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||Le.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(l||d),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!so.test(e.parentNode.nodeName)?{ignore:!0}:null}}),d)c=xo(mo(c,+d[1],+d[2]),d[4]);else if(c=p.maxOpen(co(c.content,i),!0),c.openStart||c.openEnd){let e=0,t=0;for(let t=c.content.firstChild;e{c=t(c,e,l)}),c}var so=/^(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 co(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&uo(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=fo(a[a.length-1],i.length));let n=lo(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return s.from(a)}return e}function lo(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,s.from(e));return e}function uo(e,t,n,r,i){if(i1&&(a=0),i=n&&(c=t<0?o.contentMatchAt(0).fillBefore(c,a<=i).append(c):c.append(o.contentMatchAt(o.childCount).fillBefore(s.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(c))}function mo(e,t,n){return te})}return _o.createHTML(e)}function yo(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=go(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(e),a;if((a=i&&ho[i[1].toLowerCase()])&&(e=a.map(e=>`<`+e+`>`).join(``)+e+a.map(e=>``).reverse().join(``)),r.innerHTML=vo(e),a)for(let e=0;e=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;try{i=s.from(t.create(r[e+1],i))}catch{break}a++,o++}return new p(i,a,o)}var So={},Co={},wo={touchstart:!0,touchmove:!0},To=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function Eo(e){for(let t in So){let n=So[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{jo(e,t)&&!Ao(e,t)&&(e.editable||!(t.type in Co))&&n(e,t)},wo[t]?{passive:!0}:void 0)}fi&&e.dom.addEventListener(`input`,()=>null),ko(e)}function Do(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function Oo(e){e.input.mouseDown&&e.input.mouseDown.done(),e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function ko(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>Ao(e,t))})}function Ao(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function jo(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function Mo(e,t){!Ao(e,t)&&So[t.type]&&(e.editable||!(t.type in Co))&&So[t.type](e,t)}Co.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!Yo(e)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(gi&&ui&&n.keyCode==13))){if(n.keyCode!=229&&e.domObserver.forceFlush(),pi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||io(e,n)?n.preventDefault():Do(e,`key`)}},Co.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},Co.keypress=(e,t)=>{let n=t;if(Yo(e)||!n.charCode||n.ctrlKey&&!n.altKey||mi&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof T)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function No(e){return{left:e.clientX,top:e.clientY}}function Po(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function Fo(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function Io(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);r.setMeta(`pointer`,!0),e.dispatch(r)}function Lo(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&E.isSelectable(r)?(Io(e,new E(n)),!0):!1}function Ro(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof E&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(E.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i!=null&&(Io(e,E.create(e.state.doc,i)),!0)}function zo(e,t,n,r,i){return Fo(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?Ro(e,n):Lo(e,n))}function Bo(e,t,n,r){return Fo(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function Vo(e,t,n,r){return Fo(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||Ho(e,n,r)}function Ho(e,t,n){if(n.button!=0)return!1;let r=Uo(e,t,!0),i=e.state.doc;return r?(Io(e,r),r instanceof T&&i.eq(e.state.doc)&&(e.input.mouseDown=new Jo(e,r)),!0):!1}function Uo(e,t,n){let r=e.state.doc;if(t==-1)return r.inlineContent?T.create(r,0,r.content.size):null;let i=r.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e),a=i.before(e);if(t.inlineContent)return T.create(r,a+1,a+1+t.content.size);if(n&&E.isSelectable(t))return E.create(r,a)}return null}function Wo(e){return ts(e)}var Go=mi?`metaKey`:`ctrlKey`;So.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=Wo(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&Po(n,e.input.lastClick)&&!n[Go]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let o=e.posAtCoords(No(n));o&&(a==`singleClick`?e.input.mouseDown=new qo(e,o,n,!!r):(a==`doubleClick`?Bo:Vo)(e,o.pos,o.inside,n)?n.preventDefault():Do(e,`pointer`))};var Ko=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},qo=class extends Ko{constructor(e,t,n,r){super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[Go],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&O(s.nodeDOM)?s.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof E&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!(!this.target||this.target.draggable),setUneditable:!!(this.target&&ci&&!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()),Do(e,`pointer`)}done(){super.done(),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(()=>{this.view.isDestroyed||Oa(this.view)})}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(No(e))),this.updateAllowDefault(e),this.allowDefault||!t?Do(this.view,`pointer`):zo(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||fi&&this.mightDrag&&!this.mightDrag.node.isAtom||ui&&!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)?(Io(this.view,w.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Do(this.view,`pointer`)}move(e){this.updateAllowDefault(e),Do(this.view,`pointer`),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},Jo=class extends Ko{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),Do(this.view,`pointer`);let t=this.view.posAtCoords(No(e)),n=t&&Uo(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,i=this.startSelection,[a,o]=n.from{e.input.lastTouch=Date.now(),Wo(e),Do(e,`pointer`)},So.touchmove=e=>{e.input.lastTouch=Date.now(),Do(e,`pointer`)},So.contextmenu=e=>Wo(e);function Yo(e,t){return e.composing?!0:fi&&Math.abs(Date.now()-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var Xo=gi?5e3:-1;Co.compositionstart=Co.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof T&&t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||ui&&hi&&Zo(e)))e.markCursor=e.state.storedMarks||n.marks(),ts(e,!0),e.markCursor=null;else if(ts(e,!t.selection.empty),ci&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&O(n)&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(Wr(t)){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Qo(e,Xo)};function Zo(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||!O(t)||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return O(r)&&r.contentEditable==`false`}Co.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Qo(e,20))};function Qo(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>ts(e),t))}function $o(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function es(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Kr(t.focusNode,t.focusOffset),r=qr(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return r}}return n||r}function ts(e,t=!1){if(!(gi&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),$o(e),t||e.docView&&e.docView.dirty){let n=Ea(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function ns(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var rs=oi&&si<15||pi&&vi<604;So.copy=Co.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=rs?null:n.clipboardData,{dom:o,text:s}=ao(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):ns(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function is(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function as(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?ss(e,r.value,null,i,t):ss(e,r.textContent,r.innerHTML,i,t)},50)}function ss(e,t,n,r,i){let a=oo(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||p.empty)))return!0;if(!a)return!1;let o=is(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function cs(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}Co.paste=(e,t)=>{let n=t;if(e.composing&&!gi)return;let r=rs?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&ss(e,cs(r),r.getData(`text/html`),i,n)?n.preventDefault():as(e,n)};var ls=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},us=mi?`altKey`:`ctrlKey`;function ds(e,t){let n;return e.someProp(`dragCopies`,e=>{n||=e(t)}),n==null?!t[us]:!n}So.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(No(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof E?i.to-1:i.to))){if(r&&r.mightDrag)o=E.create(e.state.doc,r.mightDrag.pos);else if(n.target&&O(n.target)){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=E.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=ao(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!ui||di>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(rs?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,rs||n.dataTransfer.setData(`text/plain`,c),e.dragging=new ls(l,ds(e,n),o)},So.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},Co.dragover=Co.dragenter=(e,t)=>t.preventDefault(),Co.drop=(e,t)=>{try{fs(e,t,e.dragging)}finally{e.dragging=null}};function fs(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(No(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=oo(e,cs(t.dataTransfer),rs?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&ds(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||p.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?$t(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&E.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new E(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(La(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}So.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Oa(e)},20))},So.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},So.beforeinput=(e,t)=>{if(gi&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,Zr(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in Co)So[e]=Co[e];function ps(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var ms=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index=a?null:new vs(i,a,this)}valid(e,t){return t.from=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;ae){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==Ss||e.maps.length==0?this:this.mapInner(e,t,0,0,n||bs)}mapInner(t,n,r,i,a){let o;if(this.local.length){let e=new ms(n.content);for(let s=0;s{let o=t+r,s;if(s=Ds(n,e,o)){for(i||=this.children.slice();aa&&n.to=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;ea&&t.type instanceof gs){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;ee.map(t,n,bs));return e.from(r)}forChild(t,n){if(n.isLeaf)return xs.empty;let r=[];for(let i=0;ie instanceof xs)?t:t.reduce((e,t)=>e.concat(t instanceof xs?t:t.members),[]))}}forEachSet(e){for(let t=0;t{let o=a-i-(n-e);for(let i=0;ia+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==Ss?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=ks(Es(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;en&&a.to{let s=Ds(e,t,o+n);if(s){a=!0;let e=ks(s,t,n+o+1,r);e!=Ss&&i.push(o,o+t.nodeSize,e)}});let o=Ts(a?Os(e):e,-n).sort(As);if(o.length){let e=new ms(t.content);for(let n=0;n0;)t++;e.splice(t,0,n)}function Ns(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=Ss&&t.push(r)}),e.cursorWrapper&&t.push(xs.create(e.state.doc,[e.cursorWrapper.deco])),Cs.from(t)}var Ps={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Fs=oi&&si<=11,Is=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},Ls=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Is,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;ee.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():fi&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Fs&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Ps)),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(Ra(this.view)){if(this.suppressingSelectionUpdates)return Oa(this.view);if(oi&&si<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Br(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=Ir(n))t.add(n);for(let r=e.anchorNode;r;r=Ir(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:Wr(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n,r=!1;!this.suppressingSelectionUpdates&&Ra(e)&&(n=e.domSelectionRange(),r=!this.currentSelection.eq(n)&&!this.ignoreSelectionChange(n));let i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;ee.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||ui&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(e=>e.type==`childList`&&e.removedNodes.length))){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&O(t);){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(ci&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||Us(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||r)&&(i>-1&&(e.docView.markDirty(i,a),Bs(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Ws(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):n&&!this.currentSelection.eq(n)&&Oa(e),n&&this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;na;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){o=e;break}if(!n||n.size)break}let f=e.state.doc,p=e.someProp(`domParser`)||Le.fromSchema(e.state.schema),m=f.resolve(s),h=null,g=p.parse(i,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:a,to:o,preserveWhitespace:m.parent.type.whitespace!=`pre`||`full`,findPositions:u,ruleFromNode:Ks(r),context:m});if(u&&u[0].pos!=null){let e=u[0].pos,t=u[1]&&u[1].pos;t??=e,h={anchor:e+s,head:t+s}}return{doc:g,sel:h,from:s,to:c}}var Ks=e=>t=>{let n=t.pmViewDesc;if(n)return n.parseRule(e);if(t.nodeName==`BR`&&t.parentNode){if(fi&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}if(t.parentNode.lastChild==t||fi&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName==`IMG`&&t.getAttribute(`mark-placeholder`))return{ignore:!0};return null},qs=/^(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 Js(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=Ea(e,t);if(n&&!e.state.selection.eq(n)){if(ui&&gi&&e.input.lastKeyCode===13&&Date.now()-100t(e,Zr(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=Gs(e,t,n,i),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100Date.now()-225||gi)&&i.some(e=>O(e)&&!qs.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m){if(r&&c instanceof T&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=Ys(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}}e.state.selection.frome.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),oi&&si<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((pi&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&Qs(l.doc,h.pos,g.pos))&&e.someProp(`handleKeyDown`,t=>t(e,Zr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&(v?m.endA>m.start&&m.endB==m.start:Zs(u,m.start,m.endA,h,g))&&e.someProp(`handleKeyDown`,t=>t(e,Zr(8,`Backspace`)))){gi&&ui&&e.domObserver.suppressSelectionUpdates();return}ui&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),gi&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,Zr(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=Ys(e,n.doc,l.sel);t&&!(ui&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDeleteOa(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=Xs(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x())}else e.dispatch(x())}function Ys(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:La(e,t.resolve(n.anchor),t.resolve(n.head))}function Xs(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,c,l;for(let e=0;ee.mark(c.addToSet(e.marks));else if(i.length==0&&a.length==1)c=a[0],o=`remove`,l=e=>e.mark(c.removeFromSet(e.marks));else return null;let u=[];for(let e=0;en||$s(o,!0,!1){e.isTextblock&&a>=t&&a0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function ec(e,t,n,r,i){let a=e.findDiffStart(t,n),o=n+e.size,s=n+t.size;if(a==null)return null;let{a:c,b:l}=e.findDiffEnd(t,o,s);if(i==`end`){let e=Math.max(0,a-Math.min(c,l));r-=c+e-a}if(c=c?a-r:0;a-=e,l=a+(l-c),c=a}else if(l=l?a-r:0;a-=e,c=a+(c-l),l=a}return{start:a,endA:c,endB:l}}var tc=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new To,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(cc),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=ic(this),rc(this),this.nodeViews=oc(this),this.docView=oa(this.state.doc,nc(this),Ns(this),this.dom,this),this.domObserver=new Ls(this,(e,t,n,r)=>Js(this,e,t,n,r)),this.domObserver.start(),Eo(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&&ko(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(cc),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&($o(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=oc(this);sc(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&ko(this),this.editable=ic(this),rc(this);let o=Ns(this),s=nc(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&Ci(this);if(i){this.domObserver.stop();let t=l&&(oi||ui)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&ac(n.selection,e.selection);if(l){let n=ui?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=es(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=oa(e.doc,s,o,this.dom,this)),!n||this.trackWrites&&this.dom.contains(this.trackWrites)||(t=!0)}let i=this.input.mouseDown;t||!(i&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ba(this)&&i.delaySelUpdate())?Oa(this,t):(Fa(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&Ti(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&Gr(this.dom,e)&&!this.someProp(`handleScrollToSelection`,e=>e(this))){if(this.state.selection instanceof E){let t=this.docView.domAfterPos(this.state.selection.from);O(t)&&Si(this,t.getBoundingClientRect(),e)}else Si(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e0&&ee.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ii(this,e)}coordsAtPos(e,t=1){return Bi(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Xi(this,t||this.state,e)}pasteHTML(e,t){return ss(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return ss(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return ao(this,e)}destroy(){this.docView&&(Oo(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ns(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,zr())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Mo(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?fi&&this.root.nodeType===11&&Qr(this.dom.ownerDocument)==this.dom&&Hs(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};tc.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function nc(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[vs.node(0,e.state.doc.content.size,t)]}function rc(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:vs.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function ic(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function ac(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function oc(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function sc(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function cc(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var lc={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:`'`},uc={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},dc=typeof navigator<`u`&&/Mac/.test(navigator.platform),fc=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),pc=0;pc<10;pc++)lc[48+pc]=lc[96+pc]=String(pc);for(var pc=1;pc<=24;pc++)lc[pc+111]=`F`+pc;for(var pc=65;pc<=90;pc++)lc[pc]=String.fromCharCode(pc+32),uc[pc]=String.fromCharCode(pc);for(var mc in lc)uc.hasOwnProperty(mc)||(uc[mc]=lc[mc]);function hc(e){var t=!(dc&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||fc&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?uc:lc)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var gc=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),_c=typeof navigator<`u`&&/Win/.test(navigator.platform);function vc(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e=t?wc.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},wc.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},wc.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},wc.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},wc.from=function(e){return e instanceof wc?e:e&&e.length?new Tc(e):wc.empty};var Tc=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=Cc)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=Cc)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(wc);wc.empty=new Tc([]);var Ec=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return ei&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(wc),Dc=500,Oc=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step)i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);else{if(i){u.push(new Ac(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new Ac(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1}},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;eMc&&(s=kc(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new ht;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new Ac(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;n=Math.min(this.items.length,n);let r=[],i=this.items.length-n,a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new Ac(i,o,l))}else r.push(new Ac(i))},i);let l=[];for(let e=n;eDc&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new Ac(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(wc.from(i.reverse()),a)}};Oc.empty=new Oc(wc.empty,0);function kc(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var Ac=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},jc=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},Mc=20;function Nc(e,t,n,r){let i=n.getMeta(Hc),a;if(i)return i.historyState;n.getMeta(Uc)&&(e=new jc(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(Hc))return o.getMeta(Hc).redo?new jc(e.done.addTransform(n,void 0,r,Bc(t)),e.undone,Fc(n.mapping.maps),e.prevTime,e.prevComposition):new jc(e.done,e.undone.addTransform(n,void 0,r,Bc(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Pc(n,e.prevRanges)),s=o?Ic(e.prevRanges,n.mapping):Fc(n.mapping.maps);return new jc(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,Bc(t)),Oc.empty,s,n.time,i??e.prevComposition)}return(a=n.getMeta(`rebased`))?new jc(e.done.rebased(n,a),e.undone.rebased(n,a),Ic(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new jc(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Ic(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Pc(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i=t[i]&&(n=!0)}),n}function Fc(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function Ic(e,t){if(!e)return null;let n=[];for(let r=0;r{let i=Hc.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=Lc(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var Kc=Gc(!1,!0),qc=Gc(!0,!0);function Jc(e){return e.getMeta(Hc)!=null}function Yc(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var Xc=class e{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}static createFakeChain(){let e=new Proxy({},{get:(t,n)=>{if(n!==`then`)return n===`run`?()=>!1:()=>e}});return e}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}static createFallbackCan(){let t=e.createFakeChain();return new Proxy({chain:()=>t},{get:(e,t)=>{if(t!==`then`)return t===`chain`?e.chain:()=>!1}})}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:Yc({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},Zc=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{if(!e.isDestroyed){var n;t.dom.blur(),(n=window)==null||(n=n.getSelection())==null||n.removeAllRanges()}}),!0),Qc=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),$c=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=Nt(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},el=e=>t=>e(t),tl=()=>({state:e,dispatch:t})=>lr(e,t),nl=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new T(r.doc.resolve(Math.max(o-1,0)))),!0},rl=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function il(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var al=e=>({tr:t,state:n,dispatch:r})=>{let i=il(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},ol=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},sl=e=>e.content?/^text(\*|\+)/.test(e.content):!1,cl=(e,t,n)=>{if(!e.parent.isInline||n===`left`&&e.pos>e.start()||n===`right`&&e.pos({from:cl(e,n,`left`),to:cl(t,n,`right`)}),ul=()=>({state:e,dispatch:t})=>{if(e.selection.empty)return!1;if(t){let n=e.tr,{ranges:r}=e.selection,i=e.selection instanceof T?e.selection.$from.marksAcross(e.selection.$to):null,a=n.steps.length;r.forEach(t=>{let r=n.mapping.slice(a),{from:i,to:o}=ll(n.doc.resolve(r.map(t.$from.pos)),n.doc.resolve(r.map(t.$to.pos)),e.schema);n.deleteRange(i,o)}),n.selection.empty||n.setSelection(T.near(n.doc.resolve(n.selection.from))),i&&n.ensureMarks(i),n.scrollIntoView(),t(n)}return!0},dl=()=>({commands:e})=>e.keyboardShortcut(`Enter`),fl=()=>({state:e,dispatch:t})=>cr(e,t);function pl(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function ml(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:pl(t[r])?t[r].test(e[r]):t[r]===e[r])}function hl(e,t,n={}){return e.find(e=>e.type===t&&ml(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function gl(e,t,n={}){return!!hl(e,t,n)}function _l(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!hl([...r.node.marks],t,n))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&gl([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o({tr:n,state:r,dispatch:i})=>{let a=vl(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=_l(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=T.create(o,e.from,e.to);n.setSelection(t)}}return!0},bl=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(Tl()||wl())&&r.dom.focus(),El()&&!Tl()&&!wl()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!xl(n.state.selection))return o(),!0;let s=Cl(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Ol=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),kl=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),Al=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&Al(r)}return e};function jl(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`${e}`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return Al(n)}function Ml(e){return typeof e?.nodesBetween==`function`}function Nl(e,t,n){if(Ml(e))return e;let r=typeof e==`object`&&!!e;n={slice:!0,parseOptions:{},...n};let i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return s.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),Nl(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new Ne({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?Le.fromSchema(a).parseSlice(jl(e),n.parseOptions):Le.fromSchema(a).parse(jl(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=Le.fromSchema(t);return n.slice?r.parseSlice(jl(e),n.parseOptions).content:r.parse(jl(e),n.parseOptions)}return Nl(``,t,n)}function Pl(e){return!(`type`in e)}function Fl(e,t,n){let r=e.steps.length-1;if(r{o===0&&(o=r)}),e.setSelection(w.near(e.doc.resolve(o),n))}var Il=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{Nl(t,a.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=Nl(t,a.schema,{parseOptions:c,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:l,to:u}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},d=!0,f=!0,p=Pl(i)?i.content:[i];if(p.forEach(e=>{e.check(),d=d?e.isText&&e.marks.length===0:!1,f=f?e.isBlock:!1}),l===u&&f){let{parent:e}=r.doc.resolve(l);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--l,u+=1)}let m;if(d)m=Array.isArray(t)?t.map(e=>e.text||``).join(``):Ml(t)?p.map(e=>e.text??``).join(``):typeof t==`object`&&t&&t.text?t.text:t,r.insertText(m,l,u);else{m=s.from(p);let e=r.doc.resolve(l),t=e.node(),n=e.parentOffset===0,i=t.isText||t.isTextblock,a=t.content.size>0;n&&i&&a&&f&&(l=Math.max(0,l-1)),r.replaceWith(l,u,p)}n.updateSelection&&Fl(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:l,text:m}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:l,text:m})}return!0};function Ll(e){for(let t=0;t({tr:t,dispatch:n,editor:r})=>{let{pos:i,attrs:a,content:o,updateSelection:s=!0}=e,c;c=typeof i==`number`?t.doc.resolve(i):i||t.selection.$from;let l=Ll(c.parent.contentMatchAt(c.index()));if(!l)return!1;let u=Object.keys(l.spec.attrs||{}),d=a?Object.fromEntries(Object.entries(a).filter(([e])=>u.includes(e))):{},f;if(o){let e=Nl(o,r.schema);f=l.createAndFill(d,e)}else f=l.createAndFill(d);return f?(n&&(t.insert(c.pos,f),s&&Fl(t,t.steps.length-1,-1)),!0):!1},zl=()=>({state:e,dispatch:t})=>rr(e,t),Bl=()=>({state:e,dispatch:t})=>ir(e,t),Vl=()=>({state:e,dispatch:t})=>Kn(e,t),Hl=()=>({state:e,dispatch:t})=>er(e,t),Ul=(e,t)=>{let n=e.resolve(t),r=n.nodeBefore,i=n.nodeAfter;return!r||!i?!1:!r.type.spec.isolating&&!i.type.spec.isolating},Wl=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Xt(e.doc,e.selection.$from.pos,-1);return r==null||!Ul(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Gl=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Xt(e.doc,e.selection.$from.pos,1);return r==null||!Ul(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Kl=()=>({state:e,dispatch:t})=>qn(e,t),ql=()=>({state:e,dispatch:t})=>Jn(e,t);function Jl(){return typeof navigator<`u`&&/Mac/.test(navigator.platform)}function Yl(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e({editor:t,view:n,tr:r,dispatch:i})=>{let a=Yl(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function Zl(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?il(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>!o||o.name===e.node.type.name).filter(e=>ml(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var Ql=(e,t={})=>({state:n,dispatch:r})=>Zl(n,il(e,n.schema),t)?ar(n,r):!1,$l=()=>({state:e,dispatch:t})=>ur(e,t),eu=e=>({state:t,dispatch:n})=>jr(il(e,t.schema))(t,n),tu=()=>({state:e,dispatch:t})=>or(e,t);function nu(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function ru(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var iu=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=nu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=il(e,r.schema)),s===`mark`&&(o=vl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,ru(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(ru(a.attrs,t))))})})}),c},au=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),ou=()=>({tr:e,dispatch:t})=>{if(t){let t=new Dn(e.doc);e.setSelection(t)}return!0},su=()=>({state:e,dispatch:t})=>Zn(e,t),cu=()=>({state:e,dispatch:t})=>tr(e,t),lu=()=>({state:e,dispatch:t})=>pr(e,t),uu=()=>({state:e,dispatch:t})=>yr(e,t),du=()=>({state:e,dispatch:t})=>vr(e,t);function fu(e,t,n={},r={}){return Nl(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var pu=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=fu(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});if(o){let e=Pl(s)?s.content:[s];a.replaceWith(0,c.content.size,e).setMeta(`preventUpdate`,!n)}return!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function mu(e,t){let n=vl(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function hu(e,t){let n=new bn(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function gu(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function _u(e,t,n){let r=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&r.push({node:e,pos:t})}),r}function vu(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function yu(e){return t=>vu(t.$from,e)}function k(e,t,n){return e.config[t]===void 0&&e.parent?k(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?k(e.parent,t,n):null}):e.config[t]}function bu(e){return e.map(e=>{let t=k(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...bu(t())]:e}).flat(10)}function xu(e,t){let n=Ze.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function Su(e,t){let n=new Map;for(let t of e){let e=n.get(t.type)??new Map;e.set(t.name,t),n.set(t.type,e)}return[...Object.values(t.nodes),...Object.values(t.marks)].flatMap(e=>Object.entries(e.spec.attrs??{}).map(([t,r])=>{let i=n.get(e.name)?.get(t),a=Object.hasOwn(r,`default`);return{type:e.name,name:t,attribute:{rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,...i?.attribute,default:r.default,isRequired:!a,validate:r.validate}}}))}var Cu={content:`string`,marks:`string`,group:`string`,inline:`boolean`,atom:`boolean`,selectable:`boolean`,draggable:`boolean`,code:`boolean`,whitespace:[`pre`,`normal`],definingAsContext:`boolean`,definingForContent:`boolean`,defining:`boolean`,isolating:`boolean`,linebreakReplacement:`boolean`},wu={inclusive:`boolean`,excludes:`string`,group:`string`,spanning:`boolean`,code:`boolean`};function Tu(e,t,n){return Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e[t];if(i===void 0)return[];if(!(typeof r==`string`?typeof i===r:typeof i==`string`&&r.includes(i)))throw RangeError(`Invalid schemaSpec field '${n}.${t}'`);return[[t,i]]}))}function Eu(e,t,n,r){return{...Object.fromEntries(Object.entries(t).filter(([e])=>e!==`attrs`&&!Object.hasOwn(r,e))),...Tu(n,r,e),attrs:n.attrs}}function Du(e,t,n){for(let r of Object.keys(t))if(!Object.hasOwn(e,r))throw RangeError(`schemaSpec requires a local ${n} extension named '${r}'`);for(let r of Object.keys(e))if(!Object.hasOwn(t,r))throw RangeError(`Local ${n} extension '${r}' is not in schemaSpec`)}function Ou(e,t){Du(e.nodes,t.nodes,`node`),Du(e.marks,t.marks,`mark`);let n=t.spec.nodes,r=t.spec.marks;return t.spec.nodes.forEach((t,r)=>{n=n.update(t,Eu(t,e.nodes[t],r,Cu))}),t.spec.marks.forEach((t,n)=>{r=r.update(t,Eu(t,e.marks[t],n,wu))}),{topNode:t.topNodeType.name,nodes:n,marks:r}}function ku(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function Au(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function ju(e){let t=[],{nodeExtensions:n,markExtensions:r}=Au(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>e.name!==`text`).map(e=>e.name),s=r.map(e=>e.name),c=[...o,...s];return e.forEach(e=>{let n=k(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{let n;n=Array.isArray(e.types)?e.types:e.types===`*`?c:e.types===`nodes`?o:e.types===`marks`?s:[],n.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=k(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function Mu(e){return typeof e==`function`}function Nu(e,t=void 0,...n){return Mu(e)?t?e.bind(t)(...n):e(...n):e}function Pu(e={}){return Object.keys(e).length===0&&e.constructor===Object}function Fu(e){let t=[],n=``,r=!1,i=!1,a=0,o=e.length;for(let s=0;s0){--a,n+=o;continue}if(o===`;`&&a===0){t.push(n),n=``;continue}}n+=o}}return n&&t.push(n),t}function Iu(e){let t=[],n=Fu(e||``),r=n.length;for(let e=0;e!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(e===`__proto__`)Object.defineProperty(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0});else if(!n[e])n[e]=t;else if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=new Map([...Iu(n[e]),...Iu(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function Lu(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>A(e,t),{})}function Ru(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`||e!==`false`&&e:e}function zu(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Ru(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function Bu(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Pu(t)?!1:t!=null))}function Vu(e){var t,n;let r={};return!(e!=null&&(t=e.attribute)!=null&&t.isRequired)&&`default`in(e?.attribute||{})&&(r.default=e.attribute.default),(e==null||(n=e.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function Hu(e,t,n=ju(e)){let{nodeExtensions:r,markExtensions:i}=Au(e);return{topNode:r.find(e=>k(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Bu({...e.reduce((e,t)=>{let n=k(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:Nu(k(r,`content`,a)),marks:Nu(k(r,`marks`,a)),group:Nu(k(r,`group`,a)),inline:Nu(k(r,`inline`,a)),atom:Nu(k(r,`atom`,a)),selectable:Nu(k(r,`selectable`,a)),draggable:Nu(k(r,`draggable`,a)),code:Nu(k(r,`code`,a)),whitespace:Nu(k(r,`whitespace`,a)),linebreakReplacement:Nu(k(r,`linebreakReplacement`,a)),defining:Nu(k(r,`defining`,a)),isolating:Nu(k(r,`isolating`,a)),attrs:Object.fromEntries(i.map(Vu))}),s=Nu(k(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>zu(e,i)));let c=k(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:Lu(e,i)}));let l=k(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=Bu({...e.reduce((e,t)=>{let n=k(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:Nu(k(r,`inclusive`,a)),excludes:Nu(k(r,`excludes`,a)),group:Nu(k(r,`group`,a)),spanning:Nu(k(r,`spanning`,a)),code:Nu(k(r,`code`,a)),attrs:Object.fromEntries(i.map(Vu))}),s=Nu(k(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>zu(e,i)));let c=k(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:Lu(e,i)})),[r.name,o]}))}}function Uu(e,t,n){if(n===void 0)return new Ne(Hu(e,t));let r=ku(e.filter(e=>e.type!==`extension`).map(e=>e.name));if(r.length)throw RangeError(`Duplicate local schema types: ${r.join(`, `)}`);let i=new Ne(n);return new Ne(Ou(Hu(e,t,Su(ju(e),i)),i))}function Wu(e){return e.sort((e,t)=>{let n=k(e,`priority`)||100,r=k(t,`priority`)||100;return n>r?-1:+(ne.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function Ku(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=` +`),slice:t}}function ao(e,t,n,r,i){let a=i.parent.type.spec.code,o,c;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp(`transformPastedText`,n=>{t=n(t,a||r,e)}),a)return c=new p(s.from(e.state.schema.text(t.replace(/\r\n?/g,` +`))),0,0),e.someProp(`transformPasted`,t=>{c=t(c,e,!0)}),c;let n=e.someProp(`clipboardTextParser`,n=>n(t,i,r,e));if(n)c=n;else{let n=i.marks(),{schema:r}=e.state,a=Ze.fromSchema(r);o=document.createElement(`div`),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=o.appendChild(document.createElement(`p`));e&&t.appendChild(a.serializeNode(r.text(e,n)))})}}else e.someProp(`transformPastedHTML`,t=>{n=t(n,e)}),o=vo(n),gi&&yo(o);let u=o&&o.querySelector(`[data-pm-slice]`),d=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute(`data-pm-slice`)||``);if(d&&d[3])for(let e=+d[3];e>0;e--){let e=o.firstChild;for(;e&&!k(e);)e=e.nextSibling;if(!e)break;o=e}if(c||=(e.someProp(`clipboardParser`)||e.someProp(`domParser`)||Le.fromSchema(e.state.schema)).parseSlice(o,{preserveWhitespace:!!(l||d),context:i,ruleFromNode(e){return e.nodeName==`BR`&&!e.nextSibling&&e.parentNode&&!oo.test(e.parentNode.nodeName)?{ignore:!0}:null}}),d)c=bo(po(c,+d[1],+d[2]),d[4]);else if(c=p.maxOpen(so(c.content,i),!0),c.openStart||c.openEnd){let e=0,t=0;for(let t=c.content.firstChild;e{c=t(c,e,l)}),c}var oo=/^(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 so(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,a=[];if(e.forEach(e=>{if(!a)return;let t=r.findWrapping(e.type),n;if(!t)return a=null;if(n=a.length&&i.length&&lo(t,i,e,a[a.length-1],0))a[a.length-1]=n;else{a.length&&(a[a.length-1]=uo(a[a.length-1],i.length));let n=co(e,t);a.push(n),r=r.matchType(n.type),i=t}}),a)return s.from(a)}return e}function co(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,s.from(e));return e}function lo(e,t,n,r,i){if(i1&&(a=0),i=n&&(c=t<0?o.contentMatchAt(0).fillBefore(c,a<=i).append(c):c.append(o.contentMatchAt(o.childCount).fillBefore(s.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(c))}function po(e,t,n){return te})}return go.createHTML(e)}function vo(e){let t=/^(\s*]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n=ho(),r=n.body,i=/<([a-z][^>\s]+)/i.exec(e),a;if((a=i&&mo[i[1].toLowerCase()])&&(e=a.map(e=>`<`+e+`>`).join(``)+e+a.map(e=>``).reverse().join(``)),r.innerHTML=_o(e),a)for(let e=0;e=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;try{i=s.from(t.create(r[e+1],i))}catch{break}a++,o++}return new p(i,a,o)}var xo={},So={},Co={touchstart:!0,touchmove:!0},wo=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:``,button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function To(e){for(let t in xo){let n=xo[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{Ao(e,t)&&!ko(e,t)&&(e.editable||!(t.type in So))&&n(e,t)},Co[t]?{passive:!0}:void 0)}di&&e.dom.addEventListener(`input`,()=>null),Oo(e)}function Eo(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function Do(e){e.input.mouseDown&&e.input.mouseDown.done(),e.domObserver.stop();for(let t in e.input.eventHandlers)e.dom.removeEventListener(t,e.input.eventHandlers[t]);clearTimeout(e.input.composingTimeout),clearTimeout(e.input.lastIOSEnterFallbackTimeout)}function Oo(e){e.someProp(`handleDOMEvents`,t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>ko(e,t))})}function ko(e,t){return e.someProp(`handleDOMEvents`,n=>{let r=n[t.type];return r?r(e,t)||t.defaultPrevented:!1})}function Ao(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}function jo(e,t){!ko(e,t)&&xo[t.type]&&(e.editable||!(t.type in So))&&xo[t.type](e,t)}So.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=n.keyCode==16||n.shiftKey,!Jo(e)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!(hi&&li&&n.keyCode==13))){if(n.keyCode!=229&&e.domObserver.forceFlush(),fi&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp(`handleKeyDown`,t=>t(e,Xr(13,`Enter`))),e.input.lastIOSEnter=0)},200)}else e.someProp(`handleKeyDown`,t=>t(e,n))||ro(e,n)?n.preventDefault():Eo(e,`key`)}},So.keyup=(e,t)=>{t.keyCode==16&&(e.input.shiftKey=!1)},So.keypress=(e,t)=>{let n=t;if(Jo(e)||!n.charCode||n.ctrlKey&&!n.altKey||pi&&n.metaKey)return;if(e.someProp(`handleKeyPress`,t=>t(e,n))){n.preventDefault();return}let r=e.state.selection;if(!(r instanceof T)||!r.$from.sameParent(r.$to)){let t=String.fromCharCode(n.charCode),i=()=>e.state.tr.insertText(t).scrollIntoView();!/[\r\n]/.test(t)&&!e.someProp(`handleTextInput`,n=>n(e,r.$from.pos,r.$to.pos,t,i))&&e.dispatch(i()),n.preventDefault()}};function Mo(e){return{left:e.clientX,top:e.clientY}}function No(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}function Po(e,t,n,r,i){if(r==-1)return!1;let a=e.state.doc.resolve(r);for(let r=a.depth+1;r>0;r--)if(e.someProp(t,t=>r>a.depth?t(e,n,a.nodeAfter,a.before(r),i,!0):t(e,n,a.node(r),a.before(r),i,!1)))return!0;return!1}function Fo(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);r.setMeta(`pointer`,!0),e.dispatch(r)}function Io(e,t){if(t==-1)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return r&&r.isAtom&&E.isSelectable(r)?(Fo(e,new E(n)),!0):!1}function Lo(e,t){if(t==-1)return!1;let n=e.state.selection,r,i;n instanceof E&&(r=n.node);let a=e.state.doc.resolve(t);for(let e=a.depth+1;e>0;e--){let t=e>a.depth?a.nodeAfter:a.node(e);if(E.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&a.before(n.$from.depth+1)==n.$from.pos?a.before(n.$from.depth):a.before(e);break}}return i!=null&&(Fo(e,E.create(e.state.doc,i)),!0)}function Ro(e,t,n,r,i){return Po(e,`handleClickOn`,t,n,r)||e.someProp(`handleClick`,n=>n(e,t,r))||(i?Lo(e,n):Io(e,n))}function zo(e,t,n,r){return Po(e,`handleDoubleClickOn`,t,n,r)||e.someProp(`handleDoubleClick`,n=>n(e,t,r))}function Bo(e,t,n,r){return Po(e,`handleTripleClickOn`,t,n,r)||e.someProp(`handleTripleClick`,n=>n(e,t,r))||Vo(e,n,r)}function Vo(e,t,n){if(n.button!=0)return!1;let r=Ho(e,t,!0),i=e.state.doc;return r?(Fo(e,r),r instanceof T&&i.eq(e.state.doc)&&(e.input.mouseDown=new qo(e,r)),!0):!1}function Ho(e,t,n){let r=e.state.doc;if(t==-1)return r.inlineContent?T.create(r,0,r.content.size):null;let i=r.resolve(t);for(let e=i.depth+1;e>0;e--){let t=e>i.depth?i.nodeAfter:i.node(e),a=i.before(e);if(t.inlineContent)return T.create(r,a+1,a+1+t.content.size);if(n&&E.isSelectable(t))return E.create(r,a)}return null}function Uo(e){return es(e)}var Wo=pi?`metaKey`:`ctrlKey`;xo.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=Uo(e),i=Date.now(),a=`singleClick`;i-e.input.lastClick.time<500&&No(n,e.input.lastClick)&&!n[Wo]&&e.input.lastClick.button==n.button&&(e.input.lastClick.type==`singleClick`?a=`doubleClick`:e.input.lastClick.type==`doubleClick`&&(a=`tripleClick`)),e.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:a,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let o=e.posAtCoords(Mo(n));o&&(a==`singleClick`?e.input.mouseDown=new Ko(e,o,n,!!r):(a==`doubleClick`?zo:Bo)(e,o.pos,o.inside,n)?n.preventDefault():Eo(e,`pointer`))};var Go=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener(`mouseup`,this.up=this.up.bind(this)),e.root.addEventListener(`mousemove`,this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener(`mouseup`,this.up),this.view.root.removeEventListener(`mousemove`,this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},Ko=class extends Go{constructor(e,t,n,r){super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[Wo],this.allowDefault=n.shiftKey;let i,a;if(t.inside>-1)i=e.state.doc.nodeAt(t.inside),a=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,a=n.depth?n.before():0}let o=r?null:n.target,s=o?e.docView.nearestDesc(o,!0):null;this.target=s&&k(s.nodeDOM)?s.nodeDOM:null;let{selection:c}=e.state;n.button==0&&(i.type.spec.draggable&&i.type.spec.selectable!==!1||c instanceof E&&c.from<=a&&c.to>a)&&(this.mightDrag={node:i,pos:a,addAttr:!(!this.target||this.target.draggable),setUneditable:!!(this.target&&si&&!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()),Eo(e,`pointer`)}done(){super.done(),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(()=>{this.view.isDestroyed||Da(this.view)})}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(Mo(e))),this.updateAllowDefault(e),this.allowDefault||!t?Eo(this.view,`pointer`):Ro(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||di&&this.mightDrag&&!this.mightDrag.node.isAtom||li&&!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)?(Fo(this.view,w.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Eo(this.view,`pointer`)}move(e){this.updateAllowDefault(e),Eo(this.view,`pointer`),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},qo=class extends Go{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),Eo(this.view,`pointer`);let t=this.view.posAtCoords(Mo(e)),n=t&&Ho(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,i=this.startSelection,[a,o]=n.from{e.input.lastTouch=Date.now(),Uo(e),Eo(e,`pointer`)},xo.touchmove=e=>{e.input.lastTouch=Date.now(),Eo(e,`pointer`)},xo.contextmenu=e=>Uo(e);function Jo(e,t){return e.composing?!0:di&&Math.abs(Date.now()-e.input.compositionEndedAt)<500?(e.input.compositionEndedAt=-2e8,!0):!1}var Yo=hi?5e3:-1;So.compositionstart=So.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof T&&t.selection.empty&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>e.type.spec.inclusive===!1)||li&&mi&&Xo(e)))e.markCursor=e.state.storedMarks||n.marks(),es(e,!0),e.markCursor=null;else if(es(e,!t.selection.empty),si&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&k(n)&&r!=0;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(Ur(t)){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Zo(e,Yo)};function Xo(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||!k(t)||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return k(r)&&r.contentEditable==`false`}So.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Zo(e,20))};function Zo(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>es(e),t))}function Qo(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function $o(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=Gr(t.focusNode,t.focusOffset),r=Kr(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(e&&e.isText(n.nodeValue))return r}}return n||r}function es(e,t=!1){if(!(hi&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),Qo(e),t||e.docView&&e.docView.dirty){let n=Ta(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}function ts(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement(`div`));n.appendChild(t),n.style.cssText=`position: fixed; left: -10000px; top: 10px`;let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}var ns=ai&&oi<15||fi&&_i<604;xo.copy=So.cut=(e,t)=>{let n=t,r=e.state.selection,i=n.type==`cut`;if(r.empty)return;let a=ns?null:n.clipboardData,{dom:o,text:s}=io(e,r.content());a?(n.preventDefault(),a.clearData(),a.setData(`text/html`,o.innerHTML),a.setData(`text/plain`,s)):ts(e,o),i&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta(`uiEvent`,`cut`))};function rs(e){return e.openStart==0&&e.openEnd==0&&e.content.childCount==1?e.content.firstChild:null}function is(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?`textarea`:`div`));n||(r.contentEditable=`true`),r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.focus();let i=e.input.shiftKey&&e.input.lastKeyCode!=45;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?as(e,r.value,null,i,t):as(e,r.textContent,r.innerHTML,i,t)},50)}function as(e,t,n,r,i){let a=ao(e,t,n,r,e.state.selection.$from);if(e.someProp(`handlePaste`,t=>t(e,i,a||p.empty)))return!0;if(!a)return!1;let o=rs(a),s=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(a);return e.dispatch(s.scrollIntoView().setMeta(`paste`,!0).setMeta(`uiEvent`,`paste`)),!0}function ss(e){let t=e.getData(`text/plain`)||e.getData(`Text`);if(t)return t;let n=e.getData(`text/uri-list`);return n?n.replace(/\r?\n/g,` `):``}So.paste=(e,t)=>{let n=t;if(e.composing&&!hi)return;let r=ns?null:n.clipboardData,i=e.input.shiftKey&&e.input.lastKeyCode!=45;r&&as(e,ss(r),r.getData(`text/html`),i,n)?n.preventDefault():is(e,n)};var cs=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},ls=pi?`altKey`:`ctrlKey`;function us(e,t){let n;return e.someProp(`dragCopies`,e=>{n||=e(t)}),n==null?!t[ls]:!n}xo.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=e.state.selection,a=i.empty?null:e.posAtCoords(Mo(n)),o;if(!(a&&a.pos>=i.from&&a.pos<=(i instanceof E?i.to-1:i.to))){if(r&&r.mightDrag)o=E.create(e.state.doc,r.mightDrag.pos);else if(n.target&&k(n.target)){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(o=E.create(e.state.doc,t.posBefore))}}let{dom:s,text:c,slice:l}=io(e,(o||e.state.selection).content());(!n.dataTransfer.files.length||!li||ui>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(ns?`Text`:`text/html`,s.innerHTML),n.dataTransfer.effectAllowed=`copyMove`,ns||n.dataTransfer.setData(`text/plain`,c),e.dragging=new cs(l,us(e,n),o)},xo.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},So.dragover=So.dragenter=(e,t)=>t.preventDefault(),So.drop=(e,t)=>{try{ds(e,t,e.dragging)}finally{e.dragging=null}};function ds(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(Mo(t));if(!r)return;let i=e.state.doc.resolve(r.pos),a=n&&n.slice;a?e.someProp(`transformPasted`,t=>{a=t(a,e,!1)}):a=ao(e,ss(t.dataTransfer),ns?null:t.dataTransfer.getData(`text/html`),!1,i);let o=!!(n&&us(e,t));if(e.someProp(`handleDrop`,n=>n(e,t,a||p.empty,o))){t.preventDefault();return}if(!a)return;t.preventDefault();let s=a?$t(e.state.doc,i.pos,a):i.pos;s??=i.pos;let c=e.state.tr;if(o){let{node:e}=n;e?e.replace(c):c.deleteSelection()}let l=c.mapping.map(s),u=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,d=c.doc;if(u?c.replaceRangeWith(l,l,a.content.firstChild):c.replaceRange(l,l,a),c.doc.eq(d))return;let f=c.doc.resolve(l);if(u&&E.isSelectable(a.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(a.content.firstChild))c.setSelection(new E(f));else{let t=c.mapping.map(s);c.mapping.maps[c.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),c.setSelection(Ia(e,f,c.doc.resolve(t)))}e.focus(),e.dispatch(c.setMeta(`uiEvent`,`drop`))}xo.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add(`ProseMirror-focused`),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Da(e)},20))},xo.blur=(e,t)=>{let n=t;e.focused&&=(e.domObserver.stop(),e.dom.classList.remove(`ProseMirror-focused`),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),!1)},xo.beforeinput=(e,t)=>{if(hi&&t.inputType==`deleteContentBackward`){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp(`handleKeyDown`,t=>t(e,Xr(8,`Backspace`)))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let e in So)xo[e]=So[e];function fs(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var ps=class{constructor(e){this.frag=e,this.index=0,this.off=0}nodeAt(e){for(;this.off<=e&&this.index=a?null:new _s(i,a,this)}valid(e,t){return t.from=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let a=0;ae){let o=this.children[a]+1;this.children[a+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==xs||e.maps.length==0?this:this.mapInner(e,t,0,0,n||ys)}mapInner(t,n,r,i,a){let o;if(this.local.length){let e=new ps(n.content);for(let s=0;s{let o=t+r,s;if(s=Es(n,e,o)){for(i||=this.children.slice();aa&&n.to=t){this.children[e]==t&&(r=this.children[e+2]);break}let a=t+1,o=a+n.content.size;for(let e=0;ea&&t.type instanceof hs){let e=Math.max(a,t.from)-a,n=Math.min(o,t.to)-a;ee.map(t,n,ys));return e.from(r)}forChild(t,n){if(n.isLeaf)return bs.empty;let r=[];for(let i=0;ie instanceof bs)?t:t.reduce((e,t)=>e.concat(t instanceof bs?t:t.members),[]))}}forEachSet(e){for(let t=0;t{let o=a-i-(n-e);for(let i=0;ia+t-r)continue;let c=s[i]+t-r;n>=c?s[i+1]=e<=c?-2:-1:e>=t&&o&&(s[i]+=o,s[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let c=!1;for(let t=0;t=r.content.size){c=!0;continue}let d=n.map(e[t+1]+a,-1)-i,{index:f,offset:p}=r.content.findIndex(u),m=r.maybeChild(f);if(m&&p==u&&p+m.nodeSize==d){let r=s[t+2].mapInner(n,m,l+1,e[t]+a+1,o);r==xs?(s[t+1]=-2,c=!0):(s[t]=u,s[t+1]=d,s[t+2]=r)}else c=!0}if(c){let c=Os(Ts(s,e,t,n,i,a,o),r,0,o);t=c.local;for(let e=0;en&&a.to{let s=Es(e,t,o+n);if(s){a=!0;let e=Os(s,t,n+o+1,r);e!=xs&&i.push(o,o+t.nodeSize,e)}});let o=ws(a?Ds(e):e,-n).sort(ks);if(o.length){let e=new ps(t.content);for(let n=0;n0;)t++;e.splice(t,0,n)}function Ms(e){let t=[];return e.someProp(`decorations`,n=>{let r=n(e.state);r&&r!=xs&&t.push(r)}),e.cursorWrapper&&t.push(bs.create(e.state.doc,[e.cursorWrapper.deco])),Ss.from(t)}var Ns={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Ps=ai&&oi<=11,Fs=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},Is=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Fs,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;ee.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():di&&e.composing&&t.some(e=>e.type==`childList`&&e.target.nodeName==`TR`)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Ps&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,Ns)),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(La(this.view)){if(this.suppressingSelectionUpdates)return Da(this.view);if(ai&&oi<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&zr(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=Fr(n))t.add(n);for(let r=e.anchorNode;r;r=Fr(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:`selection`,target:Ur(n)?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let n,r=!1;!this.suppressingSelectionUpdates&&La(e)&&(n=e.domSelectionRange(),r=!this.currentSelection.eq(n)&&!this.ignoreSelectionChange(n));let i=-1,a=-1,o=!1,s=[];if(e.editable)for(let e=0;ee.nodeName==`BR`)&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||li&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(e=>e.type==`childList`&&e.removedNodes.length))){for(let e of s)if(e.nodeName==`BR`&&e.parentNode){let t=e.nextSibling;for(;t&&k(t);){if(t.contentEditable==`false`){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(si&&s.length){let t=s.filter(e=>e.nodeName==`BR`);if(t.length==2){let[e,n]=t;e.parentNode&&e.parentNode.parentNode==n.parentNode?n.remove():e.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of t){let t=r.parentNode;t&&t.nodeName==`LI`&&(!n||Hs(e,n)!=t)&&r.remove()}}}let c=null;i<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||r)&&(i>-1&&(e.docView.markDirty(i,a),zs(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Us(e,s)),this.handleDOMChange(i,a,o,s),e.docView&&e.docView.dirty?e.updateState(e.state):n&&!this.currentSelection.eq(n)&&Da(e),n&&this.currentSelection.set(n))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if(e.type==`attributes`&&(n==this.view.docView||e.attributeName==`contenteditable`||e.attributeName==`style`&&!e.oldValue&&!e.target.getAttribute(`style`))||!n||n.ignoreMutation(e))return null;if(e.type==`childList`){for(let n=0;na;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if(t.nodeName==`BR`&&!n){o=e;break}if(!n||n.size)break}let f=e.state.doc,p=e.someProp(`domParser`)||Le.fromSchema(e.state.schema),m=f.resolve(s),h=null,g=p.parse(i,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:a,to:o,preserveWhitespace:m.parent.type.whitespace!=`pre`||`full`,findPositions:u,ruleFromNode:Gs(r),context:m});if(u&&u[0].pos!=null){let e=u[0].pos,t=u[1]&&u[1].pos;t??=e,h={anchor:e+s,head:t+s}}return{doc:g,sel:h,from:s,to:c}}var Gs=e=>t=>{let n=t.pmViewDesc;if(n)return n.parseRule(e);if(t.nodeName==`BR`&&t.parentNode){if(di&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let e=document.createElement(`div`);return e.appendChild(document.createElement(`li`)),{skip:e}}if(t.parentNode.lastChild==t||di&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName==`IMG`&&t.getAttribute(`mark-placeholder`))return{ignore:!0};return null},Ks=/^(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 qs(e,t,n,r,i){let a=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=Ta(e,t);if(n&&!e.state.selection.eq(n)){if(li&&hi&&e.input.lastKeyCode===13&&Date.now()-100t(e,Xr(13,`Enter`))))return;let r=e.state.tr.setSelection(n);t==`pointer`?r.setMeta(`pointer`,!0):t==`key`&&r.scrollIntoView(),a&&r.setMeta(`composition`,a),e.dispatch(r)}return}let o=e.state.doc.resolve(t),s=o.sharedDepth(n);t=o.before(s+1),n=e.state.doc.resolve(n).after(s+1);let c=e.state.selection,l=Ws(e,t,n,i),u=e.state.doc,d=u.slice(l.from,l.to),f,p;e.input.lastKeyCode===8&&Date.now()-100Date.now()-225||hi)&&i.some(e=>k(e)&&!Ks.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp(`handleKeyDown`,t=>t(e,Xr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(!m){if(r&&c instanceof T&&!c.empty&&c.$head.sameParent(c.$anchor)&&!e.composing&&!(l.sel&&l.sel.anchor!=l.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(l.sel){let t=Js(e,e.state.doc,l.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);a&&n.setMeta(`composition`,a),e.dispatch(n)}}return}}e.state.selection.frome.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=l.from?m.start=e.state.selection.from:m.endA=e.state.selection.to-2&&e.state.selection.to<=l.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),ai&&oi<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>l.from&&l.doc.textBetween(m.start-l.from-1,m.start-l.from+1)==` \xA0`&&(m.start--,m.endA--,m.endB--);let h=l.doc.resolveNoCache(m.start-l.from),g=l.doc.resolveNoCache(m.endB-l.from),_=u.resolve(m.start),v=h.sameParent(g)&&h.parent.inlineContent&&_.end()>=m.endA;if((fi&&e.input.lastIOSEnter>Date.now()-225&&(!v||i.some(e=>e.nodeName==`DIV`||e.nodeName==`P`))||!v&&Zs(l.doc,h.pos,g.pos))&&e.someProp(`handleKeyDown`,t=>t(e,Xr(13,`Enter`)))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&(v?m.endA>m.start&&m.endB==m.start:Xs(u,m.start,m.endA,h,g))&&e.someProp(`handleKeyDown`,t=>t(e,Xr(8,`Backspace`)))){hi&&li&&e.domObserver.suppressSelectionUpdates();return}li&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),hi&&!v&&h.start()!=g.start()&&g.parentOffset==0&&h.depth==g.depth&&l.sel&&l.sel.anchor==l.sel.head&&l.sel.head==m.endA&&(m.endB-=2,g=l.doc.resolveNoCache(m.endB-l.from),setTimeout(()=>{e.someProp(`handleKeyDown`,function(t){return t(e,Xr(13,`Enter`))})},20));let y=m.start,b=m.endA,x=t=>{let n=t||e.state.tr.replace(y,b,l.doc.slice(m.start-l.from,m.endB-l.from));if(l.sel){let t=Js(e,n.doc,l.sel);t&&!(li&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDeleteDa(e),20));let t=x(e.state.tr.delete(y,b)),n=u.resolve(m.start).marksAcross(u.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(S=Ys(h.parent.content.cut(h.parentOffset,g.parentOffset),_.parent.content.cut(_.parentOffset,m.endA-_.start())))){let t=x(e.state.tr);S.type==`add`?t.addMark(y,b,S.mark):t.removeMark(y,b,S.mark),e.dispatch(t)}else if(h.parent.child(h.index()).isText&&h.index()==g.index()-+!g.textOffset){let t=h.parent.textBetween(h.parentOffset,g.parentOffset),n=()=>x(e.state.tr.insertText(t,y,b));e.someProp(`handleTextInput`,r=>r(e,y,b,t,n))||e.dispatch(n())}else e.dispatch(x())}else e.dispatch(x())}function Js(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:Ia(e,t.resolve(n.anchor),t.resolve(n.head))}function Ys(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,a=r,o,c,l;for(let e=0;ee.mark(c.addToSet(e.marks));else if(i.length==0&&a.length==1)c=a[0],o=`remove`,l=e=>e.mark(c.removeFromSet(e.marks));else return null;let u=[];for(let e=0;en||Qs(o,!0,!1){e.isTextblock&&a>=t&&a0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function $s(e,t,n,r,i){let a=e.findDiffStart(t,n),o=n+e.size,s=n+t.size;if(a==null)return null;let{a:c,b:l}=e.findDiffEnd(t,o,s);if(i==`end`){let e=Math.max(0,a-Math.min(c,l));r-=c+e-a}if(c=c?a-r:0;a-=e,l=a+(l-c),c=a}else if(l=l?a-r:0;a-=e,c=a+(c-l),l=a}return{start:a,endA:c,endB:l}}var ec=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new wo,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(sc),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=rc(this),nc(this),this.nodeViews=ac(this),this.docView=aa(this.state.doc,tc(this),Ms(this),this.dom,this),this.domObserver=new Is(this,(e,t,n,r)=>qs(this,e,t,n,r)),this.domObserver.start(),To(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&&Oo(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(sc),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];t.state=this.state;for(let n in e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){let n=this.state,r=!1,i=!1;e.storedMarks&&this.composing&&(Qo(this),i=!0),this.state=e;let a=n.plugins!=e.plugins||this._props.plugins!=t.plugins;if(a||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=ac(this);oc(e,this.nodeViews)&&(this.nodeViews=e,r=!0)}(a||t.handleDOMEvents!=this._props.handleDOMEvents)&&Oo(this),this.editable=rc(this),nc(this);let o=Ms(this),s=tc(this),c=n.plugins!=e.plugins&&!n.doc.eq(e.doc)?`reset`:e.scrollToSelection>n.scrollToSelection?`to selection`:`preserve`,l=r||!this.docView.matchesNode(e.doc,s,o);(l||!e.selection.eq(n.selection))&&(i=!0);let u=c==`preserve`&&i&&this.dom.style.overflowAnchor==null&&Si(this);if(i){this.domObserver.stop();let t=l&&(ai||li)&&!this.composing&&!n.selection.empty&&!e.selection.empty&&ic(n.selection,e.selection);if(l){let n=li?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=$o(this)),(r||!this.docView.update(e.doc,s,o,this))&&(this.docView.updateOuterDeco(s),this.docView.destroy(),this.docView=aa(e.doc,s,o,this.dom,this)),!n||this.trackWrites&&this.dom.contains(this.trackWrites)||(t=!0)}let i=this.input.mouseDown;t||!(i&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&za(this)&&i.delaySelUpdate())?Da(this,t):(Pa(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(n),this.dragging?.node&&!n.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,n),c==`reset`?this.dom.scrollTop=0:c==`to selection`?this.scrollToSelection():u&&wi(u)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&Wr(this.dom,e)&&!this.someProp(`handleScrollToSelection`,e=>e(this))){if(this.state.selection instanceof E){let t=this.docView.domAfterPos(this.state.selection.from);k(t)&&xi(this,t.getBoundingClientRect(),e)}else xi(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e0&&ee.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Fi(this,e)}coordsAtPos(e,t=1){return zi(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(r==null)throw RangeError(`DOM position not inside the editor`);return r}endOfTextblock(e,t){return Yi(this,t||this.state,e)}pasteHTML(e,t){return as(this,``,e,!1,t||new ClipboardEvent(`paste`))}pasteText(e,t){return as(this,e,null,!0,t||new ClipboardEvent(`paste`))}serializeForClipboard(e){return io(this,e)}destroy(){this.docView&&(Do(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ms(this),this),this.dom.textContent=``):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Rr())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return jo(this,e)}domSelectionRange(){let e=this.dom.isConnected!==!1&&this.domSelection();return e?di&&this.root.nodeType===11&&Zr(this.dom.ownerDocument)==this.dom&&Vs(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};ec.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};function tc(e){let t=Object.create(null);return t.class=`ProseMirror`,t.contenteditable=String(e.editable),e.someProp(`attributes`,n=>{if(typeof n==`function`&&(n=n(e.state)),n)for(let e in n)e==`class`?t.class+=` `+n[e]:e==`style`?t.style=(t.style?t.style+`;`:``)+n[e]:!t[e]&&e!=`contenteditable`&&e!=`nodeName`&&(t[e]=String(n[e]))}),t.translate||=`no`,[_s.node(0,e.state.doc.content.size,t)]}function nc(e){if(e.markCursor){let t=document.createElement(`img`);t.className=`ProseMirror-separator`,t.setAttribute(`mark-placeholder`,`true`),t.setAttribute(`alt`,``),e.cursorWrapper={dom:t,deco:_s.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function rc(e){return!e.someProp(`editable`,t=>t(e.state)===!1)}function ic(e,t){let n=Math.min(e.$anchor.sharedDepth(e.head),t.$anchor.sharedDepth(t.head));return e.$anchor.start(n)!=t.$anchor.start(n)}function ac(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp(`nodeViews`,n),e.someProp(`markViews`,n),t}function oc(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r}function sc(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError(`Plugins passed directly to the view must not have a state component`)}for(var cc={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:`'`},lc={48:`)`,49:`!`,50:`@`,51:`#`,52:`$`,53:`%`,54:`^`,55:`&`,56:`*`,57:`(`,59:`:`,61:`+`,173:`_`,186:`:`,187:`+`,188:`<`,189:`_`,190:`>`,191:`?`,192:`~`,219:`{`,220:`|`,221:`}`,222:`"`},uc=typeof navigator<`u`&&/Mac/.test(navigator.platform),dc=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),fc=0;fc<10;fc++)cc[48+fc]=cc[96+fc]=String(fc);for(var fc=1;fc<=24;fc++)cc[fc+111]=`F`+fc;for(var fc=65;fc<=90;fc++)cc[fc]=String.fromCharCode(fc+32),lc[fc]=String.fromCharCode(fc);for(var pc in cc)lc.hasOwnProperty(pc)||(lc[pc]=cc[pc]);function mc(e){var t=!(uc&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||dc&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?lc:cc)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var hc=typeof navigator<`u`&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),gc=typeof navigator<`u`&&/Win/.test(navigator.platform);function _c(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n==`Space`&&(n=` `);let r,i,a,o;for(let e=0;e=t?Cc.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},Cc.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},Cc.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},Cc.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(t,n){return r.push(e(t,n))},t,n),r},Cc.from=function(e){return e instanceof Cc?e:e&&e.length?new wc(e):Cc.empty};var wc=function(e){function t(t){e.call(this),this.values=t}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(e,n){return e==0&&n==this.length?this:new t(this.values.slice(e,n))},t.prototype.getInner=function(e){return this.values[e]},t.prototype.forEachInner=function(e,t,n,r){for(var i=t;i=n;i--)if(e(this.values[i],r+i)===!1)return!1},t.prototype.leafAppend=function(e){if(this.length+e.length<=Sc)return new t(this.values.concat(e.flatten()))},t.prototype.leafPrepend=function(e){if(this.length+e.length<=Sc)return new t(e.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(Cc);Cc.empty=new wc([]);var Tc=function(e){function t(t,n){e.call(this),this.left=t,this.right=n,this.length=t.length+n.length,this.depth=Math.max(t.depth,n.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(e){return ei&&this.right.forEachInner(e,Math.max(t-i,0),Math.min(this.length,n)-i,r+i)===!1)return!1},t.prototype.forEachInvertedInner=function(e,t,n,r){var i=this.left.length;if(t>i&&this.right.forEachInvertedInner(e,t-i,Math.max(n,i)-i,r+i)===!1||n=n?this.right.slice(e-n,t-n):this.left.slice(e,n).append(this.right.slice(0,t-n))},t.prototype.leafAppend=function(e){var n=this.right.leafAppend(e);if(n)return new t(this.left,n)},t.prototype.leafPrepend=function(e){var n=this.left.leafPrepend(e);if(n)return new t(n,this.right)},t.prototype.appendInner=function(e){return this.left.depth>=Math.max(this.right.depth,e.depth)+1?new t(this.left,new t(this.right,e)):new t(this,e)},t}(Cc),Ec=500,Dc=class e{constructor(e,t){this.items=e,this.eventCount=t}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,a;n&&(i=this.remapping(r,this.items.length),a=i.maps.length);let o=t.tr,s,c,l=[],u=[];return this.items.forEach((t,n)=>{if(!t.step)i||(i=this.remapping(r,n+1),a=i.maps.length),a--,u.push(t);else{if(i){u.push(new kc(t.map));let e=t.step.map(i.slice(a)),n;e&&o.maybeStep(e).doc&&(n=o.mapping.maps[o.mapping.maps.length-1],l.push(new kc(n,void 0,void 0,l.length+u.length))),a--,n&&i.appendMap(n,a)}else o.maybeStep(t.step);if(t.selection)return s=i?t.selection.map(i.slice(a)):t.selection,c=new e(this.items.slice(0,r).append(u.reverse().concat(l)),this.eventCount-1),!1}},this.items.length,0),{remaining:c,transform:o,selection:s}}addTransform(t,n,r,i){let a=[],o=this.eventCount,s=this.items,c=!i&&s.length?s.get(s.length-1):null;for(let e=0;ejc&&(s=Oc(s,l),o-=l),new e(s.append(a),o)}remapping(e,t){let n=new ht;return this.items.forEach((t,r)=>{let i=t.mirrorOffset!=null&&r-t.mirrorOffset>=e?n.maps.length-t.mirrorOffset:void 0;n.appendMap(t.map,i)},e,t),n}addMaps(t){return this.eventCount==0?this:new e(this.items.append(t.map(e=>new kc(e))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;n=Math.min(this.items.length,n);let r=[],i=this.items.length-n,a=t.mapping,o=t.steps.length,s=this.eventCount;this.items.forEach(e=>{e.selection&&s--},i);let c=n;this.items.forEach(e=>{let n=a.getMirror(--c);if(n==null)return;o=Math.min(o,n);let i=a.maps[n];if(e.step){let o=t.steps[n].invert(t.docs[n]),l=e.selection&&e.selection.map(a.slice(c+1,n));l&&s++,r.push(new kc(i,o,l))}else r.push(new kc(i))},i);let l=[];for(let e=n;eEc&&(d=d.compress(this.items.length-r.length)),d}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],a=0;return this.items.forEach((e,o)=>{if(o>=t)i.push(e),e.selection&&a++;else if(e.step){let t=e.step.map(n.slice(r)),o=t&&t.getMap();if(r--,o&&n.appendMap(o,r),t){let s=e.selection&&e.selection.map(n.slice(r));s&&a++;let c=new kc(o.invert(),t,s),l,u=i.length-1;(l=i.length&&i[u].merge(c))?i[u]=l:i.push(c)}}else e.map&&r--},this.items.length,0),new e(Cc.from(i.reverse()),a)}};Dc.empty=new Dc(Cc.empty,0);function Oc(e,t){let n;return e.forEach((e,r)=>{if(e.selection&&t--==0)return n=r,!1}),e.slice(n)}var kc=class e{constructor(e,t,n,r){this.map=e,this.step=t,this.selection=n,this.mirrorOffset=r}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new e(n.getMap().invert(),n,this.selection)}}},Ac=class{constructor(e,t,n,r,i){this.done=e,this.undone=t,this.prevRanges=n,this.prevTime=r,this.prevComposition=i}},jc=20;function Mc(e,t,n,r){let i=n.getMeta(Vc),a;if(i)return i.historyState;n.getMeta(Hc)&&(e=new Ac(e.done,e.undone,null,0,-1));let o=n.getMeta(`appendedTransaction`);if(n.steps.length==0)return e;if(o&&o.getMeta(Vc))return o.getMeta(Vc).redo?new Ac(e.done.addTransform(n,void 0,r,zc(t)),e.undone,Pc(n.mapping.maps),e.prevTime,e.prevComposition):new Ac(e.done,e.undone.addTransform(n,void 0,r,zc(t)),null,e.prevTime,e.prevComposition);if(n.getMeta(`addToHistory`)!==!1&&!(o&&o.getMeta(`addToHistory`)===!1)){let i=n.getMeta(`composition`),a=e.prevTime==0||!o&&e.prevComposition!=i&&(e.prevTime<(n.time||0)-r.newGroupDelay||!Nc(n,e.prevRanges)),s=o?Fc(e.prevRanges,n.mapping):Pc(n.mapping.maps);return new Ac(e.done.addTransform(n,a?t.selection.getBookmark():void 0,r,zc(t)),Dc.empty,s,n.time,i??e.prevComposition)}return(a=n.getMeta(`rebased`))?new Ac(e.done.rebased(n,a),e.undone.rebased(n,a),Fc(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new Ac(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),Fc(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function Nc(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((e,r)=>{for(let i=0;i=t[i]&&(n=!0)}),n}function Pc(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((e,n,r,i)=>t.push(r,i));return t}function Fc(e,t){if(!e)return null;let n=[];for(let r=0;r{let i=Vc.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let a=Ic(i,n,e);a&&r(t?a.scrollIntoView():a)}return!0}}var Gc=Wc(!1,!0),Kc=Wc(!0,!0);function qc(e){return e.getMeta(Vc)!=null}function Jc(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:a}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return a},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,a=n.storedMarks,n}}}var Yc=class e{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,a=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(a);return!i.getMeta(`preventDispatch`)&&!this.hasCustomState&&r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o=[],s=!!e,c=e||i.tr,l=()=>(!s&&t&&!c.getMeta(`preventDispatch`)&&!this.hasCustomState&&a.dispatch(c),o.every(e=>e===!0)),u={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(c,t),i=n(...e)(r);return o.push(i),u}])),run:l};return u}static createFakeChain(){let e=new Proxy({},{get:(t,n)=>{if(n!==`then`)return n===`run`?()=>!1:()=>e}});return e}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}static createFallbackCan(){let t=e.createFakeChain();return new Proxy({chain:()=>t},{get:(e,t)=>{if(t!==`then`)return t===`chain`?e.chain:()=>!1}})}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:a}=r,o={tr:e,editor:r,view:a,state:Jc({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},Xc=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{if(!e.isDestroyed){var n;t.dom.blur(),(n=window)==null||(n=n.getSelection())==null||n.removeAllRanges()}}),!0),Zc=(e=!0)=>({commands:t})=>t.setContent(``,{emitUpdate:e}),Qc=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return n&&i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,a=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),s=a.blockRange(o);if(!s)return;let c=Nt(s);if(e.type.isTextblock){let{defaultType:e}=a.parent.contentMatchAt(a.index());t.setNodeMarkup(s.start,e)}(c||c===0)&&t.lift(s,c)})}),!0},$c=e=>t=>e(t),el=()=>({state:e,dispatch:t})=>cr(e,t),tl=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,a=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,a.content),r.setSelection(new T(r.doc.resolve(Math.max(o-1,0)))),!0},nl=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;--n)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function rl(e,t){if(typeof e==`string`){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var il=e=>({tr:t,state:n,dispatch:r})=>{let i=rl(e,n.schema),a=t.selection.$anchor;for(let e=a.depth;e>0;--e)if(a.node(e).type===i){if(r){let n=a.before(e),r=a.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},al=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},ol=e=>e.content?/^text(\*|\+)/.test(e.content):!1,sl=(e,t,n)=>{if(!e.parent.isInline||n===`left`&&e.pos>e.start()||n===`right`&&e.pos({from:sl(e,n,`left`),to:sl(t,n,`right`)}),ll=()=>({state:e,dispatch:t})=>{if(e.selection.empty)return!1;if(t){let n=e.tr,{ranges:r}=e.selection,i=e.selection instanceof T?e.selection.$from.marksAcross(e.selection.$to):null,a=n.steps.length;r.forEach(t=>{let r=n.mapping.slice(a),{from:i,to:o}=cl(n.doc.resolve(r.map(t.$from.pos)),n.doc.resolve(r.map(t.$to.pos)),e.schema);n.deleteRange(i,o)}),n.selection.empty||n.setSelection(T.near(n.doc.resolve(n.selection.from))),i&&n.ensureMarks(i),n.scrollIntoView(),t(n)}return!0},ul=()=>({commands:e})=>e.keyboardShortcut(`Enter`),dl=()=>({state:e,dispatch:t})=>sr(e,t);function fl(e){return Object.prototype.toString.call(e)===`[object RegExp]`}function pl(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:fl(t[r])?t[r].test(e[r]):t[r]===e[r])}function ml(e,t,n={}){return e.find(e=>e.type===t&&pl(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function hl(e,t,n={}){return!!ml(e,t,n)}function gl(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!ml([...r.node.marks],t,n))return;let i=r.index,a=e.start()+r.offset,o=i+1,s=a+r.node.nodeSize;for(;i>0&&hl([...e.parent.child(i-1).marks],t,n);)--i,a-=e.parent.child(i).nodeSize;for(;o({tr:n,state:r,dispatch:i})=>{let a=_l(e,r.schema),{doc:o,selection:s}=n,{$from:c,from:l,to:u}=s;if(i){let e=gl(c,a,t);if(e&&e.from<=l&&e.to>=u){let t=T.create(o,e.from,e.to);n.setSelection(t)}}return!0},yl=e=>t=>{let n=typeof e==`function`?e(t):e;for(let e=0;e({editor:n,view:r,tr:i,dispatch:a})=>{t={scrollIntoView:!0,...t};let o=()=>{(wl()||Cl())&&r.dom.focus(),Tl()&&!wl()&&!Cl()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),t?.scrollIntoView&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&e===null||e===!1)return!0}catch{return!1}if(a&&e===null&&!bl(n.state.selection))return o(),!0;let s=Sl(i.doc,e)||n.state.selection,c=n.state.selection.eq(s);return a&&(c||i.setSelection(s),c&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},Dl=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),Ol=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),kl=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;--n){let r=t[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):r.nodeType===1&&kl(r)}return e};function Al(e){if(typeof window>`u`)throw Error(`[tiptap error]: there is no window object available, so this function cannot be used`);let t=`${e}`,n=new window.DOMParser().parseFromString(t,`text/html`).body;return kl(n)}function jl(e){return typeof e?.nodesBetween==`function`}function Ml(e,t,n){if(jl(e))return e;let r=typeof e==`object`&&!!e;n={slice:!0,parseOptions:{},...n};let i=typeof e==`string`;if(r)try{if(Array.isArray(e)&&e.length>0)return s.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error(`[tiptap error]: Invalid JSON content`,{cause:r});return console.warn(`[tiptap warn]: Invalid content.`,`Passed value:`,e,`Error:`,r),Ml(``,t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i=``,a=new Ne({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:`inline*`,group:`block`,parseDOM:[{tag:`*`,getAttrs:e=>(r=!0,i=typeof e==`string`?e:e.outerHTML,null)}]}})});if(n.slice?Le.fromSchema(a).parseSlice(Al(e),n.parseOptions):Le.fromSchema(a).parse(Al(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error(`[tiptap error]: Invalid HTML content`,{cause:Error(`Invalid element found: ${i}`)})}let r=Le.fromSchema(t);return n.slice?r.parseSlice(Al(e),n.parseOptions).content:r.parse(Al(e),n.parseOptions)}return Ml(``,t,n)}function Nl(e){return!(`type`in e)}function Pl(e,t,n){let r=e.steps.length-1;if(r{o===0&&(o=r)}),e.setSelection(w.near(e.doc.resolve(o),n))}var Fl=(e,t,n)=>({tr:r,dispatch:i,editor:a})=>{if(i){n={parseOptions:a.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let i,o=e=>{a.emit(`contentError`,{editor:a,error:e,disableCollaboration:()=>{`collaboration`in a.storage&&typeof a.storage.collaboration==`object`&&a.storage.collaboration&&(a.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:`full`,...n.parseOptions};if(!n.errorOnInvalidContent&&!a.options.enableContentCheck&&a.options.emitContentError)try{Ml(t,a.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){o(e)}try{i=Ml(t,a.schema,{parseOptions:c,errorOnInvalidContent:n.errorOnInvalidContent??a.options.enableContentCheck})}catch(e){return o(e),!1}let{from:l,to:u}=typeof e==`number`?{from:e,to:e}:{from:e.from,to:e.to},d=!0,f=!0,p=Nl(i)?i.content:[i];if(p.forEach(e=>{e.check(),d=d?e.isText&&e.marks.length===0:!1,f=f?e.isBlock:!1}),l===u&&f){let{parent:e}=r.doc.resolve(l);e.isTextblock&&!e.type.spec.code&&!e.childCount&&(--l,u+=1)}let m;if(d)m=Array.isArray(t)?t.map(e=>e.text||``).join(``):jl(t)?p.map(e=>e.text??``).join(``):typeof t==`object`&&t&&t.text?t.text:t,r.insertText(m,l,u);else{m=s.from(p);let e=r.doc.resolve(l),t=e.node(),n=e.parentOffset===0,i=t.isText||t.isTextblock,a=t.content.size>0;n&&i&&a&&f&&(l=Math.max(0,l-1)),r.replaceWith(l,u,p)}n.updateSelection&&Pl(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta(`applyInputRules`,{from:l,text:m}),n.applyPasteRules&&r.setMeta(`applyPasteRules`,{from:l,text:m})}return!0};function Il(e){for(let t=0;t({tr:t,dispatch:n,editor:r})=>{let{pos:i,attrs:a,content:o,updateSelection:s=!0}=e,c;c=typeof i==`number`?t.doc.resolve(i):i||t.selection.$from;let l=Il(c.parent.contentMatchAt(c.index()));if(!l)return!1;let u=Object.keys(l.spec.attrs||{}),d=a?Object.fromEntries(Object.entries(a).filter(([e])=>u.includes(e))):{},f;if(o){let e=Ml(o,r.schema);f=l.createAndFill(d,e)}else f=l.createAndFill(d);return f?(n&&(t.insert(c.pos,f),s&&Pl(t,t.steps.length-1,-1)),!0):!1},Rl=()=>({state:e,dispatch:t})=>nr(e,t),zl=()=>({state:e,dispatch:t})=>rr(e,t),Bl=()=>({state:e,dispatch:t})=>Gn(e,t),Vl=()=>({state:e,dispatch:t})=>$n(e,t),Hl=(e,t)=>{let n=e.resolve(t),r=n.nodeBefore,i=n.nodeAfter;return!r||!i?!1:!r.type.spec.isolating&&!i.type.spec.isolating},Ul=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Xt(e.doc,e.selection.$from.pos,-1);return r==null||!Hl(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Wl=()=>({state:e,dispatch:t,tr:n})=>{try{let r=Xt(e.doc,e.selection.$from.pos,1);return r==null||!Hl(e.doc,r)?!1:(n.join(r,2),t&&t(n),!0)}catch{return!1}},Gl=()=>({state:e,dispatch:t})=>Kn(e,t),Kl=()=>({state:e,dispatch:t})=>qn(e,t);function ql(){return typeof navigator<`u`&&/Mac/.test(navigator.platform)}function Jl(e){let t=e.split(/-(?!$)/),n=t[t.length-1];n===`Space`&&(n=` `);let r,i,a,o;for(let e=0;e({editor:t,view:n,tr:r,dispatch:i})=>{let a=Jl(e).split(/-(?!$)/),o=a.find(e=>![`Alt`,`Ctrl`,`Meta`,`Shift`].includes(e)),s=new KeyboardEvent(`keydown`,{key:o===`Space`?` `:o,altKey:a.includes(`Alt`),ctrlKey:a.includes(`Ctrl`),metaKey:a.includes(`Meta`),shiftKey:a.includes(`Shift`),bubbles:!0,cancelable:!0});return t.captureTransaction(()=>{n.someProp(`handleKeyDown`,e=>e(n,s))})?.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function Xl(e,t,n={}){let{from:r,to:i,empty:a}=e.selection,o=t?rl(t,e.schema):null,s=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),a=Math.min(i,t+e.nodeSize);s.push({node:e,from:n,to:a})});let c=i-r,l=s.filter(e=>!o||o.name===e.node.type.name).filter(e=>pl(e.node.attrs,n,{strict:!1}));return a?!!l.length:l.reduce((e,t)=>e+t.to-t.from,0)>=c}var Zl=(e,t={})=>({state:n,dispatch:r})=>Xl(n,rl(e,n.schema),t)?ir(n,r):!1,Ql=()=>({state:e,dispatch:t})=>lr(e,t),$l=e=>({state:t,dispatch:n})=>Ar(rl(e,t.schema))(t,n),eu=()=>({state:e,dispatch:t})=>ar(e,t);function tu(e,t){return t.nodes[e]?`node`:t.marks[e]?`mark`:null}function nu(e,t){let n=typeof t==`string`?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var ru=(e,t)=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=tu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=rl(e,r.schema)),s===`mark`&&(o=_l(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,nu(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(a=>{o===a.type&&(c=!0,i&&n.addMark(r,r+e.nodeSize,o.create(nu(a.attrs,t))))})})}),c},iu=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),au=()=>({tr:e,dispatch:t})=>{if(t){let t=new Dn(e.doc);e.setSelection(t)}return!0},ou=()=>({state:e,dispatch:t})=>Xn(e,t),su=()=>({state:e,dispatch:t})=>er(e,t),cu=()=>({state:e,dispatch:t})=>fr(e,t),lu=()=>({state:e,dispatch:t})=>vr(e,t),uu=()=>({state:e,dispatch:t})=>_r(e,t);function du(e,t,n={},r={}){return Ml(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var fu=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:a,dispatch:o,commands:s})=>{let{doc:c}=a;if(r.preserveWhitespace!==`full`){let s=du(e,i.schema,r,{errorOnInvalidContent:t??i.options.enableContentCheck});if(o){let e=Nl(s)?s.content:[s];a.replaceWith(0,c.content.size,e).setMeta(`preventUpdate`,!n)}return!0}return o&&a.setMeta(`preventUpdate`,!n),s.insertContentAt({from:0,to:c.content.size},e,{parseOptions:r,errorOnInvalidContent:t??i.options.enableContentCheck})};function pu(e,t){let n=_l(t,e.schema),{from:r,to:i,empty:a}=e.selection,o=[];a?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let s=o.find(e=>e.type.name===n.name);return s?{...s.attrs}:{}}function mu(e,t){let n=new bn(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function hu(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function gu(e,t,n){let r=[];return e.nodesBetween(t.from,t.to,(e,t)=>{n(e)&&r.push({node:e,pos:t})}),r}function _u(e,t){for(let n=e.depth;n>0;--n){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function vu(e){return t=>_u(t.$from,e)}function A(e,t,n){return e.config[t]===void 0&&e.parent?A(e.parent,t,n):typeof e.config[t]==`function`?e.config[t].bind({...n,parent:e.parent?A(e.parent,t,n):null}):e.config[t]}function yu(e){return e.map(e=>{let t=A(e,`addExtensions`,{name:e.name,options:e.options,storage:e.storage});return t?[e,...yu(t())]:e}).flat(10)}function bu(e,t){let n=Ze.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement(`div`);return r.appendChild(n),r.innerHTML}function xu(e,t){let n=new Map;for(let t of e){let e=n.get(t.type)??new Map;e.set(t.name,t),n.set(t.type,e)}return[...Object.values(t.nodes),...Object.values(t.marks)].flatMap(e=>Object.entries(e.spec.attrs??{}).map(([t,r])=>{let i=n.get(e.name)?.get(t),a=Object.hasOwn(r,`default`);return{type:e.name,name:t,attribute:{rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,...i?.attribute,default:r.default,isRequired:!a,validate:r.validate}}}))}var Su={content:`string`,marks:`string`,group:`string`,inline:`boolean`,atom:`boolean`,selectable:`boolean`,draggable:`boolean`,code:`boolean`,whitespace:[`pre`,`normal`],definingAsContext:`boolean`,definingForContent:`boolean`,defining:`boolean`,isolating:`boolean`,linebreakReplacement:`boolean`},Cu={inclusive:`boolean`,excludes:`string`,group:`string`,spanning:`boolean`,code:`boolean`};function wu(e,t,n){return Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e[t];if(i===void 0)return[];if(!(typeof r==`string`?typeof i===r:typeof i==`string`&&r.includes(i)))throw RangeError(`Invalid schemaSpec field '${n}.${t}'`);return[[t,i]]}))}function Tu(e,t,n,r){return{...Object.fromEntries(Object.entries(t).filter(([e])=>e!==`attrs`&&!Object.hasOwn(r,e))),...wu(n,r,e),attrs:n.attrs}}function Eu(e,t,n){for(let r of Object.keys(t))if(!Object.hasOwn(e,r))throw RangeError(`schemaSpec requires a local ${n} extension named '${r}'`);for(let r of Object.keys(e))if(!Object.hasOwn(t,r))throw RangeError(`Local ${n} extension '${r}' is not in schemaSpec`)}function Du(e,t){Eu(e.nodes,t.nodes,`node`),Eu(e.marks,t.marks,`mark`);let n=t.spec.nodes,r=t.spec.marks;return t.spec.nodes.forEach((t,r)=>{n=n.update(t,Tu(t,e.nodes[t],r,Su))}),t.spec.marks.forEach((t,n)=>{r=r.update(t,Tu(t,e.marks[t],n,Cu))}),{topNode:t.topNodeType.name,nodes:n,marks:r}}function Ou(e){let t=e.filter((t,n)=>e.indexOf(t)!==n);return Array.from(new Set(t))}function ku(e){return{baseExtensions:e.filter(e=>e.type===`extension`),nodeExtensions:e.filter(e=>e.type===`node`),markExtensions:e.filter(e=>e.type===`mark`)}}function Au(e){let t=[],{nodeExtensions:n,markExtensions:r}=ku(e),i=[...n,...r],a={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>e.name!==`text`).map(e=>e.name),s=r.map(e=>e.name),c=[...o,...s];return e.forEach(e=>{let n=A(e,`addGlobalAttributes`,{name:e.name,options:e.options,storage:e.storage,extensions:i});n&&n().forEach(e=>{let n;n=Array.isArray(e.types)?e.types:e.types===`*`?c:e.types===`nodes`?o:e.types===`marks`?s:[],n.forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...a,...r}})})})})}),i.forEach(e=>{let n=A(e,`addAttributes`,{name:e.name,options:e.options,storage:e.storage});if(!n)return;let r=n();Object.entries(r).forEach(([n,r])=>{let i={...a,...r};typeof i?.default==`function`&&(i.default=i.default()),i?.isRequired&&i?.default===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function ju(e){return typeof e==`function`}function Mu(e,t=void 0,...n){return ju(e)?t?e.bind(t)(...n):e(...n):e}function Nu(e={}){return Object.keys(e).length===0&&e.constructor===Object}function Pu(e){let t=[],n=``,r=!1,i=!1,a=0,o=e.length;for(let s=0;s0){--a,n+=o;continue}if(o===`;`&&a===0){t.push(n),n=``;continue}}n+=o}}return n&&t.push(n),t}function Fu(e){let t=[],n=Pu(e||``),r=n.length;for(let e=0;e!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(e===`__proto__`)Object.defineProperty(n,e,{configurable:!0,enumerable:!0,value:t,writable:!0});else if(!n[e])n[e]=t;else if(e===`class`){let r=t?String(t).split(` `):[],i=n[e]?n[e].split(` `):[],a=r.filter(e=>!i.includes(e));n[e]=[...i,...a].join(` `)}else if(e===`style`){let r=new Map([...Fu(n[e]),...Fu(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join(`; `)}else n[e]=t}),n},{})}function Iu(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>j(e,t),{})}function Lu(e){return typeof e==`string`?e.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(e):e===`true`||e!==`false`&&e:e}function Ru(e,t){return`style`in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(r===!1)return!1;let i=t.reduce((e,t)=>{let r=t.attribute.parseHTML?t.attribute.parseHTML(n):Lu(n.getAttribute(t.name));return r==null?e:{...e,[t.name]:r}},{});return{...r,...i}}}}function zu(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e===`attrs`&&Nu(t)?!1:t!=null))}function Bu(e){var t,n;let r={};return!(e!=null&&(t=e.attribute)!=null&&t.isRequired)&&`default`in(e?.attribute||{})&&(r.default=e.attribute.default),(e==null||(n=e.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function Vu(e,t,n=Au(e)){let{nodeExtensions:r,markExtensions:i}=ku(e);return{topNode:r.find(e=>A(e,`topNode`))?.name,nodes:Object.fromEntries(r.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=zu({...e.reduce((e,t)=>{let n=A(t,`extendNodeSchema`,a);return{...e,...n?n(r):{}}},{}),content:Mu(A(r,`content`,a)),marks:Mu(A(r,`marks`,a)),group:Mu(A(r,`group`,a)),inline:Mu(A(r,`inline`,a)),atom:Mu(A(r,`atom`,a)),selectable:Mu(A(r,`selectable`,a)),draggable:Mu(A(r,`draggable`,a)),code:Mu(A(r,`code`,a)),whitespace:Mu(A(r,`whitespace`,a)),linebreakReplacement:Mu(A(r,`linebreakReplacement`,a)),defining:Mu(A(r,`defining`,a)),isolating:Mu(A(r,`isolating`,a)),attrs:Object.fromEntries(i.map(Bu))}),s=Mu(A(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Ru(e,i)));let c=A(r,`renderHTML`,a);c&&(o.toDOM=e=>c({node:e,HTMLAttributes:Iu(e,i)}));let l=A(r,`renderText`,a);return l&&(o.toText=l),[r.name,o]})),marks:Object.fromEntries(i.map(r=>{let i=n.filter(e=>e.type===r.name),a={name:r.name,options:r.options,storage:r.storage,editor:t},o=zu({...e.reduce((e,t)=>{let n=A(t,`extendMarkSchema`,a);return{...e,...n?n(r):{}}},{}),inclusive:Mu(A(r,`inclusive`,a)),excludes:Mu(A(r,`excludes`,a)),group:Mu(A(r,`group`,a)),spanning:Mu(A(r,`spanning`,a)),code:Mu(A(r,`code`,a)),attrs:Object.fromEntries(i.map(Bu))}),s=Mu(A(r,`parseHTML`,a));s&&(o.parseDOM=s.map(e=>Ru(e,i)));let c=A(r,`renderHTML`,a);return c&&(o.toDOM=e=>c({mark:e,HTMLAttributes:Iu(e,i)})),[r.name,o]}))}}function Hu(e,t,n){if(n===void 0)return new Ne(Vu(e,t));let r=Ou(e.filter(e=>e.type!==`extension`).map(e=>e.name));if(r.length)throw RangeError(`Duplicate local schema types: ${r.join(`, `)}`);let i=new Ne(n);return new Ne(Du(Vu(e,t,xu(Au(e),i)),i))}function Uu(e){return e.sort((e,t)=>{let n=A(e,`priority`)||100,r=A(t,`priority`)||100;return n>r?-1:+(ne.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(e=>`'${e}'`).join(`, `)}]. This can lead to issues.`),t}function Gu(e,t,n){let{from:r,to:i}=t,{blockSeparator:a=` -`,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;if(e.isText){var d;s+=e==null||(d=e.text)==null?void 0:d.slice(Math.max(r,n)-n,i-n)}}),s}function qu(e,t){return Ku(e,{from:0,to:e.content.size},t)}function Ju(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function Yu(e,t){let n=il(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function Xu(e,t){let n=nu(typeof t==`string`?t:t.name,e.schema);return n===`node`?Yu(e,t):n===`mark`?mu(e,t):{}}function Zu(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function Qu(e){let t=Zu(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function $u(e){let{mapping:t,steps:n}=e,r=[],i=t.invert();return t.maps.forEach((e,a)=>{let o=[];if(e.ranges.length)e.forEach((e,t)=>{o.push({from:e,to:t})});else{let{from:e,to:t}=n[a];if(e===void 0||t===void 0)return;o.push({from:e,to:t})}let s=t.slice(a);o.forEach(({from:e,to:t})=>{let n=s.map(e,-1),a=s.map(t),o=i.map(n,-1),c=i.map(a);r.push({oldRange:{from:o,to:c},newRange:{from:n,to:a}})})}),Qu(r)}function ed(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=_l(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&e?.nodeSize!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var td=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]},nd=e=>{let t=e.depth-1;if(t<0)return null;let n=e.index(t);return n===0?null:e.node(t).child(n-1)};function rd(e,t){return t.nodes[e]||t.marks[e]||null}function id(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var ad=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function od(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?vl(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!a||a.name===e.type.name).find(e=>ml(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(a&&e.inlineContent&&!e.type.allowsMarkType(a))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),c=Math.min(i,t+e.nodeSize),l=c-n;o+=l,s.push(...e.marks.map(e=>({mark:e,from:n,to:c})))})}),o===0)return!1;let c=s.filter(e=>!a||a.name===e.mark.type.name).filter(e=>ml(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>!a||e.mark.type!==a&&e.mark.type.excludes(a)).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function sd(e,t,n={}){if(!t)return Zl(e,null,n)||od(e,null,n);let r=nu(t,e.schema);return r===`node`?Zl(e,t,n):r===`mark`&&od(e,t,n)}var cd=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=yu(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function ud(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function dd(e,t){let{nodeExtensions:n}=Au(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=Nu(k(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`&&i.split(` `).includes(`list`)}function fd(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return!/\S/.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(fd(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function pd(e){return e instanceof E}function md(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.apply==`function`&&typeof t.getMap==`function`&&typeof t.invert==`function`&&typeof t.map==`function`&&typeof t.merge==`function`&&typeof t.toJSON==`function`}function hd(e){if(typeof e!=`object`||!e)return!1;let t=e;if(!md(t))return!1;let n=t.toJSON();return!(typeof n!=`object`||!n||n.stepType!==`replace`)}var gd=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function _d(e,t){let n=t.mapping.mapResult(e.position);return{position:new gd(n.pos),mapResult:n}}function vd(e){return new gd(e)}function yd(e,t,n){let{selection:r}=t,i=null;if(xl(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var bd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=vl(e,r.schema);if(i){if(o){let e=mu(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})})}return yd(r,n,c)},xd=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),Sd=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=il(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>xr(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>xr(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},Cd=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=Sl(e,0,n.content.size),i=E.create(n,r);t.setSelection(i)}return!0},wd=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},Td=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=T.atStart(n).from,o=T.atEnd(n).to,s=Sl(r,a,o),c=Sl(i,a,o),l=T.create(n,s,c);t.setSelection(l)}return!0},Ed=e=>({state:t,dispatch:n})=>Pr(il(e,t.schema))(t,n);function Dd(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var Od=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=id(l,s.node().type.name,s.node().attrs);if(a instanceof E&&a.node.isBlock)return!s.parentOffset||!Gt(o,s.pos)?!1:(r&&(e&&Dd(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Ll(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=a instanceof T&&!a.empty?zn.create({doc:t.doc,selection:a}).tr.deleteSelection():null,h=m?m.doc:t.doc,g=m?m.mapping.map(s.pos):s.pos,_=Gt(h,g,1,p);if(!p&&!_&&Gt(h,g,1,f?[{type:f}]:void 0)&&(_=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(_){let e=t.steps.length;if(a instanceof T&&t.deleteSelection(),t.split(t.mapping.slice(e).map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f){let n=t.mapping.slice(e).map(s.before()),r=t.doc.resolve(n);s.node(-1).canReplaceWith(r.index(),r.index()+1,f)&&t.setNodeMarkup(t.mapping.slice(e).map(s.before()),f)}}e&&Dd(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return _},kd=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=il(e,r.schema),{$from:c,$to:l}=r.selection,u=r.selection.node;if(u&&u.isBlock||c.depth<2||!c.sameParent(l))return!1;let d=c.node(-1);if(d.type!==o)return!1;let f=a.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==o||c.index(-2)!==c.node(-2).childCount-1)return!1;if(i){let e=s.empty,r=c.index(-1)?1:c.index(-2)?2:3;for(let t=c.depth-r;t>=c.depth-3;--t)e=s.from(c.node(t).copy(e));let i=c.indexAfter(-1){if(d>-1)return!1;e.isTextblock&&e.content.size===0&&(d=t+1)}),d>-1&&n.setSelection(T.near(n.doc.resolve(d))),n.scrollIntoView()}return!0}let m=l.pos===c.end()?d.contentMatchAt(0).defaultType:null,h={...id(f,d.type.name,d.attrs),...t},g={...id(f,c.node().type.name,c.node().attrs),...t},_=c.parentOffset===0&&c.index(-1)===0,v=c.before(-1);n.delete(c.pos,l.pos);let y=_?d.attrs:h,b=m?[{type:o,attrs:y},{type:m,attrs:g}]:[{type:o,attrs:y}];if(!Gt(n.doc,c.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,s=t||e.$to.parentOffset&&e.$from.marks();if(n.split(c.pos,2,b).scrollIntoView(),_&&n.setNodeMarkup(v,void 0,h),!s||!i)return!0;let l=s.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0};function Ad(e,t,n){if(!e.validContent(t))return null;try{return e.create(n,t)}catch{return null}}function jd(e,t){if(e.pendingContent.length===0)return!0;let n=Ad(t,s.from(e.pendingContent));return n?(e.items.push(n),e.pendingContent=[],!0):!1}function Md(e,t,n){return n.validContent(s.from([...t.pendingContent,e]))?(t.pendingContent.push(e),!0):!jd(t,n)||!n.validContent(s.from(e))?!1:(t.pendingContent.push(e),!0)}function Nd(e,t,n,r){let i=r(e,n);if(!i)return!1;let a=Ad(n.listType,s.from(i),e.attrs);return a?n.itemType.validContent(s.from([...t.pendingContent,a]))?(t.pendingContent.push(a),!0):jd(t,n.itemType)?(t.items.push(...i),!0):!1:!1}function Pd(e,t,n){let r={items:[],pendingContent:[]};for(let i=0;ie!==t||(n=r,!1)),n}function Ld(e){return!e||e===`1`?null:e}function Rd(e,t){return Ld(e)===Ld(t)}var zd=(e,t)=>{let n=yu(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&qt(e.doc,n.pos))||!Rd(n.node.attrs.type,i?.attrs.type)||e.join(n.pos),!0},Bd=(e,t)=>{let n=yu(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&qt(e.doc,r))||!Rd(n.node.attrs.type,i?.attrs.type)||e.join(r),!0};function Vd(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return T.between(r,i)}var Hd=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:c,chain:l,commands:u,can:d})=>{let{extensions:f,splittableMarks:p}=i.extensionManager,m=il(e,o.schema),h=il(t,o.schema),{selection:g,storedMarks:_}=o,{$from:v,$to:y}=g,b=v.blockRange(y),x=_||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;let S=yu(e=>dd(e.type.name,f))(g),C=g.from===0&&g.to===o.doc.content.size,ee=o.doc.content.content,te=ee.length===1?ee[0]:null,ne=C&&te&&dd(te.type.name,f)?{node:te,pos:0,depth:0}:null,re=S??ne,ie=!!S&&b.depth>=1&&b.depth-S.depth<=1,ae=!!ne;if((ie||ae)&&re){if(re.node.type===m)return C&&ae?l().command(({tr:e,dispatch:t})=>{let n=Vd(e);return n?(e.setSelection(n),t&&t(e),!0):!1}).liftListItem(h).run():u.liftListItem(h);if(dd(re.node.type.name,f)&&m.validContent(re.node.content))return l().command(()=>(a.setNodeMarkup(re.pos,m),!0)).command(()=>zd(a,m)).command(()=>Bd(a,m)).run();if(dd(re.node.type.name,f)){let e=re.node.firstChild?.type;if(e&&e!==h){let e=Fd(re.node,{listType:m,itemType:h,isListNode:e=>dd(e.type.name,f)}),t=e?s.from(e):null;return!t||!m.validContent(t)?!1:l().command(()=>{let{$anchor:e,$head:n}=a.selection,i=e.parent,o=n.parent,s=e.parentOffset,c=n.parentOffset,l;try{l=m.create(r,t)}catch{return!1}if(a.replaceWith(re.pos,re.pos+re.node.nodeSize,l),i.inlineContent&&o.inlineContent){let e=Id(l,i),t=Id(l,o);if(e!==null&&t!==null){let n=re.pos+e+2+s,r=re.pos+t+2+c;a.setSelection(T.create(a.doc,n,r))}}return!0}).command(()=>zd(a,m)).command(()=>Bd(a,m)).run()}}}return!n||!x||!c?l().command(()=>d().wrapInList(m,r)?!0:u.clearNodes()).wrapInList(m,r).command(()=>zd(a,m)).command(()=>Bd(a,m)).run():l().command(()=>{let e=d().wrapInList(m,r),t=x.filter(e=>p.includes(e.type.name));return a.ensureMarks(t),e?!0:u.clearNodes()}).wrapInList(m,r).command(()=>zd(a,m)).command(()=>Bd(a,m)).run()},Ud=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=vl(e,r.schema);return od(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},Wd=(e,t,n={})=>({state:r,commands:i})=>{let a=il(e,r.schema),o=il(t,r.schema),s=Zl(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},Gd=(e,t={})=>({state:n,commands:r})=>{let i=il(e,n.schema);return Zl(n,i,t)?r.lift(i):r.wrapIn(i,t)},Kd=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},qd=(e={})=>({tr:t,dispatch:n,editor:r})=>{let{ignoreClearable:i=!1}=e,{selection:a}=t,{empty:o,ranges:s}=a;if(o)return!0;let{nonClearableMarks:c}=r.extensionManager;if(n){let e=Object.values(r.schema.marks).filter(e=>i||!c.includes(e.name));s.forEach(n=>{for(let r of e)t.removeMark(n.$from.pos,n.$to.pos,r)})}return!0},Jd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=vl(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=_l(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},Yd=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},Xd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=nu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=il(e,r.schema)),s===`mark`&&(o=vl(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},Zd=new Un(`__tiptap_decorations__`),Qd=e=>({tr:t,dispatch:n})=>(n&&t.setMeta(Zd,{type:`force`,name:e}),!0),$d=(e,t={})=>({state:n,dispatch:r})=>br(il(e,n.schema),t)(n,r),ef=(e,t={})=>({state:n,dispatch:r})=>Dr(il(e,n.schema),t)(n,r),tf=t({blur:()=>Zc,clearContent:()=>Qc,clearNodes:()=>$c,command:()=>el,createParagraphNear:()=>tl,cut:()=>nl,deleteCurrentNode:()=>rl,deleteNode:()=>al,deleteRange:()=>ol,deleteSelection:()=>ul,enter:()=>dl,exitCode:()=>fl,extendMarkRange:()=>yl,first:()=>bl,focus:()=>Dl,forEach:()=>Ol,insertContent:()=>kl,insertContentAt:()=>Il,insertDefaultBlock:()=>Rl,joinBackward:()=>Vl,joinDown:()=>Bl,joinForward:()=>Hl,joinItemBackward:()=>Wl,joinItemForward:()=>Gl,joinTextblockBackward:()=>Kl,joinTextblockForward:()=>ql,joinUp:()=>zl,keyboardShortcut:()=>Xl,lift:()=>Ql,liftEmptyBlock:()=>$l,liftListItem:()=>eu,newlineInCode:()=>tu,resetAttributes:()=>iu,scrollIntoView:()=>au,selectAll:()=>ou,selectNodeBackward:()=>su,selectNodeForward:()=>cu,selectParentNode:()=>lu,selectTextblockEnd:()=>uu,selectTextblockStart:()=>du,setContent:()=>pu,setMark:()=>bd,setMeta:()=>xd,setNode:()=>Sd,setNodeSelection:()=>Cd,setTextDirection:()=>wd,setTextSelection:()=>Td,sinkListItem:()=>Ed,splitBlock:()=>Od,splitListItem:()=>kd,toggleList:()=>Hd,toggleMark:()=>Ud,toggleNode:()=>Wd,toggleWrap:()=>Gd,undoInputRule:()=>Kd,unsetAllMarks:()=>qd,unsetMark:()=>Jd,unsetTextDirection:()=>Yd,updateAttributes:()=>Xd,updateDecorations:()=>Qd,wrapIn:()=>$d,wrapInList:()=>ef}),nf=new WeakMap;function rf(e,t){nf.set(e,(nf.get(e)??0)+1);try{return t()}finally{let t=(nf.get(e)??1)-1;t>0?nf.set(e,t):nf.delete(e)}}function af(e){return nf.has(e)}var of=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},sf=typeof process<`u`&&!1;function cf(e){return e.kind===`widget`}function lf(e,t){let n=[],r=new Set;for(let i of e)i.kind===`widget`&&cf(i)&&r.add(i.key),n.push(i.toPMDecoration(t));return{decorations:n,widgetKeys:r}}function uf(e,t,n){let{decorations:r,widgetKeys:i}=lf(t,n);return{set:xs.create(e,r),widgetKeys:i}}function df({position:e,from:t,to:n,docSize:r}){return edf({position:e.anchor,from:t,to:n,docSize:r})?!0:(e.anchor===n||a.has(i)||(a.add(i),console.warn(`[tiptap warn]: Extension "${i}" returned a decoration outside the requested range [${t}, ${n}). It was ignored.`)),!1))}function pf(e){let t=e.spec?.key;return typeof t==`string`?t:void 0}function mf(e){let t=new Map,n=new Map;for(let r of e.find()){let e=pf(r);if(!e)continue;let i=r.spec.extensionName??`unknown`,a=t.get(e)??new Set;a.add(i),t.set(e,a),n.set(e,(n.get(e)??0)+1)}return Array.from(t,([e,t])=>({key:e,extensions:t})).filter(({key:e})=>(n.get(e)??0)>1)}function hf(e){return e.jsonID===`attr`}function gf(e){let t=!1;if(e.getMap().forEach(()=>{t=!0}),t||hf(e))return!0;let n=e;return typeof n.from==`number`&&typeof n.to==`number`}function _f(e,t){let n=null,r=0,i=0;for(let a=0;at.to);a+=1){let o=i+e.child(a).nodeSize;o>=t.from&&(n===null&&(n=i),r=o),i=o}return n===null?null:{from:n,to:r}}function vf(e,t){if(e.steps.some(e=>!gf(e)))return{type:`full`};let n=$u(e).map(({newRange:e})=>e);e.steps.forEach((t,r)=>{if(!hf(t))return;let i=e.mapping.slice(r);n.push({from:i.map(t.pos,-1),to:i.map(t.pos+1)})});let r=[];for(let e of n){let n=_f(t,e);n&&r.push(n)}r.sort((e,t)=>e.from-t.from);let i=[];for(let e of r){let t=i[i.length-1];t&&e.from<=t.to?t.to=Math.max(t.to,e.to):i.push({...e})}return{type:`ranges`,ranges:i}}function yf(e,t,n,r){return e.map(t,n,{onRemove:e=>{let t=e?.key;typeof t==`string`&&r.delete(t)}})}function bf(e,t,n){let r=t.decorationSetsByExtension[e]??xs.empty,i=new Set(t.widgetKeysByExtension[e]??[]);return{set:yf(r,n.mapping,n.doc,i),widgetKeys:i}}function xf(e,t){let n=Object.values(t).flatMap(e=>e.find());return xs.create(e,n)}function Sf(e){let t=new Set;for(let n of Object.values(e))for(let e of n)t.add(e);return t}function Cf(e,t){switch(t.update??`document`){case`document`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" provides createInRange() but does not use the "changedRanges" decoration update strategy.`);return;case`changedRanges`:if(!t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "changedRanges" decoration update strategy but does not provide createInRange().`);return;case`manual`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "manual" decoration update strategy, which is not compatible with createInRange(). createInRange() requires the "changedRanges" strategy.`);if(t.shouldUpdate)throw Error(`[tiptap error]: Extension "${e}" cannot combine the "manual" decoration update strategy with shouldUpdate().`);return;default:throw Error(`[tiptap error]: Extension "${e}" uses an unknown decoration update strategy. Expected "document", "changedRanges", or "manual".`)}}function wf(e,t,n){return n?!0:e.update===`manual`?!1:e.shouldUpdate?e.shouldUpdate(t):t.tr.docChanged}var Tf=new Set,Ef=class{constructor(e){this.warnedWidgetKeys=new Set,this.warnedOutOfRangeExtensions=new Set,this.handleBeforeTransaction=({nextState:e})=>{let t=Zd.getState(e);t&&this.warnDuplicateWidgetKeys(t)},this.editor=e.editor,this.entries=this.resolveEntries(e.entries),this.entries.forEach(({name:e,spec:t})=>Cf(e,t)),this.plugin=this.entries.length>0?this.createPlugin():null,this.editor.on(`beforeTransaction`,this.handleBeforeTransaction)}destroy(){this.editor.off(`beforeTransaction`,this.handleBeforeTransaction)}liveWidgetKeys(){return Zd.getState(this.editor.state)?.widgetKeys??Tf}get mountedView(){return this.editor.isDestroyed?null:this.editor.view}resolveEntries(e){let t=[];for(let{name:n,addDecorations:r}of e){let e=r();e&&t.push({name:n,spec:e})}return t}createPlugin(){let{editor:e,entries:t}=this;return new D({key:Zd,state:{init:(e,n)=>{let r={},i={};for(let{name:e,spec:a}of t){let{set:t,widgetKeys:o}=this.buildFullSet(e,a,n);r[e]=t,i[e]=o}let a={decorationSetsByExtension:r,widgetKeysByExtension:i,mergedDecorationSet:this.buildMergedSet(n.doc,r),widgetKeys:Sf(i)};return this.warnDuplicateWidgetKeys(a),a},apply:(n,r,i,a)=>{let o=n.getMeta(Zd),s=o?.type===`force`&&!o.name,c=o?.type===`force`?o.name:void 0,l={},u={},d=new Set;return rf(e,()=>{for(let{name:o,spec:f}of t){let t=s||c===o;if(!wf(f,{editor:e,tr:n,oldState:i,newState:a},t)){let e=bf(o,r,n);l[o]=e.set,u[o]=e.widgetKeys}else if(f.update===`changedRanges`&&n.docChanged&&!t){let e=this.applyChangedRangesRecompute(o,f,r,n,a);l[o]=e.set,u[o]=e.widgetKeys,d.add(o)}else{let{set:e,widgetKeys:t}=this.buildFullSet(o,f,a);l[o]=e,u[o]=t,d.add(o)}}}),d.size===0&&!n.docChanged?r:{decorationSetsByExtension:l,widgetKeysByExtension:u,mergedDecorationSet:this.mergeAfterApply({entries:t,previous:r,tr:n,decorationSetsByExtension:l,recomputedNames:d}),widgetKeys:Sf(u)}}},props:{decorations(e){return Zd.getState(e)?.mergedDecorationSet??xs.empty}}})}applyChangedRangesRecompute(e,t,n,r,i){let a=vf(r,i.doc);return a.type===`full`?this.buildFullSet(e,t,i):this.rebuildRanges(e,t,n,r,i,a.ranges)}rebuildRanges(e,t,n,r,i,a){let o=n.decorationSetsByExtension[e]??xs.empty,s=new Set(n.widgetKeysByExtension[e]??[]),c=yf(o,r.mapping,r.doc,s),l=i.doc.content.size;for(let{from:n,to:r}of a){let a=c.find(n,r).filter(e=>df({position:e.from,from:n,to:r,docSize:l}));for(let e of a){let t=pf(e);t&&s.delete(t)}c=c.remove(a);let{decorations:o,widgetKeys:u}=lf(ff({decorations:this.runCreate(e,`createInRange`,()=>t.createInRange({editor:this.editor,state:i,view:this.mountedView,from:n,to:r})),from:n,to:r,docSize:l,extensionName:e,warnedExtensions:this.warnedOutOfRangeExtensions}),e);c=c.add(i.doc,o);for(let e of u)s.add(e)}return{set:c,widgetKeys:s}}buildFullSet(e,t,n){let r=this.runCreate(e,`create`,()=>t.create({editor:this.editor,state:n,view:this.mountedView}));return uf(n.doc,r,e)}runCreate(e,t,n){try{return n()}catch(n){return console.error(`[tiptap error]: Extension "${e}" threw in \`addDecorations().${t}()\`. Its decorations were dropped for this update.`,n),[]}}warnDuplicateWidgetKeys(e){if(!sf)return;if(e.widgetKeys.size===0){this.warnedWidgetKeys.clear();return}let t=mf(e.mergedDecorationSet),n=new Set(t.map(({key:e})=>e));for(let{key:e,extensions:n}of t){if(this.warnedWidgetKeys.has(e))continue;let t=Array.from(n).map(e=>`"${e}"`).join(`, `);console.warn(`[tiptap warn]: Duplicate widget decoration key "${e}" in extension${n.size===1?``:`s`} ${t}. Widget decoration keys must be globally unique, otherwise ProseMirror misplaces the widget DOM. Use a stable, unique key (e.g. \`comment-\${id}\`).`)}this.warnedWidgetKeys=n}buildMergedSet(e,t){let n=Object.keys(t);return n.length===1?t[n[0]]:xf(e,t)}mergeAfterApply({entries:e,previous:t,tr:n,decorationSetsByExtension:r,recomputedNames:i}){return e.length===1?r[e[0].name]:i.size===0?t.mergedDecorationSet.map(n.mapping,n.doc):xf(n.doc,r)}};function Df(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof E){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}function Of(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}function kf(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)}function Af(e,t){let n=e.getAttribute(`style`);if(!n)return null;let r=n.split(`;`).map(e=>e.trim()).filter(Boolean),i=t.toLowerCase();for(let e=r.length-1;e>=0;--e){let t=r[e],n=t.indexOf(`:`);if(n!==-1&&t.slice(0,n).trim().toLowerCase()===i)return t.slice(n+1).trim()}return null}function jf(e){return typeof e==`number`}function Mf(e){return Object.prototype.toString.call(e).slice(8,-1)}function Nf(e){return Mf(e)===`Object`&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Pf(e){return typeof e==`string`&&e.trim().length>0&&!/[;{}]/.test(e)}function Ff(e){return/\s/.test(e)}function If(e){return/^[a-zA-Z]$/.test(e)}function Lf(e){return/^\w$/.test(e)}function Rf(e,t){for(;t=e.length));){let i=Gf(e,r,t);i.token&&n.push(i.token),r=i.nextIndex}return n}function qf(e){let t={},n=e.filter(e=>e.type===`class`).map(e=>e.name),r=e.find(e=>e.type===`id`);return n.length>0&&(t.class=n.join(` `)),r&&(t.id=r.name),e.forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),e.forEach(e=>{e.type===`boolean`&&(t[e.name]=!0)}),t}function Jf(e){return e?.trim()?qf(Kf(e,`pandoc`)):{}}function Yf(e){if(!e||Object.keys(e).length===0)return``;let t=[];return e.class&&String(e.class).split(/\s+/).filter(Boolean).forEach(e=>t.push(`.${e}`)),e.id&&t.push(`#${e.id}`),Object.entries(e).forEach(([e,n])=>{e!==`class`&&e!==`id`&&(n===!0?t.push(e):n!==!1&&n!=null&&t.push(`${e}="${String(n)}"`))}),t.join(` `)}function Xf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=Jf,serializeAttributes:a=Yf,defaultAttributes:o={},content:s=`block`,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let i;if(r){let t=r(e);i=typeof t==`string`?[{type:`text`,text:t}]:t}else i=s===`block`?n.parseChildren(e.tokens||[]):n.parseInline(e.tokens||[]);let a={...o,...e.attributes};return n.createNode(t,a,i)},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${l}`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(`^:::${l}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),o=e.match(a);if(!o)return;let[c,u=``]=o,d=i(u),f=1,p=c.length,m=``,h=/^:::([\w-]*)(\s.*)?/gm,g=e.slice(p);for(h.lastIndex=0;;){let n=h.exec(g);if(n===null)break;let i=n.index,a=n[1];if(!n[2]?.endsWith(`:::`)){if(a)f+=1;else if(--f,f===0){let a=g.slice(0,i);m=a.trim();let o=e.slice(0,p+i+n[0].length),c=[];if(m){if(s===`block`)for(c=r.blockTokens(a),c.forEach(e=>{e.text&&(!e.tokens||e.tokens.length===0)&&(e.tokens=r.inlineTokens(e.text))});c.length>0;){let e=c[c.length-1];if(e.type===`paragraph`&&(!e.text||e.text.trim()===``))c.pop();else break}else c=r.inlineTokens(m)}return{type:t,raw:o,attributes:d,content:m,tokens:c}}}}}},renderMarkdown:(e,t)=>{let n=u(e.attrs||{}),r=a(n),i=r?` {${r}}`:``,o=t.renderChildren(e.content||[],` +`,textSerializers:o={}}=n||{},s=``;return e.nodesBetween(r,i,(e,n,c,l)=>{e.isBlock&&n>r&&(s+=a);let u=o?.[e.type.name];if(u)return c&&(s+=u({node:e,pos:n,parent:c,index:l,range:t})),!1;if(e.isText){var d;s+=e==null||(d=e.text)==null?void 0:d.slice(Math.max(r,n)-n,i-n)}}),s}function Ku(e,t){return Gu(e,{from:0,to:e.content.size},t)}function qu(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function Ju(e,t){let n=rl(t,e.schema),{from:r,to:i}=e.selection,a=[];e.doc.nodesBetween(r,i,e=>{a.push(e)});let o=a.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}function Yu(e,t){let n=tu(typeof t==`string`?t:t.name,e.schema);return n===`node`?Ju(e,t):n===`mark`?pu(e,t):{}}function Xu(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return Object.prototype.hasOwnProperty.call(n,r)?!1:n[r]=!0})}function Zu(e){let t=Xu(e);return t.length===1?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function Qu(e){let{mapping:t,steps:n}=e,r=[],i=t.invert();return t.maps.forEach((e,a)=>{let o=[];if(e.ranges.length)e.forEach((e,t)=>{o.push({from:e,to:t})});else{let{from:e,to:t}=n[a];if(e===void 0||t===void 0)return;o.push({from:e,to:t})}let s=t.slice(a);o.forEach(({from:e,to:t})=>{let n=s.map(e,-1),a=s.map(t),o=i.map(n,-1),c=i.map(a);r.push({oldRange:{from:o,to:c},newRange:{from:n,to:a}})})}),Zu(r)}function $u(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=gl(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&e?.nodeSize!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}var ed=(e,t,n,r=20)=>{let i=e.doc.resolve(n),a=r,o=null;for(;a>0&&o===null;){let e=i.node(a);e?.type.name===t?o=e:--a}return[o,a]},td=e=>{let t=e.depth-1;if(t<0)return null;let n=e.index(t);return n===0?null:e.node(t).child(n-1)};function nd(e,t){return t.nodes[e]||t.marks[e]||null}function rd(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return r?r.attribute.keepOnSplit:!1}))}var id=(e,t=500)=>{let n=``,r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,a)=>{var o;let s=(o=e.type.spec).toText?.call(o,{node:e,pos:t,parent:i,index:a})||e.textContent||`%leaf%`;n+=e.isAtom&&!e.isText?s:s.slice(0,Math.max(0,r-t))}),n};function ad(e,t,n={}){let{empty:r,ranges:i}=e.selection,a=t?_l(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!a||a.name===e.type.name).find(e=>pl(e.attrs,n,{strict:!1}));let o=0,s=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(a&&e.inlineContent&&!e.type.allowsMarkType(a))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),c=Math.min(i,t+e.nodeSize),l=c-n;o+=l,s.push(...e.marks.map(e=>({mark:e,from:n,to:c})))})}),o===0)return!1;let c=s.filter(e=>!a||a.name===e.mark.type.name).filter(e=>pl(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),l=s.filter(e=>!a||e.mark.type!==a&&e.mark.type.excludes(a)).reduce((e,t)=>e+t.to-t.from,0);return(c>0?c+l:c)>=o}function od(e,t,n={}){if(!t)return Xl(e,null,n)||ad(e,null,n);let r=tu(t,e.schema);return r===`node`?Xl(e,t,n):r===`mark`&&ad(e,t,n)}var sd=(e,t)=>{let{$from:n,$to:r,$anchor:i}=e.selection;if(t){let n=vu(e=>e.type.name===t)(e.selection);if(!n)return!1;let r=e.doc.resolve(n.pos+1);return i.pos+1===r.end()}return!(r.parentOffset{let{$from:t,$to:n}=e.selection;return!(t.parentOffset>0||t.pos!==n.pos)};function ld(e,t){return Array.isArray(t)?t.some(t=>(typeof t==`string`?t:t.name)===e.name):t}function ud(e,t){let{nodeExtensions:n}=ku(t),r=n.find(t=>t.name===e);if(!r)return!1;let i=Mu(A(r,`group`,{name:r.name,options:r.options,storage:r.storage}));return typeof i==`string`&&i.split(` `).includes(`list`)}function dd(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){if(n){if(e.type.name===`hardBreak`)return!0;if(e.isText)return!/\S/.test(e.text??``)}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(e.content.childCount===0)return!0;if(t){let r=!0;return e.content.forEach(e=>{r!==!1&&(dd(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function fd(e){return e instanceof E}function pd(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.apply==`function`&&typeof t.getMap==`function`&&typeof t.invert==`function`&&typeof t.map==`function`&&typeof t.merge==`function`&&typeof t.toJSON==`function`}function md(e){if(typeof e!=`object`||!e)return!1;let t=e;if(!pd(t))return!1;let n=t.toJSON();return!(typeof n!=`object`||!n||n.stepType!==`replace`)}var hd=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function gd(e,t){let n=t.mapping.mapResult(e.position);return{position:new hd(n.pos),mapResult:n}}function _d(e){return new hd(e)}function vd(e,t,n){let{selection:r}=t,i=null;if(bl(r)&&(i=r.$cursor),i){let t=e.storedMarks??i.marks();return i.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:a}=r;return a.some(({$from:t,$to:r})=>{let i=t.depth===0&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),a=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&a}return!i}),i})}var yd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=n,{empty:o,ranges:s}=a,c=_l(e,r.schema);if(i){if(o){let e=pu(r,c);n.addStoredMark(c.create({...e,...t}))}else s.forEach(e=>{let i=e.$from.pos,a=e.$to.pos;r.doc.nodesBetween(i,a,(e,r)=>{let o=Math.max(r,i),s=Math.min(r+e.nodeSize,a);e.marks.find(e=>e.type===c)?e.marks.forEach(e=>{c===e.type&&n.addMark(o,s,c.create({...e.attrs,...t}))}):n.addMark(o,s,c.create(t))})})}return vd(r,n,c)},bd=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),xd=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let a=rl(e,n.schema),o;return n.selection.$anchor.sameParent(n.selection.$head)&&(o=n.selection.$anchor.parent.attrs),a.isTextblock?i().command(({commands:e})=>br(a,{...o,...t})(n)?!0:e.clearNodes()).command(({state:e})=>br(a,{...o,...t})(e,r)).run():(console.warn(`[tiptap warn]: Currently "setNode()" only supports text block nodes.`),!1)},Sd=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=xl(e,0,n.content.size),i=E.create(n,r);t.setSelection(i)}return!0},Cd=(e,t)=>({tr:n,state:r,dispatch:i})=>{let{selection:a}=r,o,s;return typeof t==`number`?(o=t,s=t):t&&`from`in t&&`to`in t?(o=t.from,s=t.to):(o=a.from,s=a.to),i&&n.doc.nodesBetween(o,s,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},wd=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}=typeof e==`number`?{from:e,to:e}:e,a=T.atStart(n).from,o=T.atEnd(n).to,s=xl(r,a,o),c=xl(i,a,o),l=T.create(n,s,c);t.setSelection(l)}return!0},Td=e=>({state:t,dispatch:n})=>Nr(rl(e,t.schema))(t,n);function Ed(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>t?.includes(e.type.name));e.tr.ensureMarks(r)}}var Dd=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:a,doc:o}=t,{$from:s,$to:c}=a,l=i.extensionManager.attributes,u=rd(l,s.node().type.name,s.node().attrs);if(a instanceof E&&a.node.isBlock)return!s.parentOffset||!Gt(o,s.pos)?!1:(r&&(e&&Ed(n,i.extensionManager.splittableMarks),t.split(s.pos).scrollIntoView()),!0);if(!s.parent.isBlock)return!1;let d=c.parentOffset===c.parent.content.size,f=s.depth===0?void 0:Il(s.node(-1).contentMatchAt(s.indexAfter(-1))),p=d&&f?[{type:f,attrs:u}]:void 0,m=a instanceof T&&!a.empty?zn.create({doc:t.doc,selection:a}).tr.deleteSelection():null,h=m?m.doc:t.doc,g=m?m.mapping.map(s.pos):s.pos,_=Gt(h,g,1,p);if(!p&&!_&&Gt(h,g,1,f?[{type:f}]:void 0)&&(_=!0,p=f?[{type:f,attrs:u}]:void 0),r){if(_){let e=t.steps.length;if(a instanceof T&&t.deleteSelection(),t.split(t.mapping.slice(e).map(s.pos),1,p),f&&!d&&!s.parentOffset&&s.parent.type!==f){let n=t.mapping.slice(e).map(s.before()),r=t.doc.resolve(n);s.node(-1).canReplaceWith(r.index(),r.index()+1,f)&&t.setNodeMarkup(t.mapping.slice(e).map(s.before()),f)}}e&&Ed(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return _},Od=(e,t={})=>({tr:n,state:r,dispatch:i,editor:a})=>{let o=rl(e,r.schema),{$from:c,$to:l}=r.selection,u=r.selection.node;if(u&&u.isBlock||c.depth<2||!c.sameParent(l))return!1;let d=c.node(-1);if(d.type!==o)return!1;let f=a.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==o||c.index(-2)!==c.node(-2).childCount-1)return!1;if(i){let e=s.empty,r=c.index(-1)?1:c.index(-2)?2:3;for(let t=c.depth-r;t>=c.depth-3;--t)e=s.from(c.node(t).copy(e));let i=c.indexAfter(-1){if(d>-1)return!1;e.isTextblock&&e.content.size===0&&(d=t+1)}),d>-1&&n.setSelection(T.near(n.doc.resolve(d))),n.scrollIntoView()}return!0}let m=l.pos===c.end()?d.contentMatchAt(0).defaultType:null,h={...rd(f,d.type.name,d.attrs),...t},g={...rd(f,c.node().type.name,c.node().attrs),...t},_=c.parentOffset===0&&c.index(-1)===0,v=c.before(-1);n.delete(c.pos,l.pos);let y=_?d.attrs:h,b=m?[{type:o,attrs:y},{type:m,attrs:g}]:[{type:o,attrs:y}];if(!Gt(n.doc,c.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=a.extensionManager,s=t||e.$to.parentOffset&&e.$from.marks();if(n.split(c.pos,2,b).scrollIntoView(),_&&n.setNodeMarkup(v,void 0,h),!s||!i)return!0;let l=s.filter(e=>o.includes(e.type.name));n.ensureMarks(l)}return!0};function kd(e,t,n){if(!e.validContent(t))return null;try{return e.create(n,t)}catch{return null}}function Ad(e,t){if(e.pendingContent.length===0)return!0;let n=kd(t,s.from(e.pendingContent));return n?(e.items.push(n),e.pendingContent=[],!0):!1}function jd(e,t,n){return n.validContent(s.from([...t.pendingContent,e]))?(t.pendingContent.push(e),!0):!Ad(t,n)||!n.validContent(s.from(e))?!1:(t.pendingContent.push(e),!0)}function Md(e,t,n,r){let i=r(e,n);if(!i)return!1;let a=kd(n.listType,s.from(i),e.attrs);return a?n.itemType.validContent(s.from([...t.pendingContent,a]))?(t.pendingContent.push(a),!0):Ad(t,n.itemType)?(t.items.push(...i),!0):!1:!1}function Nd(e,t,n){let r={items:[],pendingContent:[]};for(let i=0;ie!==t||(n=r,!1)),n}function Id(e){return!e||e===`1`?null:e}function Ld(e,t){return Id(e)===Id(t)}var Rd=(e,t)=>{let n=vu(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&qt(e.doc,n.pos))||!Ld(n.node.attrs.type,i?.attrs.type)||e.join(n.pos),!0},zd=(e,t)=>{let n=vu(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(r===void 0)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===i?.type&&qt(e.doc,r))||!Ld(n.node.attrs.type,i?.attrs.type)||e.join(r),!0};function Bd(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return T.between(r,i)}var Vd=(e,t,n,r={})=>({editor:i,tr:a,state:o,dispatch:c,chain:l,commands:u,can:d})=>{let{extensions:f,splittableMarks:p}=i.extensionManager,m=rl(e,o.schema),h=rl(t,o.schema),{selection:g,storedMarks:_}=o,{$from:v,$to:y}=g,b=v.blockRange(y),x=_||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;let S=vu(e=>ud(e.type.name,f))(g),C=g.from===0&&g.to===o.doc.content.size,ee=o.doc.content.content,te=ee.length===1?ee[0]:null,ne=C&&te&&ud(te.type.name,f)?{node:te,pos:0,depth:0}:null,re=S??ne,ie=!!S&&b.depth>=1&&b.depth-S.depth<=1,ae=!!ne;if((ie||ae)&&re){if(re.node.type===m)return C&&ae?l().command(({tr:e,dispatch:t})=>{let n=Bd(e);return n?(e.setSelection(n),t&&t(e),!0):!1}).liftListItem(h).run():u.liftListItem(h);if(ud(re.node.type.name,f)&&m.validContent(re.node.content))return l().command(()=>(a.setNodeMarkup(re.pos,m),!0)).command(()=>Rd(a,m)).command(()=>zd(a,m)).run();if(ud(re.node.type.name,f)){let e=re.node.firstChild?.type;if(e&&e!==h){let e=Pd(re.node,{listType:m,itemType:h,isListNode:e=>ud(e.type.name,f)}),t=e?s.from(e):null;return!t||!m.validContent(t)?!1:l().command(()=>{let{$anchor:e,$head:n}=a.selection,i=e.parent,o=n.parent,s=e.parentOffset,c=n.parentOffset,l;try{l=m.create(r,t)}catch{return!1}if(a.replaceWith(re.pos,re.pos+re.node.nodeSize,l),i.inlineContent&&o.inlineContent){let e=Fd(l,i),t=Fd(l,o);if(e!==null&&t!==null){let n=re.pos+e+2+s,r=re.pos+t+2+c;a.setSelection(T.create(a.doc,n,r))}}return!0}).command(()=>Rd(a,m)).command(()=>zd(a,m)).run()}}}return!n||!x||!c?l().command(()=>d().wrapInList(m,r)?!0:u.clearNodes()).wrapInList(m,r).command(()=>Rd(a,m)).command(()=>zd(a,m)).run():l().command(()=>{let e=d().wrapInList(m,r),t=x.filter(e=>p.includes(e.type.name));return a.ensureMarks(t),e?!0:u.clearNodes()}).wrapInList(m,r).command(()=>Rd(a,m)).command(()=>zd(a,m)).run()},Hd=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:a=!1}=n,o=_l(e,r.schema);return ad(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:a}):i.setMark(o,t)},Ud=(e,t,n={})=>({state:r,commands:i})=>{let a=rl(e,r.schema),o=rl(t,r.schema),s=Xl(r,a,n),c;return r.selection.$anchor.sameParent(r.selection.$head)&&(c=r.selection.$anchor.parent.attrs),s?i.setNode(o,c):i.setNode(a,{...c,...n})},Wd=(e,t={})=>({state:n,commands:r})=>{let i=rl(e,n.schema);return Xl(n,i,t)?r.lift(i):r.wrapIn(i,t)},Gd=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r=0;--e)t.step(n.steps[e].invert(n.docs[e]));if(a.text){let n=t.doc.resolve(a.from).marks();t.replaceWith(a.from,a.to,e.schema.text(a.text,n))}else t.delete(a.from,a.to)}return!0}}return!1},Kd=(e={})=>({tr:t,dispatch:n,editor:r})=>{let{ignoreClearable:i=!1}=e,{selection:a}=t,{empty:o,ranges:s}=a;if(o)return!0;let{nonClearableMarks:c}=r.extensionManager;if(n){let e=Object.values(r.schema.marks).filter(e=>i||!c.includes(e.name));s.forEach(n=>{for(let r of e)t.removeMark(n.$from.pos,n.$to.pos,r)})}return!0},qd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{extendEmptyMarkRange:a=!1}=t,{selection:o}=n,s=_l(e,r.schema),{$from:c,empty:l,ranges:u}=o;if(!i)return!0;if(l&&a){let{from:e,to:t}=o,r=gl(c,s,c.marks().find(e=>e.type===s)?.attrs);r&&(e=r.from,t=r.to),n.removeMark(e,t,s)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,s)});return n.removeStoredMark(s),!0},Jd=e=>({tr:t,state:n,dispatch:r})=>{let{selection:i}=n,a,o;return typeof e==`number`?(a=e,o=e):e&&`from`in e&&`to`in e?(a=e.from,o=e.to):(a=i.from,o=i.to),r&&t.doc.nodesBetween(a,o,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},Yd=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let a=null,o=null,s=tu(typeof e==`string`?e:e.name,r.schema);if(!s)return!1;s===`node`&&(a=rl(e,r.schema)),s===`mark`&&(o=_l(e,r.schema));let c=!1;return n.selection.ranges.forEach(e=>{let s=e.$from.pos,l=e.$to.pos,u,d,f,p;n.selection.empty?r.doc.nodesBetween(s,l,(e,t)=>{a&&a===e.type&&(c=!0,f=Math.max(t,s),p=Math.min(t+e.nodeSize,l),u=t,d=e)}):r.doc.nodesBetween(s,l,(e,r)=>{r=s&&r<=l&&(a&&a===e.type&&(c=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(a=>{if(o===a.type&&(c=!0,i)){let i=Math.max(r,s),c=Math.min(r+e.nodeSize,l);n.addMark(i,c,o.create({...a.attrs,...t}))}}))}),d&&(u!==void 0&&i&&n.setNodeMarkup(u,void 0,{...d.attrs,...t}),o&&d.marks.length&&d.marks.forEach(e=>{o===e.type&&i&&n.addMark(f,p,o.create({...e.attrs,...t}))}))}),c},Xd=new O(`__tiptap_decorations__`),Zd=e=>({tr:t,dispatch:n})=>(n&&t.setMeta(Xd,{type:`force`,name:e}),!0),Qd=(e,t={})=>({state:n,dispatch:r})=>yr(rl(e,n.schema),t)(n,r),$d=(e,t={})=>({state:n,dispatch:r})=>Er(rl(e,n.schema),t)(n,r),ef=t({blur:()=>Xc,clearContent:()=>Zc,clearNodes:()=>Qc,command:()=>$c,createParagraphNear:()=>el,cut:()=>tl,deleteCurrentNode:()=>nl,deleteNode:()=>il,deleteRange:()=>al,deleteSelection:()=>ll,enter:()=>ul,exitCode:()=>dl,extendMarkRange:()=>vl,first:()=>yl,focus:()=>El,forEach:()=>Dl,insertContent:()=>Ol,insertContentAt:()=>Fl,insertDefaultBlock:()=>Ll,joinBackward:()=>Bl,joinDown:()=>zl,joinForward:()=>Vl,joinItemBackward:()=>Ul,joinItemForward:()=>Wl,joinTextblockBackward:()=>Gl,joinTextblockForward:()=>Kl,joinUp:()=>Rl,keyboardShortcut:()=>Yl,lift:()=>Zl,liftEmptyBlock:()=>Ql,liftListItem:()=>$l,newlineInCode:()=>eu,resetAttributes:()=>ru,scrollIntoView:()=>iu,selectAll:()=>au,selectNodeBackward:()=>ou,selectNodeForward:()=>su,selectParentNode:()=>cu,selectTextblockEnd:()=>lu,selectTextblockStart:()=>uu,setContent:()=>fu,setMark:()=>yd,setMeta:()=>bd,setNode:()=>xd,setNodeSelection:()=>Sd,setTextDirection:()=>Cd,setTextSelection:()=>wd,sinkListItem:()=>Td,splitBlock:()=>Dd,splitListItem:()=>Od,toggleList:()=>Vd,toggleMark:()=>Hd,toggleNode:()=>Ud,toggleWrap:()=>Wd,undoInputRule:()=>Gd,unsetAllMarks:()=>Kd,unsetMark:()=>qd,unsetTextDirection:()=>Jd,updateAttributes:()=>Yd,updateDecorations:()=>Zd,wrapIn:()=>Qd,wrapInList:()=>$d}),tf=new WeakMap;function nf(e,t){tf.set(e,(tf.get(e)??0)+1);try{return t()}finally{let t=(tf.get(e)??1)-1;t>0?tf.set(e,t):tf.delete(e)}}function rf(e){return tf.has(e)}var af=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},of=typeof process<`u`&&!1;function sf(e){return e.kind===`widget`}function cf(e,t){let n=[],r=new Set;for(let i of e)i.kind===`widget`&&sf(i)&&r.add(i.key),n.push(i.toPMDecoration(t));return{decorations:n,widgetKeys:r}}function lf(e,t,n){let{decorations:r,widgetKeys:i}=cf(t,n);return{set:bs.create(e,r),widgetKeys:i}}function uf({position:e,from:t,to:n,docSize:r}){return euf({position:e.anchor,from:t,to:n,docSize:r})?!0:(e.anchor===n||a.has(i)||(a.add(i),console.warn(`[tiptap warn]: Extension "${i}" returned a decoration outside the requested range [${t}, ${n}). It was ignored.`)),!1))}function ff(e){let t=e.spec?.key;return typeof t==`string`?t:void 0}function pf(e){let t=new Map,n=new Map;for(let r of e.find()){let e=ff(r);if(!e)continue;let i=r.spec.extensionName??`unknown`,a=t.get(e)??new Set;a.add(i),t.set(e,a),n.set(e,(n.get(e)??0)+1)}return Array.from(t,([e,t])=>({key:e,extensions:t})).filter(({key:e})=>(n.get(e)??0)>1)}function mf(e){return e.jsonID===`attr`}function hf(e){let t=!1;if(e.getMap().forEach(()=>{t=!0}),t||mf(e))return!0;let n=e;return typeof n.from==`number`&&typeof n.to==`number`}function gf(e,t){let n=null,r=0,i=0;for(let a=0;at.to);a+=1){let o=i+e.child(a).nodeSize;o>=t.from&&(n===null&&(n=i),r=o),i=o}return n===null?null:{from:n,to:r}}function _f(e,t){if(e.steps.some(e=>!hf(e)))return{type:`full`};let n=Qu(e).map(({newRange:e})=>e);e.steps.forEach((t,r)=>{if(!mf(t))return;let i=e.mapping.slice(r);n.push({from:i.map(t.pos,-1),to:i.map(t.pos+1)})});let r=[];for(let e of n){let n=gf(t,e);n&&r.push(n)}r.sort((e,t)=>e.from-t.from);let i=[];for(let e of r){let t=i[i.length-1];t&&e.from<=t.to?t.to=Math.max(t.to,e.to):i.push({...e})}return{type:`ranges`,ranges:i}}function vf(e,t,n,r){return e.map(t,n,{onRemove:e=>{let t=e?.key;typeof t==`string`&&r.delete(t)}})}function yf(e,t,n){let r=t.decorationSetsByExtension[e]??bs.empty,i=new Set(t.widgetKeysByExtension[e]??[]);return{set:vf(r,n.mapping,n.doc,i),widgetKeys:i}}function bf(e,t){let n=Object.values(t).flatMap(e=>e.find());return bs.create(e,n)}function xf(e){let t=new Set;for(let n of Object.values(e))for(let e of n)t.add(e);return t}function Sf(e,t){switch(t.update??`document`){case`document`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" provides createInRange() but does not use the "changedRanges" decoration update strategy.`);return;case`changedRanges`:if(!t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "changedRanges" decoration update strategy but does not provide createInRange().`);return;case`manual`:if(t.createInRange)throw Error(`[tiptap error]: Extension "${e}" uses the "manual" decoration update strategy, which is not compatible with createInRange(). createInRange() requires the "changedRanges" strategy.`);if(t.shouldUpdate)throw Error(`[tiptap error]: Extension "${e}" cannot combine the "manual" decoration update strategy with shouldUpdate().`);return;default:throw Error(`[tiptap error]: Extension "${e}" uses an unknown decoration update strategy. Expected "document", "changedRanges", or "manual".`)}}function Cf(e,t,n){return n?!0:e.update===`manual`?!1:e.shouldUpdate?e.shouldUpdate(t):t.tr.docChanged}var wf=new Set,Tf=class{constructor(e){this.warnedWidgetKeys=new Set,this.warnedOutOfRangeExtensions=new Set,this.handleBeforeTransaction=({nextState:e})=>{let t=Xd.getState(e);t&&this.warnDuplicateWidgetKeys(t)},this.editor=e.editor,this.entries=this.resolveEntries(e.entries),this.entries.forEach(({name:e,spec:t})=>Sf(e,t)),this.plugin=this.entries.length>0?this.createPlugin():null,this.editor.on(`beforeTransaction`,this.handleBeforeTransaction)}destroy(){this.editor.off(`beforeTransaction`,this.handleBeforeTransaction)}liveWidgetKeys(){return Xd.getState(this.editor.state)?.widgetKeys??wf}get mountedView(){return this.editor.isDestroyed?null:this.editor.view}resolveEntries(e){let t=[];for(let{name:n,addDecorations:r}of e){let e=r();e&&t.push({name:n,spec:e})}return t}createPlugin(){let{editor:e,entries:t}=this;return new D({key:Xd,state:{init:(e,n)=>{let r={},i={};for(let{name:e,spec:a}of t){let{set:t,widgetKeys:o}=this.buildFullSet(e,a,n);r[e]=t,i[e]=o}let a={decorationSetsByExtension:r,widgetKeysByExtension:i,mergedDecorationSet:this.buildMergedSet(n.doc,r),widgetKeys:xf(i)};return this.warnDuplicateWidgetKeys(a),a},apply:(n,r,i,a)=>{let o=n.getMeta(Xd),s=o?.type===`force`&&!o.name,c=o?.type===`force`?o.name:void 0,l={},u={},d=new Set;return nf(e,()=>{for(let{name:o,spec:f}of t){let t=s||c===o;if(!Cf(f,{editor:e,tr:n,oldState:i,newState:a},t)){let e=yf(o,r,n);l[o]=e.set,u[o]=e.widgetKeys}else if(f.update===`changedRanges`&&n.docChanged&&!t){let e=this.applyChangedRangesRecompute(o,f,r,n,a);l[o]=e.set,u[o]=e.widgetKeys,d.add(o)}else{let{set:e,widgetKeys:t}=this.buildFullSet(o,f,a);l[o]=e,u[o]=t,d.add(o)}}}),d.size===0&&!n.docChanged?r:{decorationSetsByExtension:l,widgetKeysByExtension:u,mergedDecorationSet:this.mergeAfterApply({entries:t,previous:r,tr:n,decorationSetsByExtension:l,recomputedNames:d}),widgetKeys:xf(u)}}},props:{decorations(e){return Xd.getState(e)?.mergedDecorationSet??bs.empty}}})}applyChangedRangesRecompute(e,t,n,r,i){let a=_f(r,i.doc);return a.type===`full`?this.buildFullSet(e,t,i):this.rebuildRanges(e,t,n,r,i,a.ranges)}rebuildRanges(e,t,n,r,i,a){let o=n.decorationSetsByExtension[e]??bs.empty,s=new Set(n.widgetKeysByExtension[e]??[]),c=vf(o,r.mapping,r.doc,s),l=i.doc.content.size;for(let{from:n,to:r}of a){let a=c.find(n,r).filter(e=>uf({position:e.from,from:n,to:r,docSize:l}));for(let e of a){let t=ff(e);t&&s.delete(t)}c=c.remove(a);let{decorations:o,widgetKeys:u}=cf(df({decorations:this.runCreate(e,`createInRange`,()=>t.createInRange({editor:this.editor,state:i,view:this.mountedView,from:n,to:r})),from:n,to:r,docSize:l,extensionName:e,warnedExtensions:this.warnedOutOfRangeExtensions}),e);c=c.add(i.doc,o);for(let e of u)s.add(e)}return{set:c,widgetKeys:s}}buildFullSet(e,t,n){let r=this.runCreate(e,`create`,()=>t.create({editor:this.editor,state:n,view:this.mountedView}));return lf(n.doc,r,e)}runCreate(e,t,n){try{return n()}catch(n){return console.error(`[tiptap error]: Extension "${e}" threw in \`addDecorations().${t}()\`. Its decorations were dropped for this update.`,n),[]}}warnDuplicateWidgetKeys(e){if(!of)return;if(e.widgetKeys.size===0){this.warnedWidgetKeys.clear();return}let t=pf(e.mergedDecorationSet),n=new Set(t.map(({key:e})=>e));for(let{key:e,extensions:n}of t){if(this.warnedWidgetKeys.has(e))continue;let t=Array.from(n).map(e=>`"${e}"`).join(`, `);console.warn(`[tiptap warn]: Duplicate widget decoration key "${e}" in extension${n.size===1?``:`s`} ${t}. Widget decoration keys must be globally unique, otherwise ProseMirror misplaces the widget DOM. Use a stable, unique key (e.g. \`comment-\${id}\`).`)}this.warnedWidgetKeys=n}buildMergedSet(e,t){let n=Object.keys(t);return n.length===1?t[n[0]]:bf(e,t)}mergeAfterApply({entries:e,previous:t,tr:n,decorationSetsByExtension:r,recomputedNames:i}){return e.length===1?r[e[0].name]:i.size===0?t.mergedDecorationSet.map(n.mapping,n.doc):bf(n.doc,r)}};function Ef(e,t){let{selection:n}=e,{$from:r}=n;if(n instanceof E){let e=r.index();return r.parent.canReplaceWith(e,e+1,t)}let i=r.depth;for(;i>=0;){let e=r.index(i);if(r.node(i).contentMatchAt(e).matchType(t))return!0;--i}return!1}function Df(e,t,n){let r=document.querySelector(`style[data-tiptap-style${n?`-${n}`:``}]`);if(r!==null)return r;let i=document.createElement(`style`);return t&&i.setAttribute(`nonce`,t),i.setAttribute(`data-tiptap-style${n?`-${n}`:``}`,``),i.innerHTML=e,document.getElementsByTagName(`head`)[0].appendChild(i),i}function Of(e){return e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)}function kf(e,t){let n=e.getAttribute(`style`);if(!n)return null;let r=n.split(`;`).map(e=>e.trim()).filter(Boolean),i=t.toLowerCase();for(let e=r.length-1;e>=0;--e){let t=r[e],n=t.indexOf(`:`);if(n!==-1&&t.slice(0,n).trim().toLowerCase()===i)return t.slice(n+1).trim()}return null}function Af(e){return typeof e==`number`}function jf(e){return Object.prototype.toString.call(e).slice(8,-1)}function Mf(e){return jf(e)===`Object`&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}function Nf(e){return typeof e==`string`&&e.trim().length>0&&!/[;{}]/.test(e)}function Pf(e){return/\s/.test(e)}function Ff(e){return/^[a-zA-Z]$/.test(e)}function If(e){return/^\w$/.test(e)}function Lf(e,t){for(;t=e.length));){let i=Wf(e,r,t);i.token&&n.push(i.token),r=i.nextIndex}return n}function Kf(e){let t={},n=e.filter(e=>e.type===`class`).map(e=>e.name),r=e.find(e=>e.type===`id`);return n.length>0&&(t.class=n.join(` `)),r&&(t.id=r.name),e.forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),e.forEach(e=>{e.type===`boolean`&&(t[e.name]=!0)}),t}function qf(e){return e?.trim()?Kf(Gf(e,`pandoc`)):{}}function Jf(e){if(!e||Object.keys(e).length===0)return``;let t=[];return e.class&&String(e.class).split(/\s+/).filter(Boolean).forEach(e=>t.push(`.${e}`)),e.id&&t.push(`#${e.id}`),Object.entries(e).forEach(([e,n])=>{e!==`class`&&e!==`id`&&(n===!0?t.push(e):n!==!1&&n!=null&&t.push(`${e}="${String(n)}"`))}),t.join(` `)}function Yf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=qf,serializeAttributes:a=Jf,defaultAttributes:o={},content:s=`block`,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{n in e&&(t[n]=e[n])}),t};return{parseMarkdown:(e,n)=>{let i;if(r){let t=r(e);i=typeof t==`string`?[{type:`text`,text:t}]:t}else i=s===`block`?n.parseChildren(e.tokens||[]):n.parseInline(e.tokens||[]);let a={...o,...e.attributes};return n.createNode(t,a,i)},markdownTokenizer:{name:t,level:`block`,start(e){let t=RegExp(`^:::${l}`,`m`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(`^:::${l}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),o=e.match(a);if(!o)return;let[c,u=``]=o,d=i(u),f=1,p=c.length,m=``,h=/^:::([\w-]*)(\s.*)?/gm,g=e.slice(p);for(h.lastIndex=0;;){let n=h.exec(g);if(n===null)break;let i=n.index,a=n[1];if(!n[2]?.endsWith(`:::`)){if(a)f+=1;else if(--f,f===0){let a=g.slice(0,i);m=a.trim();let o=e.slice(0,p+i+n[0].length),c=[];if(m){if(s===`block`)for(c=r.blockTokens(a),c.forEach(e=>{e.text&&(!e.tokens||e.tokens.length===0)&&(e.tokens=r.inlineTokens(e.text))});c.length>0;){let e=c[c.length-1];if(e.type===`paragraph`&&(!e.text||e.text.trim()===``))c.pop();else break}else c=r.inlineTokens(m)}return{type:t,raw:o,attributes:d,content:m,tokens:c}}}}}},renderMarkdown:(e,t)=>{let n=u(e.attrs||{}),r=a(n),i=r?` {${r}}`:``,o=t.renderChildren(e.content||[],` -`);return`:::${l}${i}\n\n${o}\n\n:::`}}}function Zf(e){let t={};return Kf(e,`shortcode`).forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),t}function Qf(e){return Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(` `)}function $f(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=Zf,serializeAttributes:a=Qf,defaultAttributes:o={},selfClosing:s=!1,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{let r=typeof n==`string`?n:n.name,i=typeof n==`string`?void 0:n.skipIfDefault;if(r in e){let n=e[r];if(i!==void 0&&n===i)return;t[r]=n}}),t},d=l.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{parseMarkdown:(e,n)=>{let i={...o,...e.attributes};if(s)return n.createNode(t,i);let a=r?r(e):e.content||``;return a?n.createNode(t,i,[n.createTextNode(a)]):n.createNode(t,i,[])},markdownTokenizer:{name:t,level:`inline`,start(e){let t=RegExp(s?`\\[${d}\\s*[^\\]]*\\]`:`\\[${d}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${d}\\]`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(s?`^\\[${d}\\s*([^\\]]*)\\]`:`^\\[${d}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${d}\\]`),o=e.match(a);if(!o)return;let c=``,l=``;if(s){let[,e]=o;l=e}else{let[,e,t]=o;l=e,c=t||``}let u=i(l.trim());return{type:t,raw:o[0],content:c.trim(),attributes:u}}},renderMarkdown:e=>{let t=``;r?t=r(e):e.content&&e.content.length>0&&(t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(``));let n=u(e.attrs||{}),i=a(n),o=i?` ${i}`:``;return s?`[${l}${o}]`:`[${l}${o}]${t}[/${l}]`}}}function ep(e,t){return e.replace(/^[ \t]*/,e=>{let n=0;for(let t of e)n+=t===` `?4-n%4:1;return` `.repeat(Math.max(0,n-t))})}function tp(e,t){let n=`text\n${e}\n`,r=t(n)[0];return(r?.type===`paragraph`||r?.type===`text`)&&r.raw===n}function np(e,t,n){let r=t.split(` -`),i=n.isParagraphContinuation??(e=>tp(e,n.blockTokens)),a=0;for(let e of r){if(!e.trim()||!i(e))break;a+=1}return{mainContent:[e,...r.slice(0,a).map(e=>e.trimStart())].join(` +`);return`:::${l}${i}\n\n${o}\n\n:::`}}}function Xf(e){let t={};return Gf(e,`shortcode`).forEach(e=>{e.type===`keyValue`&&(t[e.name]=e.value)}),t}function Zf(e){return Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(` `)}function Qf(e){let{nodeName:t,name:n,getContent:r,parseAttributes:i=Xf,serializeAttributes:a=Zf,defaultAttributes:o={},selfClosing:s=!1,allowedAttributes:c}=e,l=n||t,u=e=>{if(!c)return e;let t={};return c.forEach(n=>{let r=typeof n==`string`?n:n.name,i=typeof n==`string`?void 0:n.skipIfDefault;if(r in e){let n=e[r];if(i!==void 0&&n===i)return;t[r]=n}}),t},d=l.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return{parseMarkdown:(e,n)=>{let i={...o,...e.attributes};if(s)return n.createNode(t,i);let a=r?r(e):e.content||``;return a?n.createNode(t,i,[n.createTextNode(a)]):n.createNode(t,i,[])},markdownTokenizer:{name:t,level:`inline`,start(e){let t=RegExp(s?`\\[${d}\\s*[^\\]]*\\]`:`\\[${d}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${d}\\]`),n=e.match(t)?.index;return n===void 0?-1:n},tokenize(e,n,r){let a=RegExp(s?`^\\[${d}\\s*([^\\]]*)\\]`:`^\\[${d}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${d}\\]`),o=e.match(a);if(!o)return;let c=``,l=``;if(s){let[,e]=o;l=e}else{let[,e,t]=o;l=e,c=t||``}let u=i(l.trim());return{type:t,raw:o[0],content:c.trim(),attributes:u}}},renderMarkdown:e=>{let t=``;r?t=r(e):e.content&&e.content.length>0&&(t=e.content.filter(e=>e.type===`text`).map(e=>e.text).join(``));let n=u(e.attrs||{}),i=a(n),o=i?` ${i}`:``;return s?`[${l}${o}]`:`[${l}${o}]${t}[/${l}]`}}}function $f(e,t){return e.replace(/^[ \t]*/,e=>{let n=0;for(let t of e)n+=t===` `?4-n%4:1;return` `.repeat(Math.max(0,n-t))})}function ep(e,t){let n=`text\n${e}\n`,r=t(n)[0];return(r?.type===`paragraph`||r?.type===`text`)&&r.raw===n}function tp(e,t,n){let r=t.split(` +`),i=n.isParagraphContinuation??(e=>ep(e,n.blockTokens)),a=0;for(let e of r){if(!e.trim()||!i(e))break;a+=1}return{mainContent:[e,...r.slice(0,a).map(e=>e.trimStart())].join(` `),nestedContent:r.slice(a).join(` -`)}}function rp(e,t,n){let r=e.split(` -`),i=[],a=``,o=0,s=t.baseIndentSize||2;for(;o0)break;if(e.trim()===``){o+=1,a=`${a}${e}\n`;continue}return}let d=t.extractItemData(u),{indentLevel:f,mainContent:p}=d;a=`${a}${e}\n`;let m=[p];for(o+=1;oe.trim()!==``);if(t===-1)break;if((((l=r[o+1+t].match(/^(\s*)/))==null||(l=l[1])==null?void 0:l.length)||0)>f){m.push(e),a=`${a}${e}\n`,o+=1;continue}break}if((((c=e.match(/^(\s*)/))==null||(c=c[1])==null?void 0:c.length)||0)>f)m.push(e),a=`${a}${e}\n`,o+=1;else break}let h,g=m.slice(1);if(g.length>0){let e=np(p,g.map(e=>ep(e,f+s)).join(` -`),n);d.mainContent=e.mainContent;let r=e.nestedContent;r.trim()&&(h=t.customNestedParser?t.customNestedParser(r):n.blockTokens(r))}let _=t.createToken(d,h);i.push(_)}if(i.length!==0)return{items:i,raw:a.slice(0,e.length)}}var ip=4;function ap(e){let t=0;for(let n of e)t=n===` `?t+ip-t%ip:t+1;return t}function op(e,t,n,r,i){if(!e||!Array.isArray(e.content))return``;let a=typeof n==`function`?n(r):n,[o,...s]=e.content,c=t.renderChildren([o]),l=`${a}${i?.indentMainContent?c.split(` +`)}}function np(e,t,n){let r=e.split(` +`),i=[],a=``,o=0,s=t.baseIndentSize||2;for(;o0)break;if(e.trim()===``){o+=1,a=`${a}${e}\n`;continue}return}let d=t.extractItemData(u),{indentLevel:f,mainContent:p}=d;a=`${a}${e}\n`;let m=[p];for(o+=1;oe.trim()!==``);if(t===-1)break;if((((l=r[o+1+t].match(/^(\s*)/))==null||(l=l[1])==null?void 0:l.length)||0)>f){m.push(e),a=`${a}${e}\n`,o+=1;continue}break}if((((c=e.match(/^(\s*)/))==null||(c=c[1])==null?void 0:c.length)||0)>f)m.push(e),a=`${a}${e}\n`,o+=1;else break}let h,g=m.slice(1);if(g.length>0){let e=tp(p,g.map(e=>$f(e,f+s)).join(` +`),n);d.mainContent=e.mainContent;let r=e.nestedContent;r.trim()&&(h=t.customNestedParser?t.customNestedParser(r):n.blockTokens(r))}let _=t.createToken(d,h);i.push(_)}if(i.length!==0)return{items:i,raw:a.slice(0,e.length)}}var rp=4;function ip(e){let t=0;for(let n of e)t=n===` `?t+rp-t%rp:t+1;return t}function ap(e,t,n,r,i){if(!e||!Array.isArray(e.content))return``;let a=typeof n==`function`?n(r):n,[o,...s]=e.content,c=t.renderChildren([o]),l=`${a}${i?.indentMainContent?c.split(` `).map((e,n)=>n===0?e:t.indent(e)).join(` -`):c}`;return s&&s.length>0&&s.forEach((e,n)=>{let r=t.renderChild?.call(t,e,n+1)??t.renderChildren([e]);if(r!=null){let n=e=>{if(!i?.alignNestedToPrefix)return t.indent(e);let n=t.indent(``),r=ap(a);return(ap(n)>=r?n:` `.repeat(r))+e},o=r.split(` +`):c}`;return s&&s.length>0&&s.forEach((e,n)=>{let r=t.renderChild?.call(t,e,n+1)??t.renderChildren([e]);if(r!=null){let n=e=>{if(!i?.alignNestedToPrefix)return t.indent(e);let n=t.indent(``),r=ip(a);return(ip(n)>=r?n:` `.repeat(r))+e},o=r.split(` `).map(e=>n(e||``)).join(` -`);l+=e.type===`paragraph`?`\n\n${o}`:`\n${o}`}}),l}function sp(e,t){let n={...e};return Nf(e)&&Nf(t)&&Object.keys(t).forEach(r=>{Nf(t[r])&&Nf(e[r])?n[r]=sp(e[r],t[r]):n[r]=t[r]}),n}function cp(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var lp=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},up=(e,t)=>{if(pl(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function dp(e){let{editor:t,from:n,to:r,text:i,insertText:a}=e;if(!a)return{inputTransaction:null,tr:t.view.state.tr};let o=t.view.state.tr.insertText(i,n,r);return{inputTransaction:o,tr:zn.create({doc:o.doc,selection:o.selection,storedMarks:o.storedMarks}).tr}}function fp(e){let{editor:t,from:n,to:r,text:i,rule:a,match:o,plugin:s,insertText:c}=e,{view:l}=t,{inputTransaction:u,tr:d}=dp({editor:t,from:n,to:r,text:i,insertText:c}),f=u?n+i.length:r,p=Yc({state:l.state,transaction:d}),m={from:n-(o[0].length-i.length),to:f},{commands:h,chain:g,can:_}=new Xc({editor:t,state:p});return a.handler({state:p,range:m,match:o,commands:h,chain:g,can:_})===null||!d.steps.length?!1:(u&&(l.dispatch(u),!l.state.doc.eq(u.doc))||(Vc(d),d.setMeta(`inputRule`,!0),a.undoable&&d.setMeta(s,{transform:d,from:n,to:f,text:i}),l.dispatch(d)),!0)}function pp(e,t,n){let r=t[0].length-n.length;if(r<=0)return!0;let i=e.parentOffset-r;return i>=0&&e.parent.textBetween(i,e.parentOffset)===t[0].slice(0,r)}function mp(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o,insertText:s}=e,{view:c}=t;if(c.composing)return!1;let l=c.state.doc.resolve(n);if(l.parent.type.spec.code||(l.nodeBefore||l.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let u=ad(l)+i;for(let e of a){let a=up(u,e.find);if(a&&pp(l,a,i)&&fp({editor:t,from:n,to:r,text:i,rule:e,match:a,plugin:o,insertText:s}))return!0}return!1}function hp(e){let{editor:t,rules:n}=e,r=new D({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let c=e.getMeta(`applyInputRules`);return c&&setTimeout(()=>{let{text:e}=c;e=typeof e==`string`?e:xu(s.from(e),a.schema);let{from:i}=c,o=i+e.length;mp({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return mp({editor:t,from:i,to:a,text:o,rules:n,plugin:r,insertText:!0})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&mp({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?mp({editor:t,from:a.pos,to:a.pos,text:` -`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}var gp=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...Nu(k(this,`addOptions`,{name:this.name}))}}get storage(){return{...Nu(k(this,`addStorage`,{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>sp(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},_p=class e extends gp{constructor(...e){super(...e),this.type=`mark`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},vp=class{constructor(e){this.find=e.find,this.handler=e.handler}},yp=(e,t,n)=>{if(pl(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function bp(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new Xc({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{var f;if((f=e.type)!=null&&(f=f.spec)!=null&&f.code||!(e.isText||e.isTextblock||e.isInline))return;let p=e.content?.size??e.nodeSize??0,m=Math.max(r,t),h=Math.min(i,t+p);m>=h||yp(e.isText?e.text||``:e.textBetween(m-t,h-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=m+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var xp=null,Sp=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function Cp(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c;try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}let l=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let s=e.tr,l=Yc({state:e,transaction:s});if(bp({editor:t,state:l,from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:c})&&s.steps.length){try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s}};return t.on(`destroy`,()=>{xp===t&&(xp=null)}),n.map(e=>new D({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(xp=t)},i=()=>{xp&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,c=t,!a){let e=xp;e?.isEditable&&setTimeout(()=>{if(e.isDestroyed)return;let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let c=t[0],u=c.getMeta(`uiEvent`)===`paste`&&!i,d=c.getMeta(`uiEvent`)===`drop`&&!a,f=c.getMeta(`applyPasteRules`),p=!!f;if(!u&&!d&&!p)return;if(p){let{text:t}=f;t=typeof t==`string`?t:xu(s.from(t),r.schema);let{from:n}=f,i=n+t.length,a=Sp(t);return l({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let m=n.doc.content.findDiffStart(r.doc.content),h=n.doc.content.findDiffEnd(r.doc.content);if(jf(m)&&h&&m!==h.b)return l({rule:e,state:r,from:m,to:h,pasteEvt:o})}}))}var wp=class{constructor(e,t){this.splittableMarks=[],this.nonClearableMarks=[],this.decorationManager=null,this.editor=t,this.baseExtensions=e,this.extensions=Gu(e),this.hasSchemaSpec=t.options.schemaSpec!==void 0,this.schema=Uu(this.extensions,t,t.options.schemaSpec),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=k(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:rd(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this,t=Wu([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:rd(t.name,this.schema)},r=[],i=k(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&k(t,`exitable`,n)&&(a.ArrowRight=()=>_p.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=xc(a);r.push(o);let s=k(t,`addInputRules`,n);if(ud(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=hp({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=k(t,`addPasteRules`,n);if(ud(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=Cp({editor:e,rules:t});r.push(...n)}}let l=k(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r}),n=this.createDecorationPlugin();return n&&t.push(n),t}createDecorationPlugin(){var e;let{editor:t}=this;(e=this.decorationManager)==null||e.destroy();let n=[];return this.extensions.forEach(e=>{let r=k(e,`addDecorations`,{name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:t,type:rd(e.name,this.schema)});r&&n.push({name:e.name,addDecorations:r})}),this.decorationManager=new Ef({editor:t,entries:n}),this.decorationManager.plugin}get attributes(){let e=ju(this.extensions);return this.hasSchemaSpec?Su(e,this.schema):e}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=Au(this.extensions);return Object.fromEntries(t.filter(e=>!!k(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=k(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:il(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>{let l=Lu(r,n);return i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:l})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return Wu([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:rd(n.name,this.schema)},i=k(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return Wu([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:rd(n.name,this.schema)},i=k(n,`transformPastedHTML`,r);return i?(t,n)=>{let a=e(t,n);return i.call(r,a)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=Au(this.extensions);return Object.fromEntries(t.filter(e=>!!k(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=k(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:vl(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=Lu(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{cp(i,e,t)}})}]:[]}))}destroy(){var e;(e=this.decorationManager)==null||e.destroy(),this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.decorationManager=null,this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:rd(e.name,this.schema)};e.type===`mark`&&((Nu(k(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name),(Nu(k(e,`clearable`,t))??!0)||this.nonClearableMarks.push(e.name));let n=k(e,`onBeforeCreate`,t),r=k(e,`onCreate`,t),i=k(e,`onUpdate`,t),a=k(e,`onSelectionUpdate`,t),o=k(e,`onTransaction`,t),s=k(e,`onFocus`,t),c=k(e,`onBlur`,t),l=k(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};wp.resolve=Gu,wp.sort=Wu,wp.flatten=bu;var Tp=class e extends gp{constructor(...e){super(...e),this.type=`extension`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},Ep=Tp.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new D({key:new Un(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,a=Ju(n),{blockSeparator:o}=this.options,s={...o===void 0?{}:{blockSeparator:o},textSerializers:a};return[...i.ranges].sort((e,t)=>e.$from.pos-t.$from.pos).map(({$from:e,$to:t})=>Ku(r,{from:e.pos,to:t.pos},s)).join(o??` +`);l+=e.type===`paragraph`?`\n\n${o}`:`\n${o}`}}),l}function op(e,t){let n={...e};return Mf(e)&&Mf(t)&&Object.keys(t).forEach(r=>{Mf(t[r])&&Mf(e[r])?n[r]=op(e[r],t[r]):n[r]=t[r]}),n}function sp(e,t,n={}){let{state:r}=t,{doc:i,tr:a}=r,o=e;i.descendants((t,r)=>{let i=a.mapping.map(r),s=a.mapping.map(r)+t.nodeSize,c=null;if(t.marks.forEach(e=>{if(e!==o)return!1;c=e}),!c)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==c.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});a.removeMark(i,s,e.type),a.addMark(i,s,t)}}),a.docChanged&&t.view.dispatch(a)}var cp=class{constructor(e){this.find=e.find,this.handler=e.handler,this.undoable=e.undoable??!0}},lp=(e,t)=>{if(fl(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn(`[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".`),r.push(n.replaceWith)),r};function up(e){let{editor:t,from:n,to:r,text:i,insertText:a}=e;if(!a)return{inputTransaction:null,tr:t.view.state.tr};let o=t.view.state.tr.insertText(i,n,r);return{inputTransaction:o,tr:zn.create({doc:o.doc,selection:o.selection,storedMarks:o.storedMarks}).tr}}function dp(e){let{editor:t,from:n,to:r,text:i,rule:a,match:o,plugin:s,insertText:c}=e,{view:l}=t,{inputTransaction:u,tr:d}=up({editor:t,from:n,to:r,text:i,insertText:c}),f=u?n+i.length:r,p=Jc({state:l.state,transaction:d}),m={from:n-(o[0].length-i.length),to:f},{commands:h,chain:g,can:_}=new Yc({editor:t,state:p});return a.handler({state:p,range:m,match:o,commands:h,chain:g,can:_})===null||!d.steps.length?!1:(u&&(l.dispatch(u),!l.state.doc.eq(u.doc))||(Bc(d),d.setMeta(`inputRule`,!0),a.undoable&&d.setMeta(s,{transform:d,from:n,to:f,text:i}),l.dispatch(d)),!0)}function fp(e,t,n){let r=t[0].length-n.length;if(r<=0)return!0;let i=e.parentOffset-r;return i>=0&&e.parent.textBetween(i,e.parentOffset)===t[0].slice(0,r)}function pp(e){let{editor:t,from:n,to:r,text:i,rules:a,plugin:o,insertText:s}=e,{view:c}=t;if(c.composing)return!1;let l=c.state.doc.resolve(n);if(l.parent.type.spec.code||(l.nodeBefore||l.nodeAfter)?.marks.find(e=>e.type.spec.code))return!1;let u=id(l)+i;for(let e of a){let a=lp(u,e.find);if(a&&fp(l,a,i)&&dp({editor:t,from:n,to:r,text:i,rule:e,match:a,plugin:o,insertText:s}))return!0}return!1}function mp(e){let{editor:t,rules:n}=e,r=new D({state:{init(){return null},apply(e,i,a){let o=e.getMeta(r);if(o)return o;let c=e.getMeta(`applyInputRules`);return c&&setTimeout(()=>{let{text:e}=c;e=typeof e==`string`?e:bu(s.from(e),a.schema);let{from:i}=c,o=i+e.length;pp({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput(e,i,a,o){return pp({editor:t,from:i,to:a,text:o,rules:n,plugin:r,insertText:!0})},handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&pp({editor:t,from:i.pos,to:i.pos,text:``,rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if(i.key!==`Enter`)return!1;let{$cursor:a}=e.state.selection;return a?pp({editor:t,from:a.pos,to:a.pos,text:` +`,rules:n,plugin:r}):!1}},isInputRules:!0});return r}var hp=class{constructor(e={}){this.type=`extendable`,this.parent=null,this.child=null,this.name=``,this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...Mu(A(this,`addOptions`,{name:this.name}))}}get storage(){return{...Mu(A(this,`addStorage`,{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>op(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name=`name`in e?e.name:t.parent.name,t}},gp=class e extends hp{constructor(...e){super(...e),this.type=`mark`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>e?.type.name===t.name))return!1;let a=i.find(e=>e?.type.name===t.name);return a&&n.removeStoredMark(a),n.insertText(` `,r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},_p=class{constructor(e){this.find=e.find,this.handler=e.handler}},vp=(e,t,n)=>{if(fl(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn(`[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".`),n.push(t.replaceWith)),n}):[]};function yp(e){let{editor:t,state:n,from:r,to:i,rule:a,pasteEvent:o,dropEvent:s}=e,{commands:c,chain:l,can:u}=new Yc({editor:t,state:n}),d=[];return n.doc.nodesBetween(r,i,(e,t)=>{var f;if((f=e.type)!=null&&(f=f.spec)!=null&&f.code||!(e.isText||e.isTextblock||e.isInline))return;let p=e.content?.size??e.nodeSize??0,m=Math.max(r,t),h=Math.min(i,t+p);m>=h||vp(e.isText?e.text||``:e.textBetween(m-t,h-t,void 0,``),a.find,o).forEach(e=>{if(e.index===void 0)return;let t=m+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},f=a.handler({state:n,range:i,match:e,commands:c,chain:l,can:u,pasteEvent:o,dropEvent:s});d.push(f)})}),d.every(e=>e!==null)}var bp=null,xp=e=>{var t;let n=new ClipboardEvent(`paste`,{clipboardData:new DataTransfer});return(t=n.clipboardData)==null||t.setData(`text/html`,e),n};function Sp(e){let{editor:t,rules:n}=e,r=null,i=!1,a=!1,o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,c;try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}let l=({state:e,from:n,to:r,rule:i,pasteEvt:a})=>{let s=e.tr,l=Jc({state:e,transaction:s});if(yp({editor:t,state:l,from:Math.max(n-1,0),to:r.b-1,rule:i,pasteEvent:a,dropEvent:c})&&s.steps.length){try{c=typeof DragEvent<`u`?new DragEvent(`drop`):null}catch{c=null}return o=typeof ClipboardEvent<`u`?new ClipboardEvent(`paste`):null,s}};return t.on(`destroy`,()=>{bp===t&&(bp=null)}),n.map(e=>new D({view(e){let n=n=>{r=e.dom.parentElement?.contains(n.target)?e.dom.parentElement:null,r&&(bp=t)},i=()=>{bp&&=null};return window.addEventListener(`dragstart`,n),window.addEventListener(`dragend`,i),{destroy(){window.removeEventListener(`dragstart`,n),window.removeEventListener(`dragend`,i)}}},props:{handleDOMEvents:{drop:(e,t)=>{if(a=r===e.dom.parentElement,c=t,!a){let e=bp;e?.isEditable&&setTimeout(()=>{if(e.isDestroyed)return;let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{let n=t.clipboardData?.getData(`text/html`);return o=t,i=!!n?.includes(`data-pm-slice`),!1}}},appendTransaction:(t,n,r)=>{let c=t[0],u=c.getMeta(`uiEvent`)===`paste`&&!i,d=c.getMeta(`uiEvent`)===`drop`&&!a,f=c.getMeta(`applyPasteRules`),p=!!f;if(!u&&!d&&!p)return;if(p){let{text:t}=f;t=typeof t==`string`?t:bu(s.from(t),r.schema);let{from:n}=f,i=n+t.length,a=xp(t);return l({rule:e,state:r,from:n,to:{b:i},pasteEvt:a})}let m=n.doc.content.findDiffStart(r.doc.content),h=n.doc.content.findDiffEnd(r.doc.content);if(Af(m)&&h&&m!==h.b)return l({rule:e,state:r,from:m,to:h,pasteEvt:o})}}))}var Cp=class{constructor(e,t){this.splittableMarks=[],this.nonClearableMarks=[],this.decorationManager=null,this.editor=t,this.baseExtensions=e,this.extensions=Wu(e),this.hasSchemaSpec=t.options.schemaSpec!==void 0,this.schema=Hu(this.extensions,t,t.options.schemaSpec),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n=A(t,`addCommands`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:nd(t.name,this.schema)});return n?{...e,...n()}:e},{})}get plugins(){let{editor:e}=this,t=Uu([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:nd(t.name,this.schema)},r=[],i=A(t,`addKeyboardShortcuts`,n),a={};if(t.type===`mark`&&A(t,`exitable`,n)&&(a.ArrowRight=()=>gp.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));a={...a,...t}}let o=bc(a);r.push(o);let s=A(t,`addInputRules`,n);if(ld(t,e.options.enableInputRules)&&s){let t=s();if(t&&t.length){let n=mp({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let c=A(t,`addPasteRules`,n);if(ld(t,e.options.enablePasteRules)&&c){let t=c();if(t&&t.length){let n=Sp({editor:e,rules:t});r.push(...n)}}let l=A(t,`addProseMirrorPlugins`,n);if(l){let e=l();r.push(...e)}return r}),n=this.createDecorationPlugin();return n&&t.push(n),t}createDecorationPlugin(){var e;let{editor:t}=this;(e=this.decorationManager)==null||e.destroy();let n=[];return this.extensions.forEach(e=>{let r=A(e,`addDecorations`,{name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:t,type:nd(e.name,this.schema)});r&&n.push({name:e.name,addDecorations:r})}),this.decorationManager=new Tf({editor:t,entries:n}),this.decorationManager.plugin}get attributes(){let e=Au(this.extensions);return this.hasSchemaSpec?xu(e,this.schema):e}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=ku(this.extensions);return Object.fromEntries(t.filter(e=>!!A(e,`addNodeView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=A(t,`addNodeView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:rl(t.name,this.schema)});if(!r)return[];let i=r();return i?[t.name,(r,a,o,s,c)=>{let l=Iu(r,n);return i({node:r,view:a,getPos:o,decorations:s,innerDecorations:c,editor:e,extension:t,HTMLAttributes:l})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return Uu([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:nd(n.name,this.schema)},i=A(n,`dispatchTransaction`,r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return Uu([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:nd(n.name,this.schema)},i=A(n,`transformPastedHTML`,r);return i?(t,n)=>{let a=e(t,n);return i.call(r,a)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=ku(this.extensions);return Object.fromEntries(t.filter(e=>!!A(e,`addMarkView`)).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r=A(t,`addMarkView`,{name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:_l(t.name,this.schema)});return r?[t.name,(i,a,o)=>{let s=Iu(i,n);return r()({mark:i,view:a,inline:o,editor:e,extension:t,HTMLAttributes:s,updateAttributes:t=>{sp(i,e,t)}})}]:[]}))}destroy(){var e;(e=this.decorationManager)==null||e.destroy(),this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.decorationManager=null,this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{let t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:nd(e.name,this.schema)};e.type===`mark`&&((Mu(A(e,`keepOnSplit`,t))??!0)&&this.splittableMarks.push(e.name),(Mu(A(e,`clearable`,t))??!0)||this.nonClearableMarks.push(e.name));let n=A(e,`onBeforeCreate`,t),r=A(e,`onCreate`,t),i=A(e,`onUpdate`,t),a=A(e,`onSelectionUpdate`,t),o=A(e,`onTransaction`,t),s=A(e,`onFocus`,t),c=A(e,`onBlur`,t),l=A(e,`onDestroy`,t);n&&this.editor.on(`beforeCreate`,n),r&&this.editor.on(`create`,r),i&&this.editor.on(`update`,i),a&&this.editor.on(`selectionUpdate`,a),o&&this.editor.on(`transaction`,o),s&&this.editor.on(`focus`,s),c&&this.editor.on(`blur`,c),l&&this.editor.on(`destroy`,l)})}};Cp.resolve=Wu,Cp.sort=Uu,Cp.flatten=yu;var wp=class e extends hp{constructor(...e){super(...e),this.type=`extension`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}},Tp=wp.create({name:`clipboardTextSerializer`,addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new D({key:new O(`clipboardTextSerializer`),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,a=qu(n),{blockSeparator:o}=this.options,s={...o===void 0?{}:{blockSeparator:o},textSerializers:a};return[...i.ranges].sort((e,t)=>e.$from.pos-t.$from.pos).map(({$from:e,$to:t})=>Gu(r,{from:e.pos,to:t.pos},s)).join(o??` -`)}}})]}}),Dp=Tp.create({name:`commands`,addCommands(){return{...tf}}}),Op=Tp.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){var n;let r=()=>{var n,r;if(((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null||(r=n.filterTransaction)==null?void 0:r.call(n,e))??e.getMeta(`y-sync$`))return;let i=hu(e.before,[e,...t]);$u(i).forEach(t=>{i.mapping.mapResult(t.oldRange.from).deletedAfter&&i.mapping.mapResult(t.oldRange.to).deletedBefore&&i.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let a=r+n.nodeSize-2,o=t.oldRange.from<=r&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:r,to:a,newFrom:i.mapping.map(r),newTo:i.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:i})})});let a=i.mapping;i.steps.forEach((t,n)=>{if(t instanceof xt){let r=a.slice(n).map(t.from,-1),o=a.slice(n).map(t.to),s=a.invert().map(r,-1),c=a.invert().map(o),l=r>0&&i.doc.nodeAt(r-1)?.marks.some(e=>e.eq(t.mark)),u=i.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:r,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:i})}})};((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null?void 0:n.async)??!0?setTimeout(r,0):r()}}),kp=Tp.create({name:`drop`,addProseMirrorPlugins(){return[new D({key:new Un(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),Ap=Tp.create({name:`editable`,addProseMirrorPlugins(){return[new D({key:new Un(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),jp=new Un(`focusEvents`),Mp=Tp.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new D({key:jp,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),Np=Tp.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:w.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Tl()||Jl()?i:r},addProseMirrorPlugins(){return[new D({key:new Un(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=w.atStart(t.doc).from,l=w.atEnd(t.doc).to;if(a||o!==c||s!==l||!fd(n.doc))return;let u=n.tr,d=Yc({state:n,transaction:u}),{commands:f}=new Xc({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),Pp=Tp.create({name:`paste`,addProseMirrorPlugins(){return[new D({key:new Un(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),Fp=Tp.create({name:`tabindex`,addOptions(){return{value:void 0}},addProseMirrorPlugins(){return[new D({key:new Un(`tabindex`),props:{attributes:()=>!this.editor.isEditable&&this.options.value===void 0?{}:{tabindex:this.options.value??`0`}}})]}}),Ip=Tp.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=Au(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new D({key:new Un(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),Lp=!1;function Rp(e){if(Lp)return;Lp=!0;let t;try{let n=Et.fromJSON(e,{from:0,to:0});if(!hd(n))return;t=n.slice.content}catch{return}t instanceof s||console.warn(`[tiptap warn]: prosemirror-model is loaded more than once. Wrapping and splitting nodes will fail. Deduplicate it in your lock file, or alias it to a single copy in your bundler.`)}var zp=class e{get name(){return this.node.type.name}constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1),n=this.resolvedPos.doc.resolve(t);return new e(n,this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+ +!a;if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e){if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),n&&r.length>0||(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Bp=`.ProseMirror { +`)}}})]}}),Ep=wp.create({name:`commands`,addCommands(){return{...ef}}}),Dp=wp.create({name:`delete`,onUpdate({transaction:e,appendedTransactions:t}){var n;let r=()=>{var n,r;if(((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null||(r=n.filterTransaction)==null?void 0:r.call(n,e))??e.getMeta(`y-sync$`))return;let i=mu(e.before,[e,...t]);Qu(i).forEach(t=>{i.mapping.mapResult(t.oldRange.from).deletedAfter&&i.mapping.mapResult(t.oldRange.to).deletedBefore&&i.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let a=r+n.nodeSize-2,o=t.oldRange.from<=r&&a<=t.oldRange.to;this.editor.emit(`delete`,{type:`node`,node:n,from:r,to:a,newFrom:i.mapping.map(r),newTo:i.mapping.map(a),deletedRange:t.oldRange,newRange:t.newRange,partial:!o,editor:this.editor,transaction:e,combinedTransform:i})})});let a=i.mapping;i.steps.forEach((t,n)=>{if(t instanceof xt){let r=a.slice(n).map(t.from,-1),o=a.slice(n).map(t.to),s=a.invert().map(r,-1),c=a.invert().map(o),l=r>0&&i.doc.nodeAt(r-1)?.marks.some(e=>e.eq(t.mark)),u=i.doc.nodeAt(o)?.marks.some(e=>e.eq(t.mark));this.editor.emit(`delete`,{type:`mark`,mark:t.mark,from:t.from,to:t.to,deletedRange:{from:s,to:c},newRange:{from:r,to:o},partial:!!(u||l),editor:this.editor,transaction:e,combinedTransform:i})}})};((n=this.editor.options.coreExtensionOptions)==null||(n=n.delete)==null?void 0:n.async)??!0?setTimeout(r,0):r()}}),Op=wp.create({name:`drop`,addProseMirrorPlugins(){return[new D({key:new O(`tiptapDrop`),props:{handleDrop:(e,t,n,r)=>{this.editor.emit(`drop`,{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),kp=wp.create({name:`editable`,addProseMirrorPlugins(){return[new D({key:new O(`editable`),props:{editable:()=>this.editor.options.editable}})]}}),Ap=new O(`focusEvents`),jp=wp.create({name:`focusEvents`,addProseMirrorPlugins(){let{editor:e}=this;return[new D({key:Ap,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta(`focus`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta(`blur`,{event:n}).setMeta(`addToHistory`,!1);return t.dispatch(r),!1}}}})]}}),Mp=wp.create({name:`keymap`,addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:a}=n,{pos:o,parent:s}=a,c=a.parent.isTextblock&&o>0?t.doc.resolve(o-1):a,l=c.parent.type.spec.isolating,u=a.pos-a.parentOffset,d=l&&c.parent.childCount===1?u===a.pos:w.atStart(r).from===o;return!i||!s.type.isTextblock||s.textContent.length||!d||d&&a.parent.type.name===`paragraph`?!1:e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return wl()||ql()?i:r},addProseMirrorPlugins(){return[new D({key:new O(`clearDocument`),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta(`composition`)))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta(`preventClearDocument`));if(!r||i)return;let{empty:a,from:o,to:s}=t.selection,c=w.atStart(t.doc).from,l=w.atEnd(t.doc).to;if(a||o!==c||s!==l||!dd(n.doc))return;let u=n.tr,d=Jc({state:n,transaction:u}),{commands:f}=new Yc({editor:this.editor,state:d});if(f.clearNodes(),u.steps.length)return u}})]}}),Np=wp.create({name:`paste`,addProseMirrorPlugins(){return[new D({key:new O(`tiptapPaste`),props:{handlePaste:(e,t,n)=>{this.editor.emit(`paste`,{editor:this.editor,event:t,slice:n})}}})]}}),Pp=wp.create({name:`tabindex`,addOptions(){return{value:void 0}},addProseMirrorPlugins(){return[new D({key:new O(`tabindex`),props:{attributes:()=>!this.editor.isEditable&&this.options.value===void 0?{}:{tabindex:this.options.value??`0`}}})]}}),Fp=wp.create({name:`textDirection`,addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=ku(this.extensions);return[{types:e.filter(e=>e.name!==`text`).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute(`dir`);return t&&(t===`ltr`||t===`rtl`||t===`auto`)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new D({key:new O(`textDirection`),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),Ip=!1;function Lp(e){if(Ip)return;Ip=!0;let t;try{let n=Et.fromJSON(e,{from:0,to:0});if(!md(n))return;t=n.slice.content}catch{return}t instanceof s||console.warn(`[tiptap warn]: prosemirror-model is loaded more than once. Wrapping and splitting nodes will fail. Deduplicate it in your lock file, or alias it to a single copy in your bundler.`)}var Rp=class e{get name(){return this.node.type.name}constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){return this.actualDepth??this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(this.depth===0)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1),n=this.resolvedPos.doc.resolve(t);return new e(n,this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,a=n.isAtom&&!n.isText,o=n.isInline,s=this.pos+r+ +!a;if(s<0||s>this.resolvedPos.doc.nodeSize-2)return;let c=this.resolvedPos.doc.resolve(s);if(!i&&!o&&c.depth<=this.depth)return;let l=new e(c,this.editor,i,i||o?n:null);i&&(l.actualDepth=this.depth+1),t.push(l)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e){if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r{n&&r.length>0||(a.node.type.name===e&&i.every(e=>t[e]===a.node.attrs[e])&&r.push(a),n&&r.length>0||(r=r.concat(a.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},zp=`.ProseMirror { position: relative; } @@ -100,21 +100,21 @@ img.ProseMirror-separator { .ProseMirror-focused .ProseMirror-gapcursor { display: block; -}`,Vp=class extends of{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.destroyed=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.hasWarnedStaleDecorationRead=!1,this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:_d,createMappablePosition:vd},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc();if(!this.editorState){let e=Cl(t,this.options.autofocus);this.editorState=zn.create({doc:t,schema:this.schema,selection:e||void 0})}Rp(this.schema),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){this.editorState=this.editorView.state;let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager?this.commandManager.chain():Xc.createFakeChain()}can(){return this.commandManager?this.commandManager.can():Xc.createFallbackCan()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=Of(Bp,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.editorView&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps({...this.options.editorProps,attributes:this.getEditorViewAttributes()}),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return sf&&!this.hasWarnedStaleDecorationRead&&af(this)&&(this.hasWarnedStaleDecorationRead=!0,console.warn("[tiptap warn]: `editor.state` was read while decoration `create()` was running. It returns the pre-transaction document. Use the `state` argument passed to `create()` instead. Helpers like `editor.isActive()` read `editor.state` too, so pass `state` to their standalone versions instead of calling them on the editor.")),this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=Mu(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){var e,t;let n=[...this.options.enableCoreExtensions?[Ap,Ep.configure({blockSeparator:(e=this.options.coreExtensionOptions)==null||(e=e.clipboardTextSerializer)==null?void 0:e.blockSeparator}),Dp,Mp,Np,Fp.configure({value:(t=this.options.coreExtensionOptions)==null||(t=t.tabindex)==null?void 0:t.value}),kp,Pp,Op,Ip.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions!=`object`||this.options.enableCoreExtensions[e.name]!==!1):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new wp(n,this)}createCommandManager(){this.commandManager=new Xc({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=fu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(e.message))throw e;let t=fu(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1});return this.editorState=zn.create({doc:t,schema:this.schema,selection:Cl(t,this.options.autofocus)||void 0}),this.emit(`contentError`,{editor:this,error:e,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),this.editorState.doc}return e}getEditorViewAttributes(){let e=this.options.editorProps?.attributes;return Mu(e)?t=>({role:`textbox`,...e(t)}):{role:`textbox`,...e}}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new tc(e,{...t,attributes:this.getEditorViewAttributes(),dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc)||this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return Xu(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return sd(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return xu(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=` +}`,Bp=class extends af{constructor(e={}){super(),this.css=null,this.className=`tiptap`,this.editorView=null,this.isFocused=!1,this.destroyed=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.hasWarnedStaleDecorationRead=!1,this.options={element:typeof document<`u`?document.createElement(`div`):null,content:``,injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:e})=>{throw e},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:gd,createMappablePosition:_d},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on(`beforeCreate`,this.options.onBeforeCreate),this.emit(`beforeCreate`,{editor:this}),this.on(`mount`,this.options.onMount),this.on(`unmount`,this.options.onUnmount),this.on(`contentError`,this.options.onContentError),this.on(`create`,this.options.onCreate),this.on(`update`,this.options.onUpdate),this.on(`selectionUpdate`,this.options.onSelectionUpdate),this.on(`transaction`,this.options.onTransaction),this.on(`focus`,this.options.onFocus),this.on(`blur`,this.options.onBlur),this.on(`destroy`,this.options.onDestroy),this.on(`drop`,({event:e,slice:t,moved:n})=>this.options.onDrop(e,t,n)),this.on(`paste`,({event:e,slice:t})=>this.options.onPaste(e,t)),this.on(`delete`,this.options.onDelete);let t=this.createDoc();if(!this.editorState){let e=Sl(t,this.options.autofocus);this.editorState=zn.create({doc:t,schema:this.schema,selection:e||void 0})}Lp(this.schema),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>`u`)throw Error(`[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.`);this.createView(e),this.emit(`mount`,{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit(`create`,{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){this.editorState=this.editorView.state;let e=this.editorView.dom;e?.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove==`function`?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn(`Failed to remove CSS element:`,e)}this.css=null,this.emit(`unmount`,{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager?this.commandManager.chain():Yc.createFakeChain()}can(){return this.commandManager?this.commandManager.can():Yc.createFallbackCan()}injectCSS(){this.options.injectCSS&&typeof document<`u`&&(this.css=Df(zp,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},this.editorView&&this.state&&!this.isDestroyed&&(this.options.editorProps&&this.view.setProps({...this.options.editorProps,attributes:this.getEditorViewAttributes()}),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit(`update`,{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t===`state`)return this.editorState;if(t in e)return Reflect.get(e,t);throw Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return of&&!this.hasWarnedStaleDecorationRead&&rf(this)&&(this.hasWarnedStaleDecorationRead=!0,console.warn("[tiptap warn]: `editor.state` was read while decoration `create()` was running. It returns the pre-transaction document. Use the `state` argument passed to `create()` instead. Helpers like `editor.isActive()` read `editor.state` too, so pass `state` to their standalone versions instead of calling them on the editor.")),this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){let n=ju(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;let t=this.state.plugins,n=t;if([].concat(e).forEach(e=>{let t=typeof e==`string`?`${e}$`:e.key;n=n.filter(e=>!e.key.startsWith(t))}),t.length===n.length)return;let r=this.state.reconfigure({plugins:n});return this.view.updateState(r),r}createExtensionManager(){var e,t;let n=[...this.options.enableCoreExtensions?[kp,Tp.configure({blockSeparator:(e=this.options.coreExtensionOptions)==null||(e=e.clipboardTextSerializer)==null?void 0:e.blockSeparator}),Ep,jp,Mp,Pp.configure({value:(t=this.options.coreExtensionOptions)==null||(t=t.tabindex)==null?void 0:t.value}),Op,Np,Dp,Fp.configure({direction:this.options.textDirection})].filter(e=>typeof this.options.enableCoreExtensions!=`object`||this.options.enableCoreExtensions[e.name]!==!1):[],...this.options.extensions].filter(e=>[`extension`,`node`,`mark`].includes(e?.type));this.extensionManager=new Cp(n,this)}createCommandManager(){this.commandManager=new Yc({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=du(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||![`[tiptap error]: Invalid JSON content`,`[tiptap error]: Invalid HTML content`].includes(e.message))throw e;let t=du(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1});return this.editorState=zn.create({doc:t,schema:this.schema,selection:Sl(t,this.options.autofocus)||void 0}),this.emit(`contentError`,{editor:this,error:e,disableCollaboration:()=>{`collaboration`in this.storage&&typeof this.storage.collaboration==`object`&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(e=>e.name!==`collaboration`),this.createExtensionManager()}}),this.editorState.doc}return e}getEditorViewAttributes(){let e=this.options.editorProps?.attributes;return ju(e)?t=>({role:`textbox`,...e(t)}):{role:`textbox`,...e}}createView(e){let{editorProps:t,enableExtensionDispatchTransaction:n}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),i=n?this.extensionManager.dispatchTransaction(r):r,a=t.transformPastedHTML,o=this.extensionManager.transformPastedHTML(a);this.editorView=new ec(e,{...t,attributes:this.getEditorViewAttributes(),dispatchTransaction:i,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});let s=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(s),this.prependClass(),this.injectCSS();let c=this.view.dom;c.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;let t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(e=>this.capturedTransaction?.step(e));return}let{state:t,transactions:n}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),i=n.includes(e),a=this.state;if(this.emit(`beforeTransaction`,{editor:this,transaction:e,nextState:t}),!i)return;this.view.updateState(t),this.emit(`transaction`,{editor:this,transaction:e,appendedTransactions:n.slice(1)}),r&&this.emit(`selectionUpdate`,{editor:this,transaction:e});let o=n.findLast(e=>e.getMeta(`focus`)||e.getMeta(`blur`)),s=o?.getMeta(`focus`),c=o?.getMeta(`blur`);s&&this.emit(`focus`,{editor:this,event:s.event,transaction:o}),c&&this.emit(`blur`,{editor:this,event:c.event,transaction:o}),e.getMeta(`preventUpdate`)||!n.some(e=>e.docChanged)||a.doc.eq(t.doc)||this.emit(`update`,{editor:this,transaction:e,appendedTransactions:n.slice(1)})}getAttributes(e){return Yu(this.state,e)}isActive(e,t){let n=typeof e==`string`?e:null,r=typeof e==`string`?t:e;return od(this.state,n,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return bu(this.state.doc.content,this.schema)}getText(e){let{blockSeparator:t=` -`,textSerializers:n={}}=e||{};return qu(this.state.doc,{blockSeparator:t,textSerializers:{...Ju(this.schema),...n}})}get isEmpty(){return fd(this.state.doc)}destroy(){this.destroyed||(this.destroyed=!0,this.emit(`destroy`),this.unmount(),this.removeAllListeners(),this.extensionManager.destroy(),this.extensionManager=null,this.schema=null,this.commandManager=null,this.extensionStorage={})}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){let t=this.state.doc.resolve(e),n=e>0&&t.nodeAfter&&!t.nodeAfter.isText&&t.nodeAfter.isAtom?t.nodeAfter:null;return new zp(t,this,!1,n)}get $doc(){return this.$pos(0)}};function Hp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Nu(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if(ed(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;ln.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function Up(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Nu(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function Wp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=Nu(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function Gp(e){return new lp({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=Nu(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&Ft(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&qt(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}var Kp=e=>`touches`in e,qp=class{constructor(e){var t;this.directions=[`bottom-left`,`bottom-right`,`top-left`,`top-right`],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:``,wrapper:``,handle:``,resizing:``},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.clientX-this.startX,n=e.clientY-this.startY;this.handleResize(t,n)},this.handleTouchMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this.startX,r=t.clientY-this.startY;this.handleResize(n,r)},this.handleMouseUp=()=>{if(!this.isResizing)return;let e=this.element.offsetWidth,t=this.element.offsetHeight;this.onCommit(e,t),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp)},this.handleKeyDown=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!1)},this.node=e.node,this.editor=e.editor,this.element=e.element,this.element.draggable=!1,this.contentElement=e.contentElement,this.getPos=e.getPos,this.onResize=e.onResize,this.onCommit=e.onCommit,this.onUpdate=e.onUpdate,e.options?.min&&(this.minSize={...this.minSize,...e.options.min}),e.options?.max&&(this.maxSize=e.options.max),e!=null&&(t=e.options)!=null&&t.directions&&(this.directions=e.options.directions),e.options?.preserveAspectRatio&&(this.preserveAspectRatio=e.options.preserveAspectRatio),e.options?.className&&(this.classNames={container:e.options.className.container||``,wrapper:e.options.className.wrapper||``,handle:e.options.className.handle||``,resizing:e.options.className.resizing||``}),e.options?.createCustomHandle&&(this.createCustomHandle=e.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on(`update`,this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){return this.contentElement??null}handleEditorUpdate(){let e=this.editor.isEditable;e!==this.lastEditableState&&(this.lastEditableState=e,e?e&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(e,t,n){return e.type===this.node.type&&(this.node=e,!this.onUpdate||this.onUpdate(e,t,n))}destroy(){this.isResizing&&(this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off(`update`,this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){let e=document.createElement(`div`);return e.dataset.resizeContainer=``,e.dataset.node=this.node.type.name,e.style.display=this.node.type.isInline?`inline-flex`:`flex`,this.classNames.container&&(e.className=this.classNames.container),e.appendChild(this.wrapper),e}createWrapper(){let e=document.createElement(`div`);return e.style.position=`relative`,e.style.display=`block`,e.dataset.resizeWrapper=``,this.classNames.wrapper&&(e.className=this.classNames.wrapper),e.appendChild(this.element),e}createHandle(e){let t=document.createElement(`div`);return t.dataset.resizeHandle=e,t.style.position=`absolute`,this.classNames.handle&&(t.className=this.classNames.handle),t}positionHandle(e,t){let n=t.includes(`top`),r=t.includes(`bottom`),i=t.includes(`left`),a=t.includes(`right`);n&&(e.style.top=`0`),r&&(e.style.bottom=`0`),i&&(e.style.left=`0`),a&&(e.style.right=`0`),(t===`top`||t===`bottom`)&&(e.style.left=`0`,e.style.right=`0`),(t===`left`||t===`right`)&&(e.style.top=`0`,e.style.bottom=`0`)}attachHandles(){this.directions.forEach(e=>{let t;t=this.createCustomHandle?this.createCustomHandle(e):this.createHandle(e),t instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${e}") did not return an HTMLElement. Falling back to default handle.`),t=this.createHandle(e)),this.createCustomHandle||this.positionHandle(t,e),t.addEventListener(`mousedown`,t=>this.handleResizeStart(t,e)),t.addEventListener(`touchstart`,t=>this.handleResizeStart(t,e)),this.handleMap.set(e,t),this.wrapper.appendChild(t)})}removeHandles(){this.handleMap.forEach(e=>e.remove()),this.handleMap.clear()}applyInitialSize(){let e=this.node.attrs.width,t=this.node.attrs.height;e?(this.element.style.width=`${e}px`,this.initialWidth=e):this.initialWidth=this.element.offsetWidth,t?(this.element.style.height=`${t}px`,this.initialHeight=t):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.isResizing=!0,this.activeHandle=t,Kp(e)?(this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY):(this.startX=e.clientX,this.startY=e.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState=`true`,this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener(`mousemove`,this.handleMouseMove),document.addEventListener(`touchmove`,this.handleTouchMove),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`keydown`,this.handleKeyDown),document.addEventListener(`keyup`,this.handleKeyUp)}handleResize(e,t){if(!this.activeHandle)return;let n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:i}=this.calculateNewDimensions(this.activeHandle,e,t),a=this.applyConstraints(r,i,n);this.element.style.width=`${a.width}px`,this.element.style.height=`${a.height}px`,this.onResize&&this.onResize(a.width,a.height)}calculateNewDimensions(e,t,n){let r=this.startWidth,i=this.startHeight,a=e.includes(`right`),o=e.includes(`left`),s=e.includes(`bottom`),c=e.includes(`top`);return a?r=this.startWidth+t:o&&(r=this.startWidth-t),s?i=this.startHeight+n:c&&(i=this.startHeight-n),(e===`right`||e===`left`)&&(r=this.startWidth+(a?t:-t)),(e===`top`||e===`bottom`)&&(i=this.startHeight+(s?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,i,e):{width:r,height:i}}applyConstraints(e,t,n){if(!n){let n=Math.max(this.minSize.width,e),r=Math.max(this.minSize.height,t);return this.maxSize?.width&&(n=Math.min(this.maxSize.width,n)),this.maxSize?.height&&(r=Math.min(this.maxSize.height,r)),{width:n,height:r}}let r=e,i=t;return rthis.maxSize.width&&(r=this.maxSize.width,i=r/this.aspectRatio),this.maxSize?.height&&i>this.maxSize.height&&(i=this.maxSize.height,r=i*this.aspectRatio),{width:r,height:i}}applyAspectRatio(e,t,n){return n===`left`||n===`right`?{width:e,height:e/this.aspectRatio}:n===`top`||n===`bottom`?{width:t*this.aspectRatio,height:t}:{width:e,height:e/this.aspectRatio}}},Jp=class e extends gp{constructor(...e){super(...e),this.type=`node`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Yp(e){return new vp({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=Nu(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let i=c.search(/\S/),u=n.from+c.indexOf(s),d=u+s.length;if(ed(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>u).length)return null;dn.from&&o.delete(n.from+i,u),l=n.from+i+s.length,o.addMark(n.from+i,l,e.type.create(a||{})),r.index!==void 0&&r.input!==void 0&&r.index+r[0].length>=r.input.length||o.removeStoredMark(e.type)}}})}var Xp=e=>e.replace(/[&<>"']/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`})[e]);function Zp(e,t=600){let n=[],r=``;for(let i of e.replace(/\s+/g,` `).trim().split(/(?<=[.!?…])\s+/))r&&r.length+i.length>t&&(n.push(r),r=``),r=r?`${r} ${i}`:i;return r&&n.push(r),n}function Qp(e,t,n){let r=`

${Xp(t.summaryTitle.replace(`{name}`,e.name))}

`;e.summary?r+=n(e.summary):e.summaryError&&(r+=`

${Xp(e.summaryError)}

`);let i=Zp(e.text).map(e=>`

${Xp(e)}

`).join(``);return`${r}
${Xp(t.transcript)}
${i}
`}var $p=()=>new Map,em=e=>{let t=$p();return e.forEach((e,n)=>{t.set(n,e)}),t},tm=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},nm=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},rm=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},im=()=>new Set,am=e=>e[e.length-1],om=(e,t)=>{for(let n=0;n{for(let n=0;n{for(let n=0;n{let n=Array(e);for(let r=0;r{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return sm((this._observers.get(e)||$p()).values()).forEach(e=>e(...t))}destroy(){this._observers=$p()}},pm=class{constructor(){this._observers=$p()}on(e,t){tm(this._observers,e,im).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return sm((this._observers.get(e)||$p()).values()).forEach(e=>e(...t))}destroy(){this._observers=$p()}},mm=Math.floor,hm=Math.abs,gm=(e,t)=>ee>t?e:t;Number.isNaN;var vm=e=>e===0?1/e<0:e<0,ym=1<<29,bm=2**53-1,xm=-(2**53-1),Sm=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&mm(e)===e);Number.isNaN,Number.parseInt;var Cm=String.fromCharCode;String.fromCodePoint,Cm(65535);var wm=e=>e.toLowerCase(),Tm=/^\s*/g,Em=e=>e.replace(Tm,``),Dm=/([A-Z])/g,Om=(e,t)=>Em(e.replace(Dm,e=>`${t}${wm(e)}`)),km=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;eAm.encode(e):km,Mm=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});Mm&&Mm.decode(new Uint8Array).length===1&&(Mm=null);var Nm=(e,t)=>um(t,()=>e).join(``),Pm=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Fm=()=>new Pm,Im=e=>{let t=Fm();return e(t),Rm(t)},Lm=e=>{let t=e.cpos;for(let n=0;n{let t=new Uint8Array(Lm(e)),n=0;for(let r=0;r{let n=e.cbuf.length;n-e.cpos{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},Vm=Bm,j=(e,t)=>{for(;t>127;)Bm(e,128|127&t),t=mm(t/128);Bm(e,127&t)},Hm=(e,t)=>{let n=vm(t);for(n&&(t=-t),Bm(e,(t>63?128:0)|(n?64:0)|63&t),t=mm(t/64);t>0;)Bm(e,(t>127?128:0)|127&t),t=mm(t/128)},Um=new Uint8Array(3e4),Wm=Um.length/3,Gm=Am&&Am.encodeInto?(e,t)=>{if(t.length{let n=unescape(encodeURIComponent(t)),r=n.length;j(e,r);for(let t=0;t{let n=e.cbuf.length,r=e.cpos,i=gm(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(_m(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},qm=(e,t)=>{j(e,t.byteLength),Km(e,t)},Jm=(e,t)=>{zm(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ym=(e,t)=>Jm(e,4).setFloat32(0,t,!1),Xm=(e,t)=>Jm(e,8).setFloat64(0,t,!1),Zm=(e,t)=>Jm(e,8).setBigInt64(0,t,!1),Qm=new DataView(new ArrayBuffer(4)),$m=e=>(Qm.setFloat32(0,e),Qm.getFloat32(0)===e),eh=(e,t)=>{switch(typeof t){case`string`:Bm(e,119),Gm(e,t);break;case`number`:Sm(t)&&hm(t)<=2147483647?(Bm(e,125),Hm(e,t)):$m(t)?(Bm(e,124),Ym(e,t)):(Bm(e,123),Xm(e,t));break;case`bigint`:Bm(e,122),Zm(e,t);break;case`object`:if(t===null)Bm(e,126);else if(dm(t)){Bm(e,117),j(e,t.length);for(let n=0;n0&&j(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},nh=e=>{e.count>0&&(Hm(e.encoder,e.count===1?e.s:-e.s),e.count>1&&j(e.encoder,e.count-2))},rh=class{constructor(){this.encoder=new Pm,this.s=0,this.count=0}write(e){this.s===e?this.count++:(nh(this),this.count=1,this.s=e)}toUint8Array(){return nh(this),Rm(this.encoder)}},ih=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Hm(e.encoder,t),e.count>1&&j(e.encoder,e.count-2)}},ah=class{constructor(){this.encoder=new Pm,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(ih(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return ih(this),Rm(this.encoder)}},oh=class{constructor(){this.sarr=[],this.s=``,this.lensE=new rh}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Pm;return this.sarr.push(this.s),this.s=``,Gm(e,this.sarr.join(``)),Km(e,this.lensE.toUint8Array()),Rm(e)}},sh=e=>Error(e),ch=()=>{throw sh(`Method unimplemented`)},lh=()=>{throw sh(`Unexpected case`)},uh=sh(`Unexpected end of array`),dh=sh(`Integer out of Range`),fh=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw uh;return new Uint8Array(e.buffer,e.byteOffset+t,n)},ph=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw uh;return new DataView(e.buffer,e.byteOffset+t,n)},mh=class{constructor(e){this.arr=e,this.pos=0}},hh=e=>new mh(e),gh=e=>e.pos!==e.arr.length,_h=(e,t)=>{let n=fh(e.arr,e.pos,t);return e.pos+=t,n},vh=e=>_h(e,M(e)),yh=e=>e.arr[e.pos++],M=e=>{let t=0,n=1,r=e.arr.length;for(;e.posbm)throw dh}throw uh},bh=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.posbm)throw dh}throw uh},xh=Mm?e=>Mm.decode(vh(e)):e=>{let t=M(e);if(t===0)return``;{let n=String.fromCodePoint(yh(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(yh(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},Sh=(e,t)=>{let n=ph(e.arr,e.pos,t);return e.pos+=t,n},Ch=[e=>void 0,e=>null,bh,e=>Sh(e,4).getFloat32(0,!1),e=>Sh(e,8).getFloat64(0,!1),e=>Sh(e,8).getBigInt64(0,!1),e=>!1,e=>!0,xh,e=>{let t=M(e),n={};for(let r=0;r{let t=M(e),n=[];for(let r=0;rCh[127-yh(e)](e),Th=class extends mh{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=gh(this)?M(this)+1:-1),this.count--,this.s}},Eh=class extends mh{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=bh(this);let e=vm(this.s);this.count=1,e&&(this.s=-this.s,this.count=M(this)+2)}return this.count--,this.s}},Dh=class extends mh{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=bh(this),t=e&1;this.diff=mm(e/2),this.count=1,t&&(this.count=M(this)+2)}return this.s+=this.diff,this.count--,this.s}},Oh=class{constructor(e){this.decoder=new Eh(e),this.str=xh(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var kh=crypto.getRandomValues.bind(crypto),Ah=Math.random,jh=()=>kh(new Uint32Array(1))[0],Mh=e=>e[mm(Ah()*e.length)],Nh=`10000000-1000-4000-8000-100000000000`,Ph=()=>Nh.replace(/[018]/g,e=>(e^jh()&15>>e/4).toString(16)),Fh=Date.now,Ih=e=>new Promise(e);Promise.all.bind(Promise);var Lh=e=>e===void 0?null:e,Rh=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Rh=localStorage)}catch{}var zh=Rh,Bh=Symbol(`Equality`),Vh=(e,t)=>e===t||!!e?.[Bh]?.(t)||!1,Hh=e=>typeof e==`object`,Uh=Object.assign,Wh=Object.keys,Gh=(e,t)=>{for(let n in e)t(e[n],n)},Kh=e=>Wh(e).length,qh=e=>{for(let t in e)return!1;return!0},Jh=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Yh=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Xh=(e,t)=>e===t||Kh(e)===Kh(t)&&Jh(e,(e,n)=>(e!==void 0||Yh(t,n))&&Vh(t[n],e)),Zh=Object.freeze,Qh=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Qh(e[t])}return Zh(e)},$h=(e,t,n=0)=>{try{for(;ne,tg=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Bh]!=null)return e[Bh](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;nt.includes(e),rg=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,ig=typeof window<`u`&&typeof document<`u`&&!rg;typeof navigator<`u`&&/Mac/.test(navigator.platform);var ag,og=[],sg=()=>{if(ag===void 0){if(rg){ag=$p();let e=process.argv,t=null;for(let n=0;n{if(e.length!==0){let[t,n]=e.split(`=`);ag.set(`--${Om(t,`-`)}`,n),ag.set(`-${Om(t,`-`)}`,n)}})):ag=$p()}return ag},cg=e=>sg().has(e),lg=e=>Lh(rg?{}[e.toUpperCase().replaceAll(`-`,`_`)]:zh.getItem(e)),ug=e=>cg(`--`+e)||lg(e)!==null,dg=ug(`production`),fg=rg&&ng({}.FORCE_COLOR,[`true`,`1`,`2`])||!cg(`--no-colors`)&&!ug(`no-color`)&&(!rg||process.stdout.isTTY)&&(!rg||cg(`--color`)||lg(`COLORTERM`)!==null||(lg(`TERM`)||``).includes(`color`)),pg=e=>new Uint8Array(e),mg=e=>{let t=``;for(let n=0;nBuffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),gg=e=>{let t=atob(e),n=pg(t.length);for(let e=0;enew Uint8Array(Buffer.from(e,`base64`)),vg=ig?mg:hg,yg=ig?gg:_g,bg=e=>{let t=pg(e.byteLength);return t.set(e),t},xg=e=>Im(t=>eh(t,e)),Sg=class{constructor(e,t){this.left=e,this.right=t}},Cg=(e,t)=>new Sg(e,t),wg=e=>e.next()>=.5,Tg=(e,t,n)=>mm(e.next()*(n+1-t)+t),Eg=(e,t,n)=>mm(e.next()*(n+1-t)+t),Dg=(e,t,n)=>Eg(e,t,n),Og=e=>Cm(Dg(e,97,122)),kg=(e,t=0,n=20)=>{let r=Dg(e,t,n),i=``;for(let t=0;tt[Dg(e,0,t.length-1)],jg=Symbol(`0schema`),Mg=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Nm(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(` -`)}},Ng=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Bh]?Vh(e,t):dm(e)?cm(e,e=>lm(t,t=>Ng(e,t))):Hh(e)?Jh(e,(e,n)=>Ng(e,t[n])):!1,Pg=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Ng(t,n)}equals(e){return this.constructor===e.constructor&&tg(this.shape,e.shape)}[jg](){return!0}[Bh](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){ch()}get nullable(){return p_(this,O_)}get optional(){return new Gg(this)}cast(e){return M_(e,this),e}expect(e){return M_(e,this),e}},Fg=class extends Pg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},Ig=(e,t=null)=>new Fg(e,t);Ig(Fg);var Lg=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},Rg=e=>new Lg(e);Ig(Lg);var zg=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},Bg=(...e)=>new zg(e),Vg=Ig(zg),Hg=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Ug=e=>{if(C_.check(e))return[Hg(e)];if(Vg.check(e))return e.shape.map(e=>e+``);if(S_.check(e))return[`[+-]?\\d+.?\\d*`];if(w_.check(e))return[`.*`];if(m_.check(e))return e.shape.map(Ug).flat(1);lh()};Ig(class extends Pg{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Ug).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Wg=Symbol(`optional`),Gg=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Wg](){return!0}},Kg=Ig(Gg),qg=class extends Pg{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new qg,Ig(qg);var Jg=class e extends Pg{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):Jh(this.shape,(n,r)=>{let i=this._isPartial&&!Yh(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Yg=e=>new Jg(e),Xg=Ig(Jg),Zg=Rg(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Qg=class extends Pg{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Jh(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},$g=(e,t)=>new Qg(e,t),e_=Ig(Qg),t_=class extends Pg{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Jh(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},n_=(...e)=>new t_(e);Ig(t_);var r_=class extends Pg{constructor(e){super(),this.shape=e.length===1?e[0]:new f_(e)}check(e,t){let n=dm(e)&&cm(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},i_=(...e)=>new r_(e),a_=Ig(r_),o_=Rg(e=>dm(e)),s_=class extends Pg{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},c_=(e,t=null)=>new s_(e,t);Ig(s_);var l_=c_(Pg),u_=Ig(class extends Pg{constructor(e){super(),this.len=e.length-1,this.args=n_(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),d_=Rg(e=>typeof e==`function`);Ig(class extends Pg{constructor(e){super(),this.shape=e}check(e,t){let n=cm(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var f_=class extends Pg{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=lm(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},p_=(...e)=>e.findIndex(e=>m_.check(e))>=0?p_(...e.map(e=>j_(e)).map(e=>m_.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new f_(e),m_=Ig(f_),h_=()=>!0,g_=Rg(h_),__=Ig(Lg,e=>e.shape===h_),v_=Rg(e=>typeof e==`bigint`),y_=Rg(e=>e===v_),b_=Rg(e=>typeof e==`symbol`);Rg(e=>e===b_);var x_=Rg(e=>typeof e==`number`),S_=Rg(e=>e===x_),C_=Rg(e=>typeof e==`string`),w_=Rg(e=>e===C_),T_=Rg(e=>typeof e==`boolean`),E_=Rg(e=>e===T_),D_=Bg(void 0);Ig(zg,e=>e.shape.length===1&&e.shape[0]===void 0),Bg(void 0);var O_=Bg(null),k_=Ig(zg,e=>e.shape.length===1&&e.shape[0]===null);Ig(Uint8Array),Ig(Fg,e=>e.shape===Uint8Array);var A_=p_(x_,C_,O_,D_,v_,T_,b_);(()=>{let e=i_(g_),t=$g(C_,g_),n=p_(x_,C_,O_,T_,e,t);return e.shape=n,t.shape.values=n,n})();var j_=e=>{if(l_.check(e))return e;if(Zg.check(e)){let t={};for(let n in e)t[n]=j_(e[n]);return Yg(t)}if(o_.check(e))return p_(...e.map(j_));if(A_.check(e))return Bg(e);if(d_.check(e))return Ig(e);lh()},M_=dg?()=>{}:(e,t)=>{let n=new Mg;if(!t.check(e,n))throw sh(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},N_=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:j_(e),h:t}),this}else(e){return this.if(g_,e)}done(){return(e,t)=>{for(let n=0;nnew N_(e))(g_).if(S_,(e,t)=>Tg(t,xm,bm)).if(w_,(e,t)=>kg(t)).if(E_,(e,t)=>wg(t)).if(y_,(e,t)=>BigInt(Tg(t,xm,bm))).if(m_,(e,t)=>F_(t,Ag(t,e.shape))).if(Xg,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Kg.check(i)){if(wg(t))continue;i=i.shape}n[r]=P_(i,t)}return n}).if(a_,(e,t)=>{let n=[],r=Eg(t,0,42);for(let i=0;iAg(t,e.shape)).if(k_,(e,t)=>null).if(u_,(e,t)=>{let n=F_(t,e.res);return()=>n}).if(__,(e,t)=>F_(t,Ag(t,[x_,C_,O_,D_,v_,T_,i_(x_),$g(p_(`a`,`b`,`c`),x_)]))).if(e_,(e,t)=>{let n={},r=Tg(t,0,3);for(let i=0;iP_(j_(t),e),I_=typeof document<`u`?document:{};Rg(e=>e.nodeType===V_),typeof DOMParser<`u`&&new DOMParser,Rg(e=>e.nodeType===R_),Rg(e=>e.nodeType===z_);var L_=e=>nm(e,(e,t)=>`${t}:${e};`).join(``),R_=I_.ELEMENT_NODE,z_=I_.TEXT_NODE;I_.CDATA_SECTION_NODE,I_.COMMENT_NODE;var B_=I_.DOCUMENT_NODE;I_.DOCUMENT_TYPE_NODE;var V_=I_.DOCUMENT_FRAGMENT_NODE;Rg(e=>e.nodeType===B_);var H_=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),U_=(e,t)=>new H_(setTimeout(t,e)),W_=Symbol,G_=W_(),K_=W_(),q_=W_(),J_=W_(),Y_=W_(),X_=W_(),Z_=W_(),Q_=W_(),$_=W_(),ev=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r0&&n.push(t.join(``));r{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=$p(),i=[],a=0;for(;a0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a{console.log(...nv(e)),av.forEach(t=>t.print(e))},iv=(...e)=>{console.warn(...nv(e)),e.unshift(Q_),av.forEach(t=>t.print(e))},av=im(),ov=e=>({[Symbol.iterator](){return this},next:e}),sv=(e,t)=>ov(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),cv=(e,t)=>ov(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),lv=class{constructor(e,t){this.clock=e,this.len=t}},uv=class{constructor(){this.clients=new Map}},dv=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r{let n=0,r=e.length-1;for(;n<=r;){let i=mm((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t{let n=e.clients.get(t.client);return n!==void 0&&fv(n,t.clock)!==null},mv=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t=i.clock?e[n-1]=new lv(r.clock,_m(r.len,i.clock+i.len-r.clock)):(n{let t=new uv;for(let n=0;n{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t{tm(e.clients,t,()=>[]).push(new lv(n,r))},_v=()=>new uv,vv=e=>{let t=_v();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t0&&t.clients.set(n,r)}),t},yv=(e,t)=>{j(e.restEncoder,t.clients.size),sm(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),j(e.restEncoder,t);let r=n.length;j(e.restEncoder,r);for(let t=0;t{let t=new uv,n=M(e.restDecoder);for(let r=0;r0){let i=tm(t.clients,n,()=>[]);for(let t=0;t{let r=new uv,i=M(e.restDecoder);for(let a=0;a0){let e=new jv;return j(e.restEncoder,0),yv(e,r),e.toUint8Array()}return null},Sv=jh,Cv=class e extends fm{constructor({guid:e=Ph(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=Sv(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Sy,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ih(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Ih(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&By(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(sm(this.subdocs).map(e=>e.guid))}transact(e,t=null){return By(this,e,t)}get(e,t=gb){let n=tm(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==gb&&r!==t){if(r===gb){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Lb)}getText(e=``){return this.get(e,ix)}getMap(e=``){return this.get(e,Bb)}getXmlElement(e=``){return this.get(e,lx)}getXmlFragment(e=``){return this.get(e,sx)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,sm(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,By(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},wv=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return M(this.restDecoder)}readDsLen(){return M(this.restDecoder)}},Tv=class extends wv{readLeftID(){return N(M(this.restDecoder),M(this.restDecoder))}readRightID(){return N(M(this.restDecoder),M(this.restDecoder))}readClient(){return M(this.restDecoder)}readInfo(){return yh(this.restDecoder)}readString(){return xh(this.restDecoder)}readParentInfo(){return M(this.restDecoder)===1}readTypeRef(){return M(this.restDecoder)}readLen(){return M(this.restDecoder)}readAny(){return wh(this.restDecoder)}readBuf(){return bg(vh(this.restDecoder))}readJSON(){return JSON.parse(xh(this.restDecoder))}readKey(){return xh(this.restDecoder)}},Ev=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=M(this.restDecoder),this.dsCurrVal}readDsLen(){let e=M(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Dv=class extends Ev{constructor(e){super(e),this.keys=[],M(e),this.keyClockDecoder=new Dh(vh(e)),this.clientDecoder=new Eh(vh(e)),this.leftClockDecoder=new Dh(vh(e)),this.rightClockDecoder=new Dh(vh(e)),this.infoDecoder=new Th(vh(e),yh),this.stringDecoder=new Oh(vh(e)),this.parentInfoDecoder=new Th(vh(e),yh),this.typeRefDecoder=new Eh(vh(e)),this.lenDecoder=new Eh(vh(e))}readLeftID(){return new ey(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new ey(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return wh(this.restDecoder)}readBuf(){return vh(this.restDecoder)}readJSON(){return wh(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=_m(r,t[0].id.clock);let i=Ey(t,r);j(e.restEncoder,t.length-i),e.writeClient(n),j(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n{let r=new Map;n.forEach((e,n)=>{wy(t,n)>e&&r.set(n,e)}),Cy(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),j(e.restEncoder,r.size),sm(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Mv(e,t.clients.get(n),n,r)})},Pv=(e,t)=>{let n=$p(),r=M(e.restDecoder);for(let i=0;i{let r=[],i=sm(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new Sy,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==nS){let i=tm(d,u.id.client,()=>wy(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,wy(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i0)u=r.pop();else if(o!==null&&o.i0){let e=new jv;return Nv(e,s,new Map),j(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Iv=(e,t)=>Nv(e,t.doc.store,t.beforeState),Lv=(e,t,n,r=new Dv(e))=>By(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Fv(e,i,Pv(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(nt)&&o.missing.set(e,t)}o.update=Xy([o.update,a.update])}}else i.pendingStructs=a;let s=xv(r,e,i);if(i.pendingDs){let t=new Dv(hh(i.pendingDs));M(t.restDecoder);let n=xv(t,e,i);i.pendingDs=s&&n?Xy([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Rv(e.doc,t)}},n,!1),Rv=(e,t,n,r=Dv)=>{let i=hh(t);Lv(i,e,n,new r(i))},zv=(e,t,n)=>Rv(e,t,n,Tv),Bv=(e,t,n=new Map)=>{Nv(e,t.store,n),yv(e,vv(t.store))},Vv=(e,t=new Uint8Array([0]),n=new jv)=>{Bv(n,e,Wv(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Zy(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===kv)return Jy(r.map((e,t)=>t===0?e:nb(e)));if(n.constructor===jv)return Xy(r)}return r[0]},Hv=(e,t)=>Vv(e,t,new kv),Uv=e=>{let t=new Map,n=M(e.restDecoder);for(let r=0;rUv(new wv(hh(e))),Gv=(e,t)=>(j(e.restEncoder,t.size),sm(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{j(e.restEncoder,t),j(e.restEncoder,n)}),e),Kv=(e,t)=>Gv(e,Cy(t.store)),qv=(e,t=new Av)=>(e instanceof Map?Gv(t,e):Kv(t,e),t.toUint8Array()),Jv=e=>qv(e,new Ov),Yv=class{constructor(){this.l=[]}},Xv=()=>new Yv,Zv=(e,t)=>e.l.push(t),Qv=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},$v=(e,t,n)=>$h(e.l,[t,n]),ey=class{constructor(e,t){this.client=e,this.clock=t}},ty=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,N=(e,t)=>new ey(e,t),ny=e=>N(M(e),M(e)),ry=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw lh()},iy=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},ay=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},oy=e=>new ay(e.type==null?null:N(e.type.client,e.type.clock),e.tname??null,e.item==null?null:N(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),sy=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},cy=(e,t,n=0)=>new sy(e,t,n),ly=(e,t,n)=>{let r=null,i=null;return e._item===null?i=ry(e):r=N(e._item.id.client,e._item.id.clock),new ay(r,i,t,n)},uy=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return ly(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return ly(e,N(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return ly(e,r.lastId,n);r=r.right}return ly(e,null,n)},dy=e=>{let t=null,n=null,r=null;switch(M(e)){case 0:r=ny(e);break;case 1:n=xh(e);break;case 2:t=ny(e)}let i=gh(e)?bh(e):0;return new ay(t,n,r,i)},fy=e=>dy(hh(e)),py=(e,t)=>{let n=Dy(e,t);return{item:n,diff:t.clock-n.id.clock}},my=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(wy(r,i.client)<=i.clock)return null;let e=n?qx(r,i):py(r,i),t=e.item;if(!(t instanceof Qx))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(wy(r,a.client)<=a.clock)return null;let{item:e}=n?qx(r,a):{item:Dy(r,a)};if(e instanceof Qx&&e.content instanceof Gx)c=e.content.type;else return null}else throw lh();l=s>=0?c._length:0}return cy(c,l,e.assoc)},hy=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&ty(e.item,t.item)&&ty(e.type,t.type)&&e.assoc===t.assoc,gy=class{constructor(e,t){this.ds=e,this.sv=t}},_y=(e,t)=>new gy(e,t),vy=_y(_v(),new Map),yy=e=>_y(vv(e.store),Cy(e.store)),by=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!pv(t.ds,e.id),xy=(e,t)=>{let n=tm(e.meta,xy,im),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t{}),n.add(t))},Sy=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Cy=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},wy=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},Ty=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw lh()}n.push(t)},Ey=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=mm(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t{let n=e.clients.get(t.client);return n[Ey(n,t.clock)]},Oy=(e,t,n)=>{let r=Ey(t,n),i=t[r];return i.id.clock{let n=e.doc.store.clients.get(t.client);return n[Oy(e,n,t.clock)]},Ay=(e,t,n)=>{let r=t.clients.get(n.client),i=Ey(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==vx&&r.splice(i+1,0,Yx(e,a,n.clock-a.id.clock+1)),a},jy=(e,t,n)=>{let r=e.clients.get(t.id.client);r[Ey(r,t.id.clock)]=n},My=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=Oy(e,t,n),s;do s=t[o++],at.deleteSet.clients.size===0&&!rm(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(mv(t.deleteSet),Iv(e,t),yv(e,t.deleteSet),!0),Fy=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&tm(e.changed,t,im).add(n)},Iy=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Qx&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},Ly=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=Ey(e,a.clock),i=e[r];r{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=gm(r.length-1,1+Ey(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Iy(r,e)}})},zy=(e,t)=>{if(te.push(()=>{r._item!==null&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&e.push(()=>{t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),$v(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&tx(n)})}),$h(e,[])}finally{r.gc&&Ly(a,i,r.gcFilter),Ry(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=_m(Ey(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Iy(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=Ey(r,n);a+11||a>0&&Iy(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(rv(Q_,G_,`[yjs] `,K_,X_,`Changed the client-id because another client seems to be using it.`),r.clientID=Sv()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new kv;Py(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new jv;Py(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):zy(e,t+1)}}},By=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Ny(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&zy(i,0)}}return o},Vy=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Hy=(e,t,n)=>{dv(e,n.deletions,n=>{n instanceof Qx&&t.scope.some(t=>t===e.doc||iy(t,n))&&Jx(n,!1)})},Uy=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;By(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;dv(n,o.insertions,e=>{if(e instanceof Qx){if(e.redone!==null){let{item:t,diff:i}=qx(r,e.id);i>0&&(t=ky(n,N(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||iy(t,e))&&c.push(e)}}),dv(n,o.deletions,e=>{e instanceof Qx&&a.some(t=>t===n.doc||iy(t,e))&&!pv(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Zx(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Wy=class extends fm{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=dm(e)?e[0].doc:e instanceof Cv?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new uv;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&gv(i,n,r,a)});let a=Fh(),o=!1;if(this.lastChange>0&&a-this.lastChange0&&!t&&!n){let t=r[r.length-1];t.deletions=hv([t.deletions,e.deleteSet]),t.insertions=hv([t.insertions,i])}else r.push(new Vy(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),dv(e,e.deleteSet,t=>{t instanceof Qx&&this.scope.some(n=>n===e.doc||iy(n,t))&&Jx(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.destroy=this.destroy.bind(this),this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,this.destroy)}addToScope(e){let t=new Set(this.scope);e=dm(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof gb?e.doc!==this.doc:e!==this.doc)&&iv(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Hy(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Hy(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Uy(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Uy(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),this.doc.off(`destroy`,this.destroy),super.destroy()}};function*Gy(e){let t=M(e.restDecoder);for(let n=0;nXy(e,Tv,kv),Yy=(e,t)=>{if(e.constructor===vx){let{client:n,clock:r}=e.id;return new vx(N(n,r+t),e.length-t)}if(e.constructor===nS){let{client:n,clock:r}=e.id;return new nS(N(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Qx(N(r,i+t),null,N(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Xy=(e,t=Dv,n=jv)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(hh(e))),i=r.map(e=>new Ky(e,!0)),a=null,o=new n,s=new qy(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===nS?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)$y(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length0&&(a.struct.constructor===nS?a.struct.length-=t:n=Yy(n,t)),a.struct.mergeWith(n)||($y(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==nS;n=e.next())$y(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&($y(s,a.struct,a.offset),a=null),eb(s),yv(o,hv(r.map(e=>bv(e)))),o.toUint8Array()},Zy=(e,t,n=Dv,r=jv)=>{let i=Wv(t),a=new r,o=new qy(a),s=new n(hh(e)),c=new Ky(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===nS)c.next();else if(e.id.clock+e.length>n)for($y(o,e,_m(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)$y(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return eb(o),yv(a,bv(s)),a.toUint8Array()},Qy=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Rm(e.encoder.restEncoder)}),e.encoder.restEncoder=Fm(),e.written=0)},$y=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Qy(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),j(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},eb=e=>{Qy(e);let t=e.encoder.restEncoder;j(t,e.clientStructs.length);for(let n=0;n{let i=new n(hh(e)),a=new Ky(i,!1),o=new r,s=new qy(o);for(let e=a.curr;e!==null;e=a.next())$y(s,t(e),0);return eb(s),yv(o,bv(i)),o.toUint8Array()},nb=e=>tb(e,eg,Dv,kv),rb=`You must not compute changes after the event-handler fired.`,ib=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=ab(this.currentTarget,this.target)}deletes(e){return pv(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw sh(rb);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=am(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=am(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=am(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw sh(rb);let t=this.target,n=im(),r=im(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},ab=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},ob=()=>{iv(`Invalid access: Add Yjs type to a document before reading data.`)},sb=80,cb=0,lb=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=cb++}},ub=e=>{e.timestamp=cb++},db=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=cb++},fb=(e,t,n)=>{if(e.length>=sb){let r=e.reduce((e,t)=>e.timestamp{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>hm(t-e.index)t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&hm(n.index-i){for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t0&&t===i.index)&&(i.index=_m(t,i.index+n))}},hb=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;tm(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;$v(r._eH,n,t)},gb=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Xv(),this._dEH=Xv(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw ch()}clone(){throw ch()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Zv(this._eH,e)}observeDeep(e){Zv(this._dEH,e)}unobserve(e){Qv(this._eH,e)}unobserveDeep(e){Qv(this._dEH,e)}toJSON(){}},_b=(e,t,n)=>{e.doc??ob(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},vb=e=>{e.doc??ob();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n{let n=[],r=e._start;for(;r!==null;){if(r.countable&&by(r,t)){let e=r.content.getContent();for(let t=0;t{let n=0,r=e._start;for(e.doc??ob();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r{let n=[];return bb(e,(r,i)=>{n.push(t(r,i,e))}),n},Sb=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},Cb=(e,t)=>{e.doc??ob();let n=pb(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Nx(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new yx(new Uint8Array(n))),i.integrate(e,0);break;case Cv:i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new wx(n)),i.integrate(e,0);break;default:if(n instanceof gb)i=new Qx(N(o,wy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Gx(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},Tb=()=>sh(`Length exceeded!`),Eb=(e,t,n,r)=>{if(n>t._length)throw Tb();if(n===0)return t._searchMarker&&mb(t._searchMarker,n,r.length),wb(e,t,null,r);let i=n,a=pb(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return wb(e,t,r,n)},Ob=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=pb(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n0&&s!==null;)s.deleted||(r0)throw Tb();t._searchMarker&&mb(t._searchMarker,i,-a+r)},kb=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},Ab=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Nx([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Nx([r]);break;case Uint8Array:s=new yx(r);break;case Cv:s=new wx(r);break;default:if(r instanceof gb)s=new Gx(r);else throw Error(`Unexpected content type`)}new Qx(N(o,wy(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},jb=(e,t)=>{e.doc??ob();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Mb=e=>{let t={};return e.doc??ob(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Nb=(e,t)=>{e.doc??ob();let n=e._map.get(t);return n!==void 0&&!n.deleted},Pb=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&by(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},Fb=e=>(e.doc??ob(),sv(e._map.entries(),e=>!e[1].deleted)),Ib=class extends ib{},Lb=class e extends gb{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gb?e.clone():e)),t}get length(){return this.doc??ob(),this._length}_callObserver(e,t){super._callObserver(e,t),hb(this,e,new Ib(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):By(this.doc,n=>{Eb(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):By(this.doc,t=>{Db(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):By(this.doc,n=>{Ob(n,this,e,t)})}get(e){return Cb(this,e)}toArray(){return vb(this)}slice(e=0,t=this.length){return _b(this,e,t)}toJSON(){return this.map(e=>e instanceof gb?e.toJSON():e)}map(e){return xb(this,e)}forEach(e){bb(this,e)}[Symbol.iterator](){return Sb(this)}_write(e){e.writeTypeRef(Rx)}},Rb=e=>new Lb,zb=class extends ib{constructor(e,t,n){super(e,t),this.keysChanged=n}},Bb=class e extends gb{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof gb?e.clone():e)}),t}_callObserver(e,t){hb(this,e,new zb(this,e,t))}toJSON(){this.doc??ob();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof gb?r.toJSON():r}}),e}get size(){return[...Fb(this)].length}keys(){return cv(Fb(this),e=>e[0])}values(){return cv(Fb(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return cv(Fb(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ob(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):By(this.doc,t=>{kb(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):By(this.doc,n=>{Ab(n,this,e,t)}),t}get(e){return jb(this,e)}has(e){return Nb(this,e)}clear(){this.doc===null?this._prelimContent.clear():By(this.doc,e=>{this.forEach(function(t,n,r){kb(e,r,n)})})}_write(e){e.writeTypeRef(zx)}},Vb=e=>new Bb,Hb=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Xh(e,t),Ub=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&lh(),this.right.content.constructor){case Ox:this.right.deleted||qb(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Wb=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Ox:t.right.deleted||qb(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n{let i=new Map,a=r?pb(t,n):null;return a?Wb(e,new Ub(a.p.left,a.p,a.index,i),n-a.index):Wb(e,new Ub(null,t._start,0,i),n)},Kb=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Ox&&Hb(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Qx(N(a,wy(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new Ox(o,r));l.integrate(e,0),n.right=l,n.forward()})},qb=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Jb=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Ox&&Hb(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Yb=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Hb(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Qx(N(a,wy(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new Ox(s,c)),n.right.integrate(e,0),n.forward()}}return o},Xb=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Jb(n,i);let s=Yb(e,t,n,i),c=r.constructor===String?new Fx(r):r instanceof gb?new Gx(r):new Ex(r),{left:l,right:u,index:d}=n;t._searchMarker&&mb(t._searchMarker,n.index,c.getLength()),u=new Qx(N(o,wy(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Kb(e,t,n,s)},Zb=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Jb(n,i);let s=Yb(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Ox));){if(!n.right.deleted)switch(n.right.content.constructor){case Ox:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Hb(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r0){let i=``;for(;r>0;r--)i+=` -`;n.right=new Qx(N(o,wy(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Fx(i)),n.right.integrate(e,0),n.forward()}Kb(e,t,n,s)},Qb=(e,t,n,r,i)=>{let a=t,o=$p();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===Ox){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case Ox:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&qb(i,n);break}}}t=t.right}return s},$b=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Ox){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},ex=e=>{let t=0;return By(e.doc,n=>{let r=e._start,i=e._start,a=$p(),o=em(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Ox:qb(o,i.content);break;default:t+=Qb(n,r,i,a,o),a=em(o),r=i}i=i.right}}),t},tx=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&My(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Ox&&e.constructor!==vx&&t.add(e.parent)})}By(n,n=>{dv(e,e.deleteSet,e=>{if(e instanceof vx||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===Ox?t.add(r):$b(n,e)});for(let e of t)ex(e)})},nx=(e,t,n)=>{let r=n,i=em(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Gx:case Ex:case Fx:n{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];By(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},qh(o)||(e.attributes=Uh({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Gx:case Ex:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case Fx:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case Ox:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Hb(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Hb(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Hb(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Hb(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),qb(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},ix=class e extends gb{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ob(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new rx(this,e,t);hb(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ob();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Fx&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):By(this.doc,n=>{let r=new Ub(null,this._start,0,new Map);for(let i=0;i0)&&Xb(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&nx(n,r,a.delete):Zb(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??ob();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(by(s,e)||t!==void 0&&by(s,t))switch(s.content.constructor){case Fx:{let r=i.get(`ychange`);e!==void 0&&!by(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!by(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Gx:case Ex:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case Ox:by(s,e)&&(c(),qb(i,s.content))}s=s.right}c()};return e||t?By(a,n=>{e&&xy(n,e),t&&xy(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):By(r,r=>{let i=Gb(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Xb(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):By(r,r=>{let i=Gb(r,this,e,!n);Xb(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):By(n,n=>{nx(n,Gb(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):By(r,r=>{let i=Gb(r,this,e,!1);i.right!==null&&Zb(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):By(this.doc,t=>{kb(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):By(this.doc,n=>{Ab(n,this,e,t)})}getAttribute(e){return jb(this,e)}getAttributes(){return Mb(this)}_write(e){e.writeTypeRef(Bx)}},ax=e=>new ix,ox=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ob()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===lx||t.constructor===sx)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},sx=class e extends gb{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gb?e.clone():e)),t}get length(){return this.doc??ob(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ox(this,e)}querySelector(e){e=e.toUpperCase();let t=new ox(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),sm(new ox(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){hb(this,e,new dx(this,t,e))}toString(){return xb(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),bb(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):By(this.doc,n=>{Eb(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)By(this.doc,n=>{let r=e&&e instanceof gb?e._item:e;wb(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw sh(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):By(this.doc,n=>{Ob(n,this,e,t)})}toArray(){return vb(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Cb(this,e)}slice(e=0,t=this.length){return _b(this,e,t)}forEach(e){bb(this,e)}_write(e){e.writeTypeRef(Hx)}},cx=e=>new sx,lx=class e extends sx{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Gh(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof gb?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i0?` `+t.join(` `):``}>${super.toString()}`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):By(this.doc,t=>{kb(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):By(this.doc,n=>{Ab(n,this,e,t)})}getAttribute(e){return jb(this,e)}hasAttribute(e){return Nb(this,e)}getAttributes(e){return e?Pb(this,e):Mb(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return bb(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Vx),e.writeKey(this.nodeName)}},ux=e=>new lx(e.readKey()),dx=class extends ib{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},fx=class e extends Bb{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Ux),e.writeKey(this.hookName)}},px=e=>new fx(e.readKey()),mx=class e extends ix{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.keye.nodeName`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=``;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Wx)}},hx=e=>new mx,gx=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw ch()}mergeWith(e){return!1}write(e,t,n){throw ch()}integrate(e,t){throw ch()}},_x=0,vx=class extends gx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Ty(e.doc.store,this)}write(e,t){e.writeInfo(_x),e.writeLen(this.length-t)}getMissing(e,t){return null}},yx=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},bx=e=>new yx(e.readBuf()),xx=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){gv(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},Sx=e=>new xx(e.readLen()),Cx=(e,t)=>new Cv({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),wx=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(Cx(this.doc.guid,this.opts))}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},Tx=e=>new wx(Cx(e.readString(),e.readAny())),Ex=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},Dx=e=>new Ex(e.readJSON()),Ox=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},kx=e=>new Ox(e.readKey(),e.readJSON()),Ax=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r{let t=e.readLen(),n=[];for(let r=0;r{let t=e.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},Ix=e=>new Fx(e.readString()),Lx=[Rb,Vb,ax,ux,cx,px,hx],Rx=0,zx=1,Bx=2,Vx=3,Hx=4,Ux=5,Wx=6,Gx=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw ch()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Kx=e=>new Gx(Lx[e.readTypeRef()](e)),qx=(e,t)=>{let n=t,r=0,i;do r>0&&(n=N(n.client,n.clock+r)),i=Dy(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Qx);return{item:i,diff:r}},Jx=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Yx=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Qx(N(r,i+n),t,N(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=N(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Xx=(e,t)=>lm(e,e=>pv(e.deletions,t)),Zx=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return ky(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Zx(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=ky(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:ky(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:ky(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||pv(r,d.right.id)||Xx(a.undoStack,d.right.id)||Xx(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=ky(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=N(c,wy(s,c)),h=new Qx(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,Jx(h,!0),h.integrate(e,0),h},Qx=class e extends gx{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=wy(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=wy(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===ey&&this.id.client!==this.parent.client&&this.parent.clock>=wy(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=Ay(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=ky(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===vx||this.right&&this.right.constructor===vx)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===ey){let e=Dy(n,this.parent);this.parent=e.constructor===vx?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Ay(e,e.doc.store,N(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),ty(this.origin,n.origin)){if(n.id.client{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),gv(e.deleteSet,this.id.client,this.id.clock,this.length),Fy(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw lh();this.content.gc(e),t?jy(e,this,new vx(this.id,this.length)):this.content=new xx(this.length)}write(e,t){let n=t>0?N(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=ry(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===ey?(e.writeParentInfo(!1),e.writeLeftID(t)):lh();i!==null&&e.writeString(i)}this.content.write(e,t)}},$x=(e,t)=>eS[t&31](e),eS=[()=>{lh()},Sx,jx,bx,Ix,Dx,kx,Kx,Px,Tx,()=>{lh()}],tS=10,nS=class extends gx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){lh()}write(e,t){e.writeInfo(tS),j(e.restEncoder,this.length-t)}getMissing(e,t){return null}},rS=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},iS=`__ $YJS$ __`;rS[iS]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),rS[iS]=!0;var aS=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},oS=(e,t)=>e>>>t|e<<32-t,sS=e=>oS(e,2)^oS(e,13)^oS(e,22),cS=e=>oS(e,6)^oS(e,11)^oS(e,25),lS=e=>oS(e,7)^oS(e,18)^e>>>3,uS=e=>oS(e,17)^oS(e,19)^e>>>10,dS=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),fS=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),pS=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(fS),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=uS(t[e-2])+t[e-7]+lS(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+cS(o)+(o&s^~o&c)+dS[e]+t[e]>>>0,d=sS(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3=0&&t>>(3-t)*8;return i}},mS=e=>new pS().digest(e),hS=/[\uD800-\uDBFF]/,gS=/[\uDC00-\uDFFF]/,_S=(e,t)=>{let n=0,r=0;for(;n0&&hS.test(e[n-1])&&n--;r+n0&&gS.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}};function vS(e){if(!e||!(e.content instanceof Gx))return null;let t=e.content.type;if(!(t instanceof sx||t instanceof ix||t instanceof fx))throw Error(`Expected a Yjs XML type`);return t}function yS(e){if(e===null)return null;if(!(e.parent instanceof gb))throw Error(`Expected an integrated Yjs parent`);let t=e.parent;if(!(t instanceof sx||t instanceof ix||t instanceof fx))throw Error(`Expected a Yjs XML type`);return t}var bS=(e,t)=>{let n=null,r=null;return e._item===null?r=ry(e):n=N(e._item.id.client,e._item.id.clock),new ay(n,r,t.id)},xS=(e,t,n)=>{if(e===0)return uy(t,0,-1);let r=vS(t._first);for(;r!==null&&t!==r;){if(r instanceof mx){if(r._length>=e)return uy(r,e,-1);if(e-=r._length,r._item!==null&&r._item.next!==null)r=vS(r._item.next);else{do r=yS(r._item),e--;while(r!==t&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==t&&(r=r._item===null?null:vS(r._item.next))}}else{let i=n.get(r),a=i instanceof ce?i.nodeSize:0;if(r._first!==null&&e1)return new ay(r._item===null?null:r._item.id,r._item===null?ry(r):null,null);if(e-=a,r._item!==null&&r._item.next!==null)r=vS(r._item.next);else{if(e===0){if(r=r._item===null?r:yS(r._item),r===null)throw lh();return new ay(r._item===null?null:r._item.id,r._item===null?ry(r):null,null)}do{if(r=yS(r._item),r===null)throw lh();e--}while(r!==t&&r._item?.next===null);r!==t&&(r=vS(r._item?.next))}}}if(r===null)throw lh();if(e===0&&r.constructor!==mx&&r!==t){let e=r._item,t=yS(e);if(e===null||t===null)throw lh();return bS(t,e)}}return uy(t,t._length,-1)},SS=(e,t)=>{if(!e.docChanged)return!1;if(e.doc.childCount!==t.childCount)return!0;for(let n of e.steps)if(n instanceof Et){if(n.from===0&&n.to===t.content.size)return!0;if(n.slice.content.size>0){let e=!1;if(n.slice.content.forEach(t=>{t.isBlock&&(e=!0)}),e)return!0}else if(n.to>n.from){let e=t.resolve(n.from),r=t.resolve(n.to);if(e.depth===0&&r.depth===0&&e.index()!==r.index())return!0}}return!1};function CS(e,t){if(e instanceof mx)return e._length;let n=t.get(e);return n instanceof ce?n.nodeSize:null}function wS(e,t,n){let r=0,i=e._first;for(;i!==null;){let e=vS(i);if(e===t)break;let a=i.deleted;if(i=i.right,a)continue;if(e===null)return null;let o=CS(e,n);if(o===null)return null;r+=o}return r}function TS(e,t,n){let r=0,i=0,a=e._first;for(;i{if(n===null)return!1;let r=my(t,e);return r!==null&&r.type instanceof mx&&t.item!==null&&r.type._item?.deleted===!0},DS=e=>{if(!e.doc)throw Error(`The Yjs fragment must belong to a document`);let t=e._item?`item:${e._item.id.client}:${e._item.id.clock}`:`root:${ry(e)}`;return e.doc.getMap(`__tiptap_position_migrations:${t}`)},OS=new WeakMap,kS=(e,t)=>{let n=t.item??t.type;if(!n)return[];let r;t.item||(r=t.assoc<0?`start`:`end`);let i=OS.get(e);if(!i||i.size!==e.size){let t=new Map;e.forEach(e=>e.transfers.forEach(n=>{let r=t.get(n.source.client)??[];r.push({migration:e,transfer:n}),t.set(n.source.client,r)})),i={size:e.size,clients:t},OS.set(e,i)}let a=(i.clients.get(n.client)??[]).filter(({transfer:e})=>e.source.boundary===r&&e.source.clock<=n.clock&&n.clock!a.some(t=>t.migration!==e.migration&&t.migration.seen.some(([t,n])=>t===e.migration.client&&n>e.migration.clock)))},AS=(e,t,n)=>{let{source:r,target:i}=e.transfer;return i?new ay(i.boundary?N(i.client,i.clock):i.type,i.tname??null,i.boundary?null:N(i.client,i.clock+t.clock-r.clock),i.assoc??n):null},jS=(e,t,n)=>{let r=AS(e[0],t,n);return!r||e.some(e=>{let i=AS(e,t,n);return!i||!hy(r,i)})?null:r},MS=e=>{let t=e.item??e.type;if(!t)return null;let n=e.assoc<0?`start`:`end`;return e.item&&(n=`item`),`${t.client}:${t.clock}:${n}`},NS=(e,t)=>{let n=DS(e),r=new Set,i=t,a=i.item??i.type;for(;a;){let e=MS(i);if(r.has(e))return null;r.add(e);let t=kS(n,i);if(t.length===0)return i;let o=jS(t,a,i.assoc);if(!o)return null;if(MS(o)===e)return o;i=o,a=o.item??o.type}return i},PS=(e,t,n,r)=>{let i=NS(t,n);if(!i)return null;n=i;let a=my(n,e);if(a===null||a.type!==t&&!iy(t,a.type._item))return null;let o=a.type,s=0;if(o.constructor===mx)s=a.index;else if(!o._item?.deleted){let e=TS(o,a.index,r);if(e===null)return null;s=e+1}for(;o!==t&&o._item!==null;){let e=yS(o._item);if(e===null)return null;if(e._item?.deleted){o=e;continue}let t=wS(e,o,r);if(t===null)return null;s+=t+1,o=e}let c=s-1;return ES(e,n,c)?null:c},FS=new Un(`y-sync`),IS=new Un(`y-undo`),LS=new Un(`yjs-cursor`),RS=null;function zS(){let e=RS;RS=null;let t=[];return e?.forEach((e,n)=>{e.forEach((e,r)=>t.push({view:n,key:r,value:e}))}),t}function BS(e=zS(),t=!1){let n=!0;for(;e.length>0;){let{view:r,key:i,value:a}=e[0];try{let e=FS.getState(r.state);e&&e.binding.prosemirrorView!==null&&r.dispatch(r.state.tr.setMeta(i,a))}catch(r){if(!(r instanceof RangeError))throw r;t&&n&&e.shift(),e.length>0&&U_(0,()=>BS(e,!0));return}n=!1,e.shift()}}function VS(e,t,n){RS===null&&(RS=new Map,U_(0,BS));let r=RS.get(e);r||(r=new Map,RS.set(e,r)),r.set(t,n)}var HS=(e,t,n)=>e!==t,US=e=>{let t=document.createElement(`span`);t.classList.add(`ProseMirror-yjs-cursor`),t.setAttribute(`style`,`border-color: ${e.color}`);let n=document.createElement(`div`);n.setAttribute(`style`,`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);let r=document.createTextNode(`⁠`),i=document.createTextNode(`⁠`);return t.insertBefore(r,null),t.insertBefore(n,null),t.insertBefore(i,null),t},WS=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),GS=/^#[0-9a-fA-F]{6}$/,KS=e=>typeof e.name==`string`&&typeof e.color==`string`,qS=(e,t,n,r,i)=>{let a=FS.getState(e);if(a==null||a.doc==null||a.binding==null)return xs.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?xs.create(e.doc,[]):(t.getStates().forEach((t,c)=>{if(n(o.clientID,c,t)&&t&&t.cursor!=null){let n={...t.user};if(n.color==null?n.color=`#ffa500`:GS.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`,!KS(n))return;let l=PS(o,a.type,oy(t.cursor.anchor),a.binding.mapping),u=PS(o,a.type,oy(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=_m(e.doc.content.size-1,0);l=gm(l,t),u=gm(u,t),s.push(vs.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=gm(l,u),o=_m(l,u);s.push(vs.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),xs.create(e.doc,s))},JS=(e,{awarenessStateFilter:t=HS,cursorBuilder:n=US,selectionBuilder:r=WS,getSelection:i=e=>e.selection}={},a=`cursor`)=>new D({key:LS,state:{init(i,a){return qS(a,e,t,n,r)},apply(i,a,o,s){let c=FS.getState(s),l=i.getMeta(LS),u=c&&c.isChangeOrigin;return i.docChanged&&!u&&SS(i,o.doc)?xs.empty:u||l&&l.awarenessUpdated?qS(s,e,t,n,r):i.docChanged?a.map(i.mapping,i.doc):a}},props:{decorations:e=>LS.getState(e)??xs.empty},view:t=>{let n=()=>{t.isDestroyed||VS(t,LS,{awarenessUpdated:!0})},r=t=>{let n=FS.getState(t.state);if(!n||!n.binding)return;let r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=xS(o.anchor,n.type,n.binding.mapping),c=xS(o.head,n.type,n.binding.mapping);r.cursor!=null&&hy(oy(r.cursor.anchor),s)&&hy(oy(r.cursor.head),c)||e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&PS(n.doc,n.type,oy(r.cursor.anchor),n.binding.mapping)!==null&&e.setLocalStateField(a,null)},o=()=>r(t);return e.on(`change`,n),t.dom.addEventListener(`focusin`,o),t.dom.addEventListener(`focusout`,o),{update:r,destroy:()=>{t.dom.removeEventListener(`focusin`,o),t.dom.removeEventListener(`focusout`,o),e.off(`change`,n),e.setLocalStateField(a,null)}}}});function YS(e){let t=FS.getState(e);if(!t)throw Error(`The editor requires ySyncPlugin`);return t}var XS=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)??0)>e.id.clock&&!pv(t.ds,e.id),ZS=(e,t,n)=>{if(!e.has(n)){if(e.sizen.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,Mh(t))}let r=e.get(n);if(!r)throw Error(`At least one snapshot color is required`);return r},QS=(e,t)=>{if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])},$S=e=>{let t=e.type.spec.attrs||{};return Object.keys(e.attrs).some(n=>{let r=t[n];return r==null||!Object.prototype.hasOwnProperty.call(r,`default`)||r.default!==e.attrs[n]})},eC=(e,t,n)=>{let r=0,i=0;for(;in)break;r+=t.nodeSize}if(i>=e.childCount)return null;let a=e.child(i),o=e.resolve(n),s=(e,t)=>{if(o.depth===0){let i=e+(n-r),a=e+1,o=e+t.nodeSize-1;return Math.max(a,Math.min(i,o))}if(o.depth>1){let n=eC(o.node(1),t,o.pos-o.start(1));return n===null?null:e+1+n}return t.isTextblock?e+1+Math.min(o.parentOffset,t.content.size):null},c=(n,r=!1)=>{let a=0;for(let t=0;t<=i;t++)n(e.child(t))&&a++;let o=0,c=-1,l=null,u=0;for(let e=0;ee.type===a.type&&QS(e.attrs,a.attrs),u=a.textContent,d=c(e=>l(e)&&e.textContent===u);if(d!==null)return d;let f=c(e=>e.type===a.type&&e.textContent===u);if(f!==null)return f;if(!a.isTextblock||$S(a)){let e=c(l,!0);if(e!==null)return e}return c(e=>l(e)&&u!==``&&e.textContent!==``&&(u.startsWith(e.textContent)||e.textContent.startsWith(u)),!0)},tC=(e,t,n,r)=>{if(r===null)return!1;let i=e.resolve(n),a=t.resolve(r);if(!i.parent.isTextblock)return!1;if(!a.parent.isTextblock||i.parent.textContent!==a.parent.textContent||i.parentOffset!==0&&a.parentOffset===0)return!0;let o=i.parentOffset===0&&a.parentOffset===0,s=i.parentOffset!==a.parentOffset||i.parent.type!==a.parent.type||!QS(i.parent.attrs,a.parent.attrs);if(o||s){let i=eC(e,t,n);return i!==null&&i!==r}return!1},nC=(e,t,n,r)=>{if(n==null||n<0||n>t.content.size||!(r===null||n>1&&r<=1||tC(t,e,n,r)))return r;let i=eC(t,e,n);return i===null?r:i},rC=(e,t,n,r)=>{if(t!==null&&t.anchor!==null&&t.head!==null){if(t.type===`all`)e.setSelection(new Dn(e.doc));else if(t.type===`node`){let r=PS(n.doc,n.type,t.anchor,n.mapping);r!==null&&e.setSelection(iC(e,r))}else if(t.type===`nodeRange`){let r=aC(e,PS(n.doc,n.type,t.anchor,n.mapping),PS(n.doc,n.type,t.head,n.mapping),t.depth);r!==null&&e.setSelection(r)}else{let i=PS(n.doc,n.type,t.anchor,n.mapping),a=PS(n.doc,n.type,t.head,n.mapping);r!=null&&(NS(n.type,t.anchor)===t.anchor&&(i=nC(e.doc,r,t.absAnchor,i)),NS(n.type,t.head)===t.head&&(a=nC(e.doc,r,t.absHead,a))),i===null&&(i=a),a===null&&(a=i),i!==null&&a!==null&&e.setSelection(T.between(e.doc.resolve(i),e.doc.resolve(a)))}}},iC=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?E.create(e.doc,t):T.near(n)},aC=(e,t,n,r)=>{if(t===null||n===null)return null;let i=Math.min(Math.max(t,0),e.doc.content.size),a=Math.min(Math.max(n,0),e.doc.content.size);try{let t=w.fromJSON(e.doc,{type:`nodeRange`,anchor:i,head:a,depth:r});return t.ranges.length?t:T.near(e.doc.resolve(i))}catch{return T.near(e.doc.resolve(i))}},oC=(e,t)=>{let n=t.selection,r=n.toJSON(),i=typeof r.type==`string`?r.type:`text`;return{type:i,depth:i===`nodeRange`&&`depth`in n&&typeof n.depth==`number`?n.depth:void 0,anchor:xS(t.selection.anchor,e.type,e.mapping),head:xS(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},sC=new WeakMap,cC=(e,t)=>{var n;(t instanceof sx||t instanceof ix||t instanceof fx)&&(e.delete(t),(n=sC.get(e))==null||n.delete(t))},lC=/(.*)(--[a-zA-Z0-9+/=]{8})$/,uC=e=>lC.exec(e)?.[1]??e,dC=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(uC(r),e[r]));return n},fC=e=>{let t=e.doc,n=e._item;if(!t||!n)throw lh();t.transact(e=>{n.delete(e)},FS)},pC=(e,t,n,r,i,a)=>{let o=e.toDelta(r,i,a);try{return o.map(e=>t.text(e.insert,dC(e.attributes,t)))}catch{return fC(e),null}},mC=e=>{var t;let n=(t=e._item)==null||(t=t.right)==null?void 0:t.content,r=n instanceof Gx?n.type:null;if(!(r instanceof ix))return;let i=r._item,a=r.doc;i&&a&&!i.deleted&&i.id.client===a.clientID&&(e.applyDelta([{retain:e.length},...r.toDelta()]),a.transact(e=>{i.delete(e)}))},hC=(e,t,n,r)=>{if(e._item){if(!XS(e._item,t))return r?r(`removed`,e._item.id):{type:`removed`};if(!XS(e._item,n))return r?r(`added`,e._item.id):{type:`added`}}},gC=(e,t,n)=>{e.mapping.set(t,n);let r=sC.get(e.mapping);r===void 0&&(r=new WeakMap,sC.set(e.mapping,r)),r.set(t,n)},_C=(e,t,n,r,i,a)=>{let o=n.mapping.get(e),s=Array.isArray(o)?void 0:o;if(s!==void 0&&sC.get(n.mapping)?.get(e)===s)return s;let c=[],l=e=>{if(e instanceof lx){let o=_C(e,t,n,r,i,a);o!==null&&c.push(o)}else e instanceof mx&&(mC(e),pC(e,t,n,r,i,a)?.forEach(e=>c.push(e)))};r===void 0||i===void 0?e.toArray().forEach(l):yb(e,new gy(i.ds,r.sv)).forEach(l);try{let o=e.getAttributes(r),l=r?hC(e,r,i,a):void 0;l!==void 0&&(o.ychange=l);let u=t.node(e.nodeName,o,c);return s?.eq(u)&&(u=s),gC(n,e,u),u}catch{return fC(e),cC(n.mapping,e),null}},vC=e=>{for(let t=6;tvg(vC(mS(xg(e)))),bC=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=tm(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${yC(e.toJSON())}`:e.type.name]=e.attrs}}),n},xC=(e,t)=>{let n=new mx,r=e.map(e=>({insert:e.text??``,attributes:bC(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},SC=e=>{let t=e.content.content,n=[];for(let e=0;ee instanceof Array?xC(e,t):wC(e,t),wC=(e,t)=>{let n=new lx(e.type.name);for(let t in e.attrs){let r=e.attrs[t];r!==null&&t!==`ychange`&&n.setAttribute(t,r)}return n.insert(0,SC(e).map(e=>CC(e,t))),t.mapping.set(n,e),n},TC=e=>typeof e==`object`&&!!e,EC=(e,t)=>{let n=Object.keys(e).filter(t=>e[t]!==null),r=n.length===Object.keys(t).filter(e=>t[e]!==null).length;for(let i=0;i{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Wh(e.attributes||{}).length===t[n].marks.length&&Object.entries(e.attributes??{}).every(([e,r])=>{let i=uC(e),a=t[n].marks.find(e=>e.type.name===i);return a?EC(r,a.attrs):!1}))},OC=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,kC=(e,t)=>{if(e instanceof lx&&!(t instanceof Array)&&OC(e,t)){let n=SC(t);return e._length===n.length&&EC(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>kC(e,n[t]))}return e instanceof mx&&t instanceof Array&&DC(e,t)},AC=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),jC=(e,t,n)=>{let r=new Map;t.forEach((e,t)=>{r.has(e)||r.set(e,t)});let i=[];if(e.forEach((e,a)=>{let o=n.mapping.get(e),s=o===void 0?void 0:r.get(o);s!==void 0&&AC(o,t[s])&&i.push({yIndex:a,pIndex:s,yChild:e})}),i.length===0)return[];let a=[],o=[];for(let e=0;e>1;i[o[r]].pIndex0?o[t-1]:-1,o[t]=e}let s=[];for(let e=o[o.length-1];e!==-1;e=a[e])s.push(i[e]);return s.reverse()},MC=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof Fx?t+=n.content.str:n.content instanceof Ox&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},NC=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=MC(e),a=t.map(e=>({insert:e.text??``,attributes:Object.assign({},r,bC(e.marks,n))})),{insert:o,remove:s,index:c}=_S(i,a.map(e=>e.insert).join(``));e.delete(c,s),e.insert(c,o),e.applyDelta(a.map(e=>({retain:e.insert.length,attributes:e.attributes})))},PC=(e,t,n,r,i)=>t instanceof mx&&n instanceof Array?(DC(t,n)?r.mapping.set(t,n):NC(t,n,r),!0):t instanceof lx&&!(n instanceof Array)&&OC(t,n)?(kC(t,n)?r.mapping.set(t,n):i(e,t,n,r),!0):!1,FC=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>cC(r.mapping,e)),e.delete(t,n))},IC=(e,t,n,r,i,a)=>{if(r{let u=gm(a-i,s-o);for(let a=0;a{let o=jC(r,n,i);if(o.length<2||!o.some(e=>e.yIndex!==e.pIndex)||o.some(e=>{let t=n[e.pIndex];return!(e.yChild instanceof mx&&t instanceof Array||e.yChild instanceof lx&&!(t instanceof Array))}))return!1;let s=0,c=0;for(let l of o){LC(e,t,n,r,s,l.yIndex,c,l.pIndex,i,a);let o=n[l.pIndex];PC(e,l.yChild,o,i,a),s=l.yIndex+1,c=l.pIndex+1}return LC(e,t,n,r,s,r.length,c,n.length,i,a),!0},zC=(e,t,n)=>{let r=e.toArray(),i=SC(t),a=i.length,o=r.length,s=gm(o,a),c=0,l=0,u=!1;for(;c{if(t instanceof lx&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof lx){let e=t.getAttributes(),r=n.attrs;for(let n in r)r[n]===null?t.removeAttribute(n):e[n]!==r[n]&&n!==`ychange`&&t.setAttribute(n,r[n]);for(let n in e)r[n]===void 0&&t.removeAttribute(n)}let i=SC(n),a=i.length,o=t.toArray(),s=o.length,c=gm(a,s),l=!1;if(e.transact(()=>{l=RC(e,t,i,o,r,BC)},FS),l)return;let u=0,d=0;for(;u{for(;s-u-d>0&&a-u-d>0;){let n=o[u],c=i[u],l=o[s-d-1],f=i[a-d-1];if(n instanceof mx&&c instanceof Array){DC(n,c)||NC(n,c,r),u+=1;continue}let p=n instanceof lx&&OC(n,c),m=l instanceof lx&&OC(l,f);if(p&&m&&n instanceof lx&&l instanceof lx&&!Array.isArray(c)&&!Array.isArray(f)){let e=zC(n,c,r),t=zC(l,f,r);e.foundMappedChild&&!t.foundMappedChild?m=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor0&&(t.slice(u,u+n).forEach(e=>cC(r.mapping,e)),t.delete(u,n)),u+d>=a)return;let c=[];for(let e=u;e{let n=[];if(!e._item)throw Error(`Position tracking requires integrated text`);for(let r=e._start;r;r=r.right)if(!r.deleted&&r.countable){if(!(r.content instanceof Fx))throw Error(`Position tracking requires string text content`);for(let i=0;i{let r=[{current:-1,target:-1}];return e.forEach((e,n)=>{let i=t.get(`${e.client}:${e.clock}`);i!==void 0&&i>r[r.length-1].target&&r.push({current:n,target:i})}),r.push({current:e.length,target:n}),r},UC=(e,t,n,r,i)=>{let a=VC(e),o=new Map;for(let e=0;e0;--n){let r=s[n-1],o=s[n],c=a.slice(r.current+1,o.current),l=t.slice(r.target+1,o.target);(c.some(e=>i.has(`${e.client}:${e.clock}`))||c.map(e=>e.text).join(``)!==l)&&(e.delete(r.current+1,c.length),e.insert(r.current+1,l))}return VC(e,n)},WC=(e,t)=>!e.target||!t.target?e.target===t.target:e.target.client===t.target.client&&e.target.assoc===t.target.assoc&&e.target.boundary===t.target.boundary&&e.target.tname===t.target.tname&&e.target.clock+e.source.length===t.target.clock&&ty(e.target.type,t.target.type),GC=e=>{let t=[];return e.forEach(e=>{let n=t[t.length-1];n&&n.source.client===e.source.client&&n.source.boundary===e.source.boundary&&n.source.clock+n.source.length===e.source.clock&&WC(n,e)?n.source.length+=e.source.length:t.push({...e,source:{...e.source}})}),t},KC=(e,t)=>{let n=e.doc;if(!n||t.length===0)return;let r=wy(n.store,n.clientID);e.set(`${n.clientID}:${r}`,{version:1,client:n.clientID,clock:r,seen:[...Wv(Jv(n))],transfers:GC(t)})},qC=(e,t)=>{let n=new Map;e.forEach(e=>{let t=`${e.type.client}:${e.type.clock}`,r=n.get(t)??[];r.push(e),n.set(t,r)});let r=[];return n.forEach(e=>{let n=e[0],i=e[e.length-1],a=n.position===null?void 0:t.get(n.position),o=i.position===null?void 0:t.get(i.position);a&&ty(n.type,a.type)||r.push({source:{...n.type,length:1,boundary:`start`},target:a?{...a,assoc:0}:null}),o&&ty(i.type,o.type)||r.push({source:{...n.type,length:1,boundary:`end`},target:o?{...o,assoc:-1}:null})}),r},JC=(e,t,n,r)=>{let i=[];e.forEach(e=>{let n=e.position===null?null:t.get(e.position)??null;n&&ty(e.id,n)||i.push({source:{...e.id,length:1},target:n})});let a=[...e,...r];for(let e of[`start`,`end`]){let r=e===`start`?t:n;a.forEach(t=>{let n=e===`start`?t.position:t.end,a=n===null?null:r.get(n)??null;a&&ty(t.id,a)||i.push({source:{...t.id,length:1,boundary:e},target:a?{client:a.client,clock:a.clock,type:null,boundary:e}:null})})}return i},YC=(e,t,n,r,i,a)=>{let o=e.get(t);if(!(o instanceof lx)||!o._item)throw Error(`Position migration requires synchronized elements`);let s=i.get(`${o._item.id.client}:${o._item.id.clock}`);if(s&&s.position!==r&&(cC(a.mapping,o),e.delete(t,1),o=CC(n,a),e.insert(t,[o])),!(o instanceof lx)||!o._item)throw Error(`Position migration requires integrated elements`);return o},XC=(e,t,n,r)=>{let i=new Map(t.characters.map(e=>[e.position,e])),a=new Set(t.characters.map(e=>`${e.client}:${e.clock}`)),o=new Map,s=new Map(t.nodes.map(e=>[`${e.id.client}:${e.id.clock}`,e])),c=new Map,l=new Map,u=(e,t,r)=>{let d=e.toArray(),f=r;SC(t).forEach((t,r)=>{let p=d[r];if(Array.isArray(t)){if(!(p instanceof mx)||!p._item)throw Error(`Position migration requires integrated text`);let e=t.map(e=>e.text??``).join(``),r=UC(p,e,f,i,a),s=p._item.id;r.forEach(e=>o.set(e.position,{client:e.client,clock:e.clock,type:s})),NC(p,t,n),f+=e.length;return}let m=YC(e,r,t,f,s,n),h=m._item.id,g={client:h.client,clock:h.clock,type:e._item?.id??null,...e._item?{}:{tname:ry(e)}};c.set(f,g),l.set(f+t.nodeSize-1,g),t.isLeaf||u(m,t,f+1),f+=t.nodeSize})};u(e,t.doc,0);let d=[];t.characters.forEach(e=>{let t=e.position===null?null:o.get(e.position)??null;t&&ty(e,t)&&ty(e.type,t.type)||d.push({source:{client:e.client,clock:e.clock,length:1},target:t})}),d.push(...qC(t.characters,o)),d.push(...JC(t.nodes,c,l,t.emptyTexts)),KC(r,d)},ZC=(e,t)=>{let n=e.doc.content,r=0,i=0;for(;rr&&o>r&&n.child(a-1)===t.child(o-1);)s+=n.child(a-1).nodeSize,a--,o--;if(r===a&&r===o)return e;let c=new p(t.cut(i,t.size-s),0,0),l=en(e.doc,i,n.size-s,c);return l!==null&&l.apply(e.doc).doc?.content.eq(t)?e.step(l):e.replace(0,n.size,new p(t,0,0))},QC=class{constructor(e,t=new Map){if(this.prosemirrorView=null,this.mux=aS(),this.isOMark=new Map,this.beforeTransactionSelection=null,this._domSelectionInView=null,this.syncedDoc=null,this.type=e,this.mapping=t,this._observeFunction=this._typeChanged.bind(this),e.doc===null)throw Error(`The Yjs fragment must belong to a document`);this.doc=e.doc,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=oC(this,this.view.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null}}get view(){if(!this.prosemirrorView)throw Error(`The binding has no editor view`);return this.prosemirrorView}get _tr(){return this.view.state.tr.setMeta(`addToHistory`,!1)}_isLocalCursorInView(){return this.view.hasFocus()?(ig&&this._domSelectionInView===null&&(U_(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.view.root,t=`getSelection`in e&&typeof e.getSelection==`function`?e.getSelection():this.view.dom.ownerDocument.getSelection();if(t==null||t.anchorNode==null||t.focusNode==null)return!1;let n=this.view.dom.ownerDocument.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);let r=n.getBoundingClientRect(),i=I_.documentElement;return r.bottom>=0&&r.right>=0&&r.left<=(window.innerWidth||i.clientWidth||0)&&r.top<=(window.innerHeight||i.clientHeight||0)}renderSnapshot(e,t){t||=_y(_v(),new Map),this.view.dispatch(this._tr.setMeta(FS,{snapshot:e,prevSnapshot:t}))}createDocumentTransaction(){let e=this.type.toArray().map(e=>{if(!(e instanceof lx))throw ch();return _C(e,this.view.state.schema,this)}).filter(e=>e!==null);return this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(e),0,0))}unrenderSnapshot(){this.mapping.clear(),sC.delete(this.mapping),this.mux(()=>{let e=this.createDocumentTransaction();e.setMeta(FS,{snapshot:null,prevSnapshot:null}),this.view.dispatch(e)})}_forceRerender(){this.mapping.clear(),sC.delete(this.mapping),this.mux(()=>{let e=this.beforeTransactionSelection===null?this.view.state.selection:null,t=this.createDocumentTransaction();if(e){let n=gm(_m(e.anchor,0),t.doc.content.size),r=gm(_m(e.head,0),t.doc.content.size);t.setSelection(T.create(t.doc,n,r))}this.view.dispatch(t.setMeta(FS,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=yy(this.doc),e instanceof Uint8Array||t instanceof Uint8Array){if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array))throw lh();if(r=new Cv({gc:!1}),Rv(r,t),t=yy(r),Rv(r,e),e=yy(r),i._item===null){let e=Array.from(this.doc.share.keys()).find(e=>Object.is(this.doc.share.get(e),i));i=r.getXmlFragment(e)}else{let e=r.store.clients.get(i._item.id.client)??[],t=e[Ey(e,i._item.id.clock)];if(!(t instanceof Qx&&t.content instanceof Gx&&t.content.type instanceof sx))throw lh();i=t.content.type}}let a=e,o=t??vy;this.mapping.clear(),sC.delete(this.mapping),this.mux(()=>{r.transact(e=>{let t=n.permanentUserData;t&&t.dss.forEach(t=>{dv(e,t,e=>{})});let r=(e,r)=>{let i=t?e===`added`?t.getUserByClientId(r.client):t.getUserByDeletedId(r):null;return{user:i,type:e,color:ZS(n.colorMapping,n.colors,i)}},c=yb(i,new gy(o.ds,a.sv)).map(e=>!(e instanceof lx)||!e._item?null:!e._item.deleted||XS(e._item,a)||XS(e._item,o)?_C(e,this.view.state.schema,{mapping:new Map,isOMark:new Map},a,o,r):null).filter(e=>e!==null),l=this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(c),0,0));this.view.dispatch(l.setMeta(FS,{isChangeOrigin:!0}))},FS)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=YS(this.view.state);if(e.length===0||n.snapshot!=null||n.prevSnapshot!=null){this.renderSnapshot(n.snapshot,n.prevSnapshot);return}let r=t.origin instanceof Wy,i=r?t.origin.currStackItem?.meta.get(this):void 0,a=i||this.beforeTransactionSelection,o=i?void 0:this.view.state.doc;this.mux(()=>{let e=(e,t)=>cC(this.mapping,t);dv(t,t.deleteSet,e=>{e instanceof Qx&&e.content instanceof Gx&&cC(this.mapping,e.content.type)}),t.changed.forEach(e),t.changedParentTypes.forEach(e);let n=this.type.toArray().map(e=>{if(!(e instanceof lx))throw ch();return _C(e,this.view.state.schema,this)}).filter(e=>e!==null),i=ZC(this._tr,s.from(n));rC(i,a,this,o),i=i.setMeta(FS,{isChangeOrigin:!0,isUndoRedoOperation:r}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.view.dispatch(i)})}_prosemirrorChanged(e,t=null){let n=YS(this.view.state);n.snapshot==null&&n.prevSnapshot==null&&this.doc.transact(()=>{BC(this.doc,this.type,e,this),t?.doc===e&&XC(this.type,t,this,DS(this.type)),this.syncedDoc=e,this.beforeTransactionSelection=oC(this,this.view.state)},FS)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on(`beforeAllTransactions`,this.beforeAllTransactions),this.doc.on(`afterAllTransactions`,this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off(`beforeAllTransactions`,this.beforeAllTransactions),this.doc.off(`afterAllTransactions`,this.afterAllTransactions))}},$C=(e,t)=>{let n=[],r=[],i=[];if(e.length===0)return{characters:n,nodes:r,emptyTexts:i};let a=(e,t,o)=>{let s=e.toArray(),c=SC(t),l=o;t.content.size===0&&s.forEach(e=>{e instanceof mx&&e._item&&i.push({id:e._item.id,position:o-1,end:o})}),c.forEach((e,t)=>{let i=s[t];if(!Array.isArray(e)){if(!(i instanceof lx)||!i._item)throw Error(`Position tracking requires synchronized editor content`);r.push({id:i._item.id,position:l,end:l+e.nodeSize-1}),e.isLeaf||a(i,e,l+1),l+=e.nodeSize;return}if(!(i instanceof mx))throw Error(`Position tracking requires synchronized editor text`);let o=VC(i,l);n.push(...o),l+=o.length})};return a(e,t,0),{characters:n,nodes:r,emptyTexts:i}},ew=(e,t,n,r)=>{let i=e.toJSON();if(i.stepType!==`replace`&&i.stepType!==`replaceAround`||r!==i.from&&r!==i.to-1)return!1;let a=t.nodeAt(i.from),o=n.nodeAt(i.from);return!a||!o||a.nodeSize!==i.to-i.from?!1:tw(a,o)},tw=(e,t)=>e.type===t.type&&e.content.eq(t.content)&&!e.sameMarkup(t),nw=(e,t)=>{let n=e.toJSON(),r=n.slice??{content:[]};if(n.stepType!==`replace`||r.openStart>0||r.openEnd>0)return!1;let i=t.resolve(n.from),a=t.resolve(n.to);return r.content.every(e=>e.type===`text`)&&i.parent.isTextblock&&i.sameParent(a)},rw=e=>{let t=new Map;return e.descendants((e,n)=>{let r=t.get(e)??[];r.push(n),t.set(e,r)}),t},iw=(e,t,n,r)=>{if(r[n].get(e)?.length!==1)return null;for(let i=n+1;i{let i=n[t].resolve(e),a=[],o=n[t].nodeAt(e);o&&!o.isText&&a.push({node:o,offset:0});for(let t=i.depth;t>0;--t)a.push({node:i.node(t),offset:e-i.before(t)});for(let e of a){let n=iw(e.node,e.offset,t,r);if(n)return n}return null},ow=(e,t,n,r)=>{for(let i=0;i{let r=n?.doc===e.before&&n.doc!==t.syncedDoc?n:null;if(!e.docChanged||!t.prosemirrorView||!r&&e.steps.every((t,n)=>nw(t,e.docs[n])))return r;let i=r??$C(t.type,e.before),a=[...e.docs,e.doc],o=a.map(rw),s=i.characters.map(t=>({...t,position:t.position===null?null:ow(t.position,e,a,o)})),c=t=>({...t,position:t.position===null?null:ow(t.position,e,a,o),end:t.end===null?null:ow(t.end,e,a,o)});return{doc:e.doc,characters:s,nodes:i.nodes.map(c),emptyTexts:i.emptyTexts.map(c)}},cw=[{light:`#ecd44433`,dark:`#ecd444`}],lw=(e,{colors:t=cw,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new QC(e,a);return new D({props:{editable:e=>{let t=YS(e);return t.snapshot==null&&t.prevSnapshot==null}},key:FS,state:{init:(i,a)=>({type:e,doc:s.doc,binding:s,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:r,positionMigration:null}),apply:(e,t)=>{let n=e.getMeta(FS);return n!==void 0&&(t=Object.assign({},t,n)),e.docChanged&&(t.addToHistory=e.getMeta(`addToHistory`)!==!1),t.isChangeOrigin=n!==void 0&&!!n.isChangeOrigin,t.isUndoRedoOperation=n!==void 0&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,t={...t,positionMigration:t.isChangeOrigin||t.snapshot||t.prevSnapshot||n?.snapshot!==void 0||n?.prevSnapshot!==void 0?null:sw(e,s,t.positionMigration??null)},s.prosemirrorView===null||n===void 0||n.snapshot==null&&n.prevSnapshot==null||U_(0,()=>{s.prosemirrorView!=null&&(n.restore==null?s._renderSnapshot(n.snapshot,n.prevSnapshot,t):(s._renderSnapshot(n.snapshot,n.snapshot,t),s.mux(()=>{let e=s.prosemirrorView;e&&(e.dispatch(s._tr.setMeta(FS,{restore:!1,snapshot:null,prevSnapshot:null,isChangeOrigin:!0})),s._prosemirrorChanged(e.state.doc))})))}),t}},view:e=>(s.initView(e),a??s._forceRerender(),i(),{update:()=>{let t=YS(e.state);if(t.snapshot==null&&t.prevSnapshot==null){let n=e.state.doc.type.createAndFill();if(!n)throw Error(`The schema cannot create an empty document`);if(o||e.state.doc.content.findDiffStart(n.content)!==null){if(o=!0,t.addToHistory===!1&&!t.isChangeOrigin){let t=IS.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}s.mux(()=>{t.doc.transact(n=>{n.meta.set(`addToHistory`,t.addToHistory),s._prosemirrorChanged(e.state.doc,t.positionMigration??null)},FS)})}}},destroy:()=>{s.destroy()}})})};function uw(e){let t=IS.getState(e);if(!t)throw Error(`The editor requires yUndoPlugin`);return t}var dw=e=>{let t=new Map,n=e=>{e.toArray().forEach(r=>{if(r instanceof lx){let i=r._item.id;t.set(`${i.client}:${i.clock}`,{client:i.client,clock:i.clock,type:e._item?.id??null,...e._item?{}:{tname:ry(e)}}),n(r);return}if(!(r instanceof mx)||!r._item)return;let i=r._item.id;VC(r).forEach(e=>{t.set(`${e.client}:${e.clock}`,{client:e.client,clock:e.clock,type:i})})})};return n(e),t},fw=(e,t)=>{let n=e.doc;if(!n)return;let r=dw(e),i=new Map,a=new Map,o=(e,t)=>{let n=`${e.client}:${e.clock}`,r=`${t.client}:${t.clock}`;i.set(n,e),i.set(r,t);let o=a.get(n)??new Set,s=a.get(r)??new Set;o.add(r),s.add(n),a.set(n,o),a.set(r,s)};t.forEach(e=>e.transfers.forEach(({source:e,target:t})=>{if(t&&!e.boundary)for(let n=0;ne.forEach(e=>{if(e instanceof Qx&&e.redone&&(e.content instanceof Fx||e.content instanceof Gx))for(let t=0;t{if(c.has(t))return;let o=[t],l=[],u=[];for(;o.length>0;){let e=o.pop();if(c.has(e))continue;c.add(e),l.push(e);let t=r.get(e);t&&u.push(t),o.push(...a.get(e)??[])}u.length===1&&l.forEach(e=>{if(r.has(e))return;let t=i.get(e);s.push({source:{client:t.client,clock:t.clock,length:1},target:u[0]});let a=Dy(n.store,t);if(a.content instanceof Gx&&a.content.type instanceof lx)for(let e of[`start`,`end`])s.push({source:{client:t.client,clock:t.clock,length:1,boundary:e},target:{client:u[0].client,clock:u[0].clock,type:null,boundary:e}})})}),KC(t,s)},pw=(e,t,n)=>{let r=DS(e);if(r.size===0)return t[n]();let i=n===`undo`?`undoing`:`redoing`,a=null,o=({stackItem:e})=>{a=e};t.on(`stack-item-popped`,o);try{t.doc.transact(()=>{t[n](),t[i]=!0,t.currStackItem=a,a&&fw(e,r)},t)}finally{t.off(`stack-item-popped`,o),t[i]=!1,t.currStackItem=null}return a},mw=(e,t)=>{let n=YS(e);if(n.snapshot!=null||n.prevSnapshot!=null)return!1;let r=uw(e).undoManager;if(r!=null)return pw(n.type,r,t),!0},hw=e=>mw(e,`undo`),gw=e=>mw(e,`redo`),_w=new Set([`paragraph`]),vw=(e,t)=>!(e instanceof Qx)||!(e.content instanceof Gx)||!(e.content.type instanceof ix||e.content.type instanceof lx&&t.has(e.content.type.nodeName))||e.content.type._length===0,yw=({protectedNodes:e=_w,trackedOrigins:t=[],undoManager:n=null}={})=>new D({key:IS,state:{init:(r,i)=>{let a=YS(i),o=new Set,s=n;if(!s){let n=new Set(a.doc._observers.get(`destroy`));s=new Wy(a.type,{trackedOrigins:new Set([FS,...t]),deleteFilter:t=>vw(t,e),captureTransaction:e=>e.meta.get(`addToHistory`)!==!1}),(a.doc._observers.get(`destroy`)??new Set).forEach(e=>{n.has(e)||o.add(e)})}return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0,destroyListeners:o}},apply:(e,t,n,r)=>{let i=YS(r).binding;return{...t,prevSel:i?oC(i,n):t.prevSel,hasUndoOps:t.undoManager.undoStack.length>0,hasRedoOps:t.undoManager.redoStack.length>0}}},view:e=>{let t=YS(e.state),{undoManager:n,destroyListeners:r}=uw(e.state);return n.on(`stack-item-added`,({stackItem:r})=>{let i=t.binding;if(i){let t=n.undoing||n.redoing?i.beforeTransactionSelection:uw(e.state).prevSel;r.meta.set(i,t)}}),{destroy:()=>{n.destroy(),r.forEach(e=>n.doc.off(`destroy`,e)),r.clear()}}}});function bw(e,t){let n=t||new sx;return BC(n.doc??{transact:e=>e()},n,e,{mapping:new Map,isOMark:new Map}),n}function xw(e){let t=e.toArray(),n=e=>{let t;if(e instanceof mx)t=e.toDelta().map(e=>{let t={type:`text`,text:e.insert},n=e.attributes;return n&&(t.marks=Object.keys(n).map(e=>{let t=n[e],r={type:uC(e)};return Object.keys(t).length&&(r.attrs=t),r})),t});else if(e instanceof lx){t={type:e.nodeName};let r=e.getAttributes();Object.keys(r).length&&(t.attrs=r);let i=e.toArray();i.length&&(t.content=i.map(n).flat())}else lh();return t};return{type:`doc`,content:t.map(n)}}function Sw(e,t,n){return bw(ce.fromJSON(e,t),n)}function Cw(e){return!!e.getMeta(FS)}function ww(e,t){if(t===null)return 0;let n=Ew(e);return PS(n.doc,n.type,t,n.binding.mapping)||0}function Tw(e,t){let n=Ew(e);return xS(t,n.type,n.binding.mapping)}function Ew(e){let t=FS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs sync plugin`);return t}var Dw=class e extends gd{constructor(e,t){super(e),this.yRelativePosition=t}static fromJSON(t){return new e(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Ow(e,t){return new Dw(e,Tw(t,e))}function kw(e,t,n){let r=e instanceof Dw?e.yRelativePosition:null;if(Cw(t)&&r)return{position:new Dw(ww(n,r),r),mapResult:null};let i=_d(e,t),a=i.position.position;return{position:new Dw(a,r??Tw(n,a)),mapResult:i.mapResult}}function Aw(e){let t=IS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs undo plugin`);return t.undoManager}var jw=Tp.create({name:`collaboration`,priority:1e3,addOptions(){return{document:null,field:`default`,fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name===`undoRedo`)&&console.warn(`[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".`)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>kw(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Ow(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Aw(t).undoStack.length===0?!1:n?hw(t)??!1:!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),Aw(t).redoStack.length===0?!1:n?gw(t)??!1:!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){let e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=yw(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let t=Aw(e.state);t.restore&&=(t.restore(),()=>{});let r=n?n(e):void 0;return{destroy:()=>{let e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on(`afterTransaction`,t.afterTransactionHandler),t._observers=n},r?.destroy&&r.destroy()}}},[lw(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,new D({filterTransaction:(e,t)=>(e.getMeta(`inputRule`)&&Aw(t).stopCapturing(),!0)}),this.editor.options.enableContentCheck&&new D({key:new Un(`filterInvalidContent`),filterTransaction:t=>{if(!Cw(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(t){return this.storage.isDisabled=!0,this.editor.emit(`contentError`,{error:t,editor:this.editor,disableCollaboration:()=>{var t;(t=e.doc)==null||t.destroy()}}),!0}}})].filter(e=>e!==!1)}}),Mw=e=>Array.from(e.entries()).map(([e,t])=>t&&t.user?{clientId:e,...t.user}:{clientId:e}),Nw=()=>null,Pw=e=>Pf(e)&&/^#[0-9a-fA-F]{6}$/.test(e),Fw=e=>({...e,color:Pw(e.color)?e.color:`transparent`}),Iw=Tp.create({name:`collaborationCaret`,priority:999,addOptions(){return{provider:null,user:{name:null,color:null},render:e=>{let t=document.createElement(`span`),{color:n}=Fw(e);t.classList.add(`collaboration-carets__caret`),t.style.borderColor=n;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.style.backgroundColor=n,r.insertBefore(document.createTextNode(e.name),null),t.insertBefore(r,null),t},selectionRender:e=>Pw(e.color)?WS({name:e.name,color:e.color}):{},onUpdate:Nw}},onCreate(){if(this.options.onUpdate!==Nw&&console.warn('[tiptap warn]: DEPRECATED: The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'),!this.options.provider)throw Error(`The "provider" option is required for the CollaborationCaret extension`)},addStorage(){return{users:[]}},addCommands(){return{updateUser:e=>()=>(this.options.provider.awareness.setLocalStateField(`user`,e),!0),user:e=>({editor:t})=>(console.warn(`[tiptap warn]: DEPRECATED: The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret`),t.commands.updateUser(e))}},addProseMirrorPlugins(){let{provider:e}=this.options,t=this.storage,n=this.options.user;return[new D({key:new Un(`collaborationCaretAwarenessListener`),view:()=>{let r=()=>{t.users=Mw(e.awareness.states)};return e.awareness.setLocalStateField(`user`,n),t.users=Mw(e.awareness.states),e.awareness.on(`update`,r),{destroy:()=>{e.awareness.off(`update`,r),t.users=[]}}}}),JS(e.awareness,{cursorBuilder:e=>this.options.render(Fw(e)),selectionBuilder:e=>this.options.selectionRender(Fw(e))})]}});function Lw(e={}){return new D({view(t){return new Rw(t,e)}})}var Rw=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.lastDragEvent=null,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.setCursor(null),this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){if(this.cursorPos!=null&&t.doc!=e.state.doc){if(this.lastDragEvent){let e=this.computeTarget(this.lastDragEvent);e==this.cursorPos?this.updateOverlay():this.setCursor(e)}else this.updateOverlay()}}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}computeTarget(e){let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(!t||i)return null;let a=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let e=$t(this.editorView.state.doc,a,this.editorView.dragging.slice);e!=null&&(a=e)}return a}dragover(e){if(!this.editorView.editable)return;this.lastDragEvent=e;let t=this.computeTarget(e);t!=null&&(this.setCursor(t),this.scheduleRemoval(5e3))}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},zw=class e extends w{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):w.near(r)}content(){return p.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new Bw(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!Hw(e)||!Uw(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!E.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};zw.prototype.visible=!1,zw.findFrom=zw.findGapCursorFrom,w.jsonID(`gapcursor`,zw);var Bw=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return zw.valid(t)?new zw(t):w.near(t)}};function Vw(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function Hw(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0}else for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||Vw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Uw(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0}else for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||Vw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Ww(){return new D({props:{decorations:Yw,createSelectionBetween(e,t,n){return t.pos==n.pos&&zw.valid(n)?new zw(n):null},handleClick:qw,handleKeyDown:Gw,handleDOMEvents:{beforeinput:Jw}}})}var Gw=Sc({ArrowLeft:Kw(`horiz`,-1),ArrowRight:Kw(`horiz`,1),ArrowUp:Kw(`vert`,-1),ArrowDown:Kw(`vert`,1)});function Kw(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof T){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=zw.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new zw(c))),!0):!1}}function qw(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!zw.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&E.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new zw(r))),!0)}function Jw(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof zw))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=s.empty;for(let e=r.length-1;e>=0;e--)i=s.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new p(i,0,0));return a.setSelection(T.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function Yw(e){if(!(e.selection instanceof zw))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,xs.create(e.doc,[vs.widget(e.selection.head,t,{key:`gapcursor`})])}Tp.create({name:`characterCount`,addOptions(){return{limit:null,autoTrim:!0,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new D({key:new Un(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit,a=this.options.autoTrim;if(i==null||i===0||a===!1){e=!0;return}let o=this.storage.characters({node:r.doc});if(o>i){let t=o-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var Xw=Tp.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[Lw(this.options)]}});Tp.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new D({key:new Un(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return xs.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(vs.node(t,t+e.nodeSize,{class:this.options.className}))}),xs.create(e,a)}}})]}});var Zw=Tp.create({name:`gapCursor`,addProseMirrorPlugins(){return[Ww()]},extendNodeSchema(e){return{allowGapCursor:Nu(k(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),Qw=`placeholder`,$w=new Un(`tiptap__placeholder`);function eT(e){let{editor:t,placeholder:n,dataAttribute:r,pos:i,node:a,isEmptyDoc:o,hasAnchor:s,classes:{emptyNode:c,emptyEditor:l}}=e,u=[c];return o&&u.push(l),vs.node(i,i+a.nodeSize,{class:u.join(` `),[r]:typeof n==`function`?n({editor:t,node:a,pos:i,hasAnchor:s}):n})}function tT(e,t){return typeof e==`function`?e(t):e}function nT({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:a,to:o}){let{anchor:s}=i,c=[],l=e.isEmpty;return r.nodesBetween(a,o,(r,i)=>{let a=s>=i&&s<=i+r.nodeSize,o=!r.isLeaf&&fd(r);return r.type.isTextblock&&(a||!t.showOnlyCurrent)&&o&&c.push(eT({editor:e,isEmptyDoc:l,dataAttribute:n,hasAnchor:a,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:tT(t.emptyNodeClass,{editor:e,node:r,pos:i,hasAnchor:a})},node:r,pos:i})),t.includeChildren}),c}function rT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}){if(!e.isEditable&&t.showOnlyWhenEditable)return null;let{anchor:a}=i,o=[],s=e.isEmpty;if(t.showOnlyCurrent&&!t.includeChildren){let i=r.resolve(a),c=i.depth>0?i.node(1):i.nodeAfter,l=i.depth>0?i.before(1):a;if(c&&c.type.isTextblock&&fd(c)){let r=a>=l&&a<=l+c.nodeSize;o.push(eT({editor:e,isEmptyDoc:s,dataAttribute:n,hasAnchor:r,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:tT(t.emptyNodeClass,{editor:e,node:c,pos:l,hasAnchor:r})},node:c,pos:l}))}}else o.push(...nT({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:0,to:r.content.size}));return xs.create(r,o)}function iT(e,t){let n=e.resolve(t);if(n.depth===0){let e=n.nodeAfter??n.nodeBefore;if(!e)return{from:t,to:t};let r=n.nodeAfter?t:t-e.nodeSize;return{from:r,to:r+e.nodeSize}}let r=n.before(1);return{from:r,to:r+n.node(1).nodeSize}}function aT(e,t){return{from:Math.max(0,t.from-1),to:Math.min(e.content.size,t.to-1)}}function oT(e,t,n){let r=[];return e.forEach((e,i)=>{let a=i,o=a+e.nodeSize,s=a+1,c=o+1;st&&r.push({from:a,to:o})}),r}function sT(e){if(e.length===0)return[];let t=[...e].sort((e,t)=>e.from-t.from),n=[{...t[0]}];for(let e=1;et.from?n.push(aT(e,iT(e,Math.min(t.to,e.content.size+1)-1))):t.frome.from>=t&&e.to<=c);l.length&&(s=s.remove(l));let u=nT({editor:n,options:r,dataAttribute:i,doc:a,selection:o,from:t,to:c});u.length&&(s=s.add(a,u))}return s}function fT({editor:e,options:t,dataAttribute:n}){return{init(r,i){return rT({editor:e,options:t,dataAttribute:n,doc:i.doc,selection:i.selection})??xs.empty},apply(r,i,a,o){return!r.docChanged&&!r.selectionSet?i:dT({decorations:i.map(r.mapping,r.doc),ranges:lT(r,a,o),editor:e,options:t,dataAttribute:n,doc:o.doc,selection:o.selection})}}}function pT(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}function mT({editor:e,options:t}){let n=t.dataAttribute?`data-${pT(t.dataAttribute)}`:`data-${Qw}`,r=t.showOnlyCurrent&&!t.includeChildren;return new D({key:$w,...r?{}:{state:fT({editor:e,options:t,dataAttribute:n})},props:{decorations:r?({doc:r,selection:i})=>rT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}):n=>t.showOnlyWhenEditable&&!e.isEditable?xs.empty:$w.getState(n)??xs.empty}})}var hT=Tp.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:Qw,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[mT({editor:this.editor,options:this.options})]}});function gT(e,t){return!e.selection.empty&&!pd(e.selection)&&t.isEditable}function _T(e,t){return gT(e,t)&&!t.isFocused&&!t.view.dragging}function vT(){var e;(e=window.getSelection())==null||e.removeAllRanges()}function yT(e){e.focus()}Tp.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new D({key:new Un(`selection`),props:{decorations(n){return _T(n,e)?xs.create(n.doc,[vs.inline(n.selection.from,n.selection.to,{class:t.className})]):null},handleDOMEvents:{blur(t){return gT(t.state,e)&&vT(),!1},focus(t){return gT(t.state,e)&&requestAnimationFrame(()=>{!e.isDestroyed&&t.hasFocus()&&yT(t)}),!1}}}})]}});function bT({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var xT=Tp.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new Un(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new D({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!bT({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!bT({node:r,types:n})}}})]}}),ST=Tp.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>Kc(e,t),redo:()=>({state:e,dispatch:t})=>qc(e,t)}},addProseMirrorPlugins(){return[Wc(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),CT=new WeakSet,wT=new WeakSet;function TT(e){let t=e;return CT.add(t),t}function ET(e){return Array.isArray(e)&&CT.has(e)}function DT(e){return e.flatMap(e=>e==null?[]:Array.isArray(e)&&wT.has(e)&&!ET(e)?DT(e):[e])}function OT(e,t){if(e===`slot`)return 0;if(e instanceof Function){let n=e(t);return Array.isArray(n)&&!ET(n)&&!wT.has(n)?TT(n):n}let{children:n,...r}=t??{};if(e===`svg`)throw Error(`SVG elements are not supported in the JSX syntax, use the array syntax instead`);if(Array.isArray(n)){if(ET(n))return TT([e,r,n]);if(n.length===0)return TT([e,r]);let t=DT(n);return t.length===0?TT([e,r]):TT([e,r,...t])}return TT(n==null?[e,r]:[e,r,n])}var kT=(e,t)=>OT(e,t),AT=(e,t)=>{let{state:n}=e,{selection:r}=n;if(!r.empty)return!1;let{$from:i}=r;if(i.parentOffset!==0)return!1;let a=i.depth-1;if(a<0)return!1;let o=i.node(a),s=i.index(a);if(s===0)return!1;if(o.type===t)return e.commands.lift(t.name);let c=o.child(s-1);if(c.type!==t||!c.lastChild?.isTextblock)return!1;let l=i.before()-1-1;return e.commands.command(({tr:e,dispatch:t})=>{if(!t)return!0;let n=i.parent.content,r=new p(n,0,0);return e.replace(l,i.after(),r),e.setSelection(T.create(e.doc,l+n.size)),e.scrollIntoView(),t(e),!0})},jT=/^\s*>\s$/,MT=Jp.create({name:`blockquote`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,group:`block`,defining:!0,parseHTML(){return[{tag:`blockquote`}]},renderHTML({HTMLAttributes:e}){return kT(`blockquote`,{...A(this.options.HTMLAttributes,e),children:kT(`slot`,{})})},parseMarkdown:(e,t)=>{let n=t.parseBlockChildren??t.parseChildren;return t.createNode(`blockquote`,void 0,n(e.tokens||[]))},renderMarkdown:(e,t)=>{if(!e.content)return``;let n=[];return e.content.forEach((e,r)=>{let i=(t.renderChild?.call(t,e,r)??t.renderChildren([e])).split(` +`,textSerializers:n={}}=e||{};return Ku(this.state.doc,{blockSeparator:t,textSerializers:{...qu(this.schema),...n}})}get isEmpty(){return dd(this.state.doc)}destroy(){this.destroyed||(this.destroyed=!0,this.emit(`destroy`),this.unmount(),this.removeAllListeners(),this.extensionManager.destroy(),this.extensionManager=null,this.schema=null,this.commandManager=null,this.extensionStorage={})}get isDestroyed(){return this.editorView?.isDestroyed??!0}$node(e,t){return this.$doc?.querySelector(e,t)||null}$nodes(e,t){return this.$doc?.querySelectorAll(e,t)||null}$pos(e){let t=this.state.doc.resolve(e),n=e>0&&t.nodeAfter&&!t.nodeAfter.isText&&t.nodeAfter.isAtom?t.nodeAfter:null;return new Rp(t,this,!1,n)}get $doc(){return this.$pos(0)}};function Vp(e){return new cp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Mu(e.getAttributes,void 0,r);if(i===!1||i===null)return null;let{tr:a}=t,o=r[r.length-1],s=r[0];if(o){let r=s.search(/\S/),c=n.from+s.indexOf(o),l=c+o.length;if($u(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>c).length)return null;ln.from&&a.delete(n.from+r,c);let u=n.from+r+o.length;a.addMark(n.from+r,u,e.type.create(i||{})),a.removeStoredMark(e.type)}},undoable:e.undoable})}function Hp(e){return new cp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=Mu(e.getAttributes,void 0,r)||{},{tr:a}=t,o=n.from,s=n.to,c=e.type.create(i);if(r[1]){let e=o+r[0].lastIndexOf(r[1]);e>s?e=s:s=e+r[1].length;let t=r[0][r[0].length-1];a.insertText(t,o+r[0].length-1),a.replaceWith(e,s,c)}else if(r[0]){let t=e.type.isInline?o:o-1;a.insert(t,e.type.create(i)).delete(a.mapping.map(o),a.mapping.map(s))}a.scrollIntoView()},undoable:e.undoable})}function Up(e){return new cp({find:e.find,handler:({state:t,range:n,match:r})=>{let i=t.doc.resolve(n.from),a=Mu(e.getAttributes,void 0,r)||{};if(!i.node(-1).canReplaceWith(i.index(-1),i.indexAfter(-1),e.type))return null;t.tr.delete(n.from,n.to).setBlockType(n.from,n.from,e.type,a)},undoable:e.undoable})}function Wp(e){return new cp({find:e.find,handler:({state:t,range:n,match:r,chain:i})=>{let a=Mu(e.getAttributes,void 0,r)||{},o=t.tr.delete(n.from,n.to),s=o.doc.resolve(n.from).blockRange(),c=s&&Ft(s,e.type,a);if(!c)return null;if(o.wrap(s,c),e.keepMarks&&e.editor){let{selection:n,storedMarks:r}=t,{splittableMarks:i}=e.editor.extensionManager,a=r||n.$to.parentOffset&&n.$from.marks();if(a){let e=a.filter(e=>i.includes(e.type.name));o.ensureMarks(e)}}if(e.keepAttributes){let t=e.type.name===`bulletList`||e.type.name===`orderedList`?`listItem`:`taskList`;i().updateAttributes(t,a).run()}let l=o.doc.resolve(n.from-1).nodeBefore;l&&l.type===e.type&&qt(o.doc,n.from-1)&&(!e.joinPredicate||e.joinPredicate(r,l))&&o.join(n.from-1)},undoable:e.undoable})}var Gp=e=>`touches`in e,Kp=class{constructor(e){var t;this.directions=[`bottom-left`,`bottom-right`,`top-left`,`top-right`],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:``,wrapper:``,handle:``,resizing:``},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.clientX-this.startX,n=e.clientY-this.startY;this.handleResize(t,n)},this.handleTouchMove=e=>{if(!this.isResizing||!this.activeHandle)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this.startX,r=t.clientY-this.startY;this.handleResize(n,r)},this.handleMouseUp=()=>{if(!this.isResizing)return;let e=this.element.offsetWidth,t=this.element.offsetHeight;this.onCommit(e,t),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp)},this.handleKeyDown=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=e=>{e.key===`Shift`&&(this.isShiftKeyPressed=!1)},this.node=e.node,this.editor=e.editor,this.element=e.element,this.element.draggable=!1,this.contentElement=e.contentElement,this.getPos=e.getPos,this.onResize=e.onResize,this.onCommit=e.onCommit,this.onUpdate=e.onUpdate,e.options?.min&&(this.minSize={...this.minSize,...e.options.min}),e.options?.max&&(this.maxSize=e.options.max),e!=null&&(t=e.options)!=null&&t.directions&&(this.directions=e.options.directions),e.options?.preserveAspectRatio&&(this.preserveAspectRatio=e.options.preserveAspectRatio),e.options?.className&&(this.classNames={container:e.options.className.container||``,wrapper:e.options.className.wrapper||``,handle:e.options.className.handle||``,resizing:e.options.className.resizing||``}),e.options?.createCustomHandle&&(this.createCustomHandle=e.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on(`update`,this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){return this.contentElement??null}handleEditorUpdate(){let e=this.editor.isEditable;e!==this.lastEditableState&&(this.lastEditableState=e,e?e&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(e,t,n){return e.type===this.node.type&&(this.node=e,!this.onUpdate||this.onUpdate(e,t,n))}destroy(){this.isResizing&&(this.container.dataset.resizeState=`false`,this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener(`mousemove`,this.handleMouseMove),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`keydown`,this.handleKeyDown),document.removeEventListener(`keyup`,this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off(`update`,this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){let e=document.createElement(`div`);return e.dataset.resizeContainer=``,e.dataset.node=this.node.type.name,e.style.display=this.node.type.isInline?`inline-flex`:`flex`,this.classNames.container&&(e.className=this.classNames.container),e.appendChild(this.wrapper),e}createWrapper(){let e=document.createElement(`div`);return e.style.position=`relative`,e.style.display=`block`,e.dataset.resizeWrapper=``,this.classNames.wrapper&&(e.className=this.classNames.wrapper),e.appendChild(this.element),e}createHandle(e){let t=document.createElement(`div`);return t.dataset.resizeHandle=e,t.style.position=`absolute`,this.classNames.handle&&(t.className=this.classNames.handle),t}positionHandle(e,t){let n=t.includes(`top`),r=t.includes(`bottom`),i=t.includes(`left`),a=t.includes(`right`);n&&(e.style.top=`0`),r&&(e.style.bottom=`0`),i&&(e.style.left=`0`),a&&(e.style.right=`0`),(t===`top`||t===`bottom`)&&(e.style.left=`0`,e.style.right=`0`),(t===`left`||t===`right`)&&(e.style.top=`0`,e.style.bottom=`0`)}attachHandles(){this.directions.forEach(e=>{let t;t=this.createCustomHandle?this.createCustomHandle(e):this.createHandle(e),t instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${e}") did not return an HTMLElement. Falling back to default handle.`),t=this.createHandle(e)),this.createCustomHandle||this.positionHandle(t,e),t.addEventListener(`mousedown`,t=>this.handleResizeStart(t,e)),t.addEventListener(`touchstart`,t=>this.handleResizeStart(t,e)),this.handleMap.set(e,t),this.wrapper.appendChild(t)})}removeHandles(){this.handleMap.forEach(e=>e.remove()),this.handleMap.clear()}applyInitialSize(){let e=this.node.attrs.width,t=this.node.attrs.height;e?(this.element.style.width=`${e}px`,this.initialWidth=e):this.initialWidth=this.element.offsetWidth,t?(this.element.style.height=`${t}px`,this.initialHeight=t):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(e,t){e.preventDefault(),e.stopPropagation(),this.isResizing=!0,this.activeHandle=t,Gp(e)?(this.startX=e.touches[0].clientX,this.startY=e.touches[0].clientY):(this.startX=e.clientX,this.startY=e.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState=`true`,this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener(`mousemove`,this.handleMouseMove),document.addEventListener(`touchmove`,this.handleTouchMove),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`keydown`,this.handleKeyDown),document.addEventListener(`keyup`,this.handleKeyUp)}handleResize(e,t){if(!this.activeHandle)return;let n=this.preserveAspectRatio||this.isShiftKeyPressed,{width:r,height:i}=this.calculateNewDimensions(this.activeHandle,e,t),a=this.applyConstraints(r,i,n);this.element.style.width=`${a.width}px`,this.element.style.height=`${a.height}px`,this.onResize&&this.onResize(a.width,a.height)}calculateNewDimensions(e,t,n){let r=this.startWidth,i=this.startHeight,a=e.includes(`right`),o=e.includes(`left`),s=e.includes(`bottom`),c=e.includes(`top`);return a?r=this.startWidth+t:o&&(r=this.startWidth-t),s?i=this.startHeight+n:c&&(i=this.startHeight-n),(e===`right`||e===`left`)&&(r=this.startWidth+(a?t:-t)),(e===`top`||e===`bottom`)&&(i=this.startHeight+(s?n:-n)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(r,i,e):{width:r,height:i}}applyConstraints(e,t,n){if(!n){let n=Math.max(this.minSize.width,e),r=Math.max(this.minSize.height,t);return this.maxSize?.width&&(n=Math.min(this.maxSize.width,n)),this.maxSize?.height&&(r=Math.min(this.maxSize.height,r)),{width:n,height:r}}let r=e,i=t;return rthis.maxSize.width&&(r=this.maxSize.width,i=r/this.aspectRatio),this.maxSize?.height&&i>this.maxSize.height&&(i=this.maxSize.height,r=i*this.aspectRatio),{width:r,height:i}}applyAspectRatio(e,t,n){return n===`left`||n===`right`?{width:e,height:e/this.aspectRatio}:n===`top`||n===`bottom`?{width:t*this.aspectRatio,height:t}:{width:e,height:e/this.aspectRatio}}},qp=class e extends hp{constructor(...e){super(...e),this.type=`node`}static create(t={}){let n=typeof t==`function`?t():t;return new e(n)}configure(e){return super.configure(e)}extend(e){let t=typeof e==`function`?e():e;return super.extend(t)}};function Jp(e){return new _p({find:e.find,handler:({state:t,range:n,match:r,pasteEvent:i})=>{let a=Mu(e.getAttributes,void 0,r,i);if(a===!1||a===null)return null;let{tr:o}=t,s=r[r.length-1],c=r[0],l=n.to;if(s){let i=c.search(/\S/),u=n.from+c.indexOf(s),d=u+s.length;if($u(n.from,n.to,t.doc).filter(t=>t.mark.type.excluded.find(n=>n===e.type&&n!==t.mark.type)).filter(e=>e.to>u).length)return null;dn.from&&o.delete(n.from+i,u),l=n.from+i+s.length,o.addMark(n.from+i,l,e.type.create(a||{})),r.index!==void 0&&r.input!==void 0&&r.index+r[0].length>=r.input.length||o.removeStoredMark(e.type)}}})}var Yp=e=>e.replace(/[&<>"']/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`})[e]);function Xp(e,t=600){let n=[],r=``;for(let i of e.replace(/\s+/g,` `).trim().split(/(?<=[.!?…])\s+/))r&&r.length+i.length>t&&(n.push(r),r=``),r=r?`${r} ${i}`:i;return r&&n.push(r),n}function Zp(e,t,n){let r=`

${Yp(t.summaryTitle.replace(`{name}`,e.name))}

`;e.summary?r+=n(e.summary):e.summaryError&&(r+=`

${Yp(e.summaryError)}

`);let i=Xp(e.text).map(e=>`

${Yp(e)}

`).join(``);return`${r}
${Yp(t.transcript)}
${i}
`}var Qp=()=>new Map,$p=e=>{let t=Qp();return e.forEach((e,n)=>{t.set(n,e)}),t},em=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},tm=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},nm=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},rm=()=>new Set,im=e=>e[e.length-1],am=(e,t)=>{for(let n=0;n{for(let n=0;n{for(let n=0;n{let n=Array(e);for(let r=0;r{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return om((this._observers.get(e)||Qp()).values()).forEach(e=>e(...t))}destroy(){this._observers=Qp()}},fm=class{constructor(){this._observers=Qp()}on(e,t){em(this._observers,e,rm).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return om((this._observers.get(e)||Qp()).values()).forEach(e=>e(...t))}destroy(){this._observers=Qp()}},pm=Math.floor,mm=Math.abs,hm=(e,t)=>ee>t?e:t;Number.isNaN;var _m=e=>e===0?1/e<0:e<0,vm=1<<29,ym=2**53-1,bm=-(2**53-1),xm=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&pm(e)===e);Number.isNaN,Number.parseInt;var Sm=String.fromCharCode;String.fromCodePoint,Sm(65535);var Cm=e=>e.toLowerCase(),wm=/^\s*/g,Tm=e=>e.replace(wm,``),Em=/([A-Z])/g,Dm=(e,t)=>Tm(e.replace(Em,e=>`${t}${Cm(e)}`)),Om=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;ekm.encode(e):Om,jm=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});jm&&jm.decode(new Uint8Array).length===1&&(jm=null);var Mm=(e,t)=>lm(t,()=>e).join(``),Nm=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Pm=()=>new Nm,Fm=e=>{let t=Pm();return e(t),Lm(t)},Im=e=>{let t=e.cpos;for(let n=0;n{let t=new Uint8Array(Im(e)),n=0;for(let r=0;r{let n=e.cbuf.length;n-e.cpos{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},Bm=zm,M=(e,t)=>{for(;t>127;)zm(e,128|127&t),t=pm(t/128);zm(e,127&t)},Vm=(e,t)=>{let n=_m(t);for(n&&(t=-t),zm(e,(t>63?128:0)|(n?64:0)|63&t),t=pm(t/64);t>0;)zm(e,(t>127?128:0)|127&t),t=pm(t/128)},Hm=new Uint8Array(3e4),Um=Hm.length/3,Wm=km&&km.encodeInto?(e,t)=>{if(t.length{let n=unescape(encodeURIComponent(t)),r=n.length;M(e,r);for(let t=0;t{let n=e.cbuf.length,r=e.cpos,i=hm(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(gm(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Km=(e,t)=>{M(e,t.byteLength),Gm(e,t)},qm=(e,t)=>{Rm(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Jm=(e,t)=>qm(e,4).setFloat32(0,t,!1),Ym=(e,t)=>qm(e,8).setFloat64(0,t,!1),Xm=(e,t)=>qm(e,8).setBigInt64(0,t,!1),Zm=new DataView(new ArrayBuffer(4)),Qm=e=>(Zm.setFloat32(0,e),Zm.getFloat32(0)===e),$m=(e,t)=>{switch(typeof t){case`string`:zm(e,119),Wm(e,t);break;case`number`:xm(t)&&mm(t)<=2147483647?(zm(e,125),Vm(e,t)):Qm(t)?(zm(e,124),Jm(e,t)):(zm(e,123),Ym(e,t));break;case`bigint`:zm(e,122),Xm(e,t);break;case`object`:if(t===null)zm(e,126);else if(um(t)){zm(e,117),M(e,t.length);for(let n=0;n0&&M(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},th=e=>{e.count>0&&(Vm(e.encoder,e.count===1?e.s:-e.s),e.count>1&&M(e.encoder,e.count-2))},nh=class{constructor(){this.encoder=new Nm,this.s=0,this.count=0}write(e){this.s===e?this.count++:(th(this),this.count=1,this.s=e)}toUint8Array(){return th(this),Lm(this.encoder)}},rh=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Vm(e.encoder,t),e.count>1&&M(e.encoder,e.count-2)}},ih=class{constructor(){this.encoder=new Nm,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(rh(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return rh(this),Lm(this.encoder)}},ah=class{constructor(){this.sarr=[],this.s=``,this.lensE=new nh}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Nm;return this.sarr.push(this.s),this.s=``,Wm(e,this.sarr.join(``)),Gm(e,this.lensE.toUint8Array()),Lm(e)}},oh=e=>Error(e),sh=()=>{throw oh(`Method unimplemented`)},ch=()=>{throw oh(`Unexpected case`)},lh=oh(`Unexpected end of array`),uh=oh(`Integer out of Range`),dh=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw lh;return new Uint8Array(e.buffer,e.byteOffset+t,n)},fh=(e,t,n)=>{if(t<0||n<0||t+n>e.length)throw lh;return new DataView(e.buffer,e.byteOffset+t,n)},ph=class{constructor(e){this.arr=e,this.pos=0}},mh=e=>new ph(e),hh=e=>e.pos!==e.arr.length,gh=(e,t)=>{let n=dh(e.arr,e.pos,t);return e.pos+=t,n},_h=e=>gh(e,N(e)),vh=e=>e.arr[e.pos++],N=e=>{let t=0,n=1,r=e.arr.length;for(;e.posym)throw uh}throw lh},yh=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.posym)throw uh}throw lh},bh=jm?e=>jm.decode(_h(e)):e=>{let t=N(e);if(t===0)return``;{let n=String.fromCodePoint(vh(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(vh(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},xh=(e,t)=>{let n=fh(e.arr,e.pos,t);return e.pos+=t,n},Sh=[e=>void 0,e=>null,yh,e=>xh(e,4).getFloat32(0,!1),e=>xh(e,8).getFloat64(0,!1),e=>xh(e,8).getBigInt64(0,!1),e=>!1,e=>!0,bh,e=>{let t=N(e),n={};for(let r=0;r{let t=N(e),n=[];for(let r=0;rSh[127-vh(e)](e),wh=class extends ph{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=hh(this)?N(this)+1:-1),this.count--,this.s}},Th=class extends ph{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=yh(this);let e=_m(this.s);this.count=1,e&&(this.s=-this.s,this.count=N(this)+2)}return this.count--,this.s}},Eh=class extends ph{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=yh(this),t=e&1;this.diff=pm(e/2),this.count=1,t&&(this.count=N(this)+2)}return this.s+=this.diff,this.count--,this.s}},Dh=class{constructor(e){this.decoder=new Th(e),this.str=bh(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var Oh=crypto.getRandomValues.bind(crypto),kh=Math.random,Ah=()=>Oh(new Uint32Array(1))[0],jh=e=>e[pm(kh()*e.length)],Mh=`10000000-1000-4000-8000-100000000000`,Nh=()=>Mh.replace(/[018]/g,e=>(e^Ah()&15>>e/4).toString(16)),Ph=Date.now,Fh=e=>new Promise(e);Promise.all.bind(Promise);var Ih=e=>e===void 0?null:e,Lh=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Lh=localStorage)}catch{}var Rh=Lh,zh=Symbol(`Equality`),Bh=(e,t)=>e===t||!!e?.[zh]?.(t)||!1,Vh=e=>typeof e==`object`,Hh=Object.assign,Uh=Object.keys,Wh=(e,t)=>{for(let n in e)t(e[n],n)},Gh=e=>Uh(e).length,Kh=e=>{for(let t in e)return!1;return!0},qh=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Jh=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Yh=(e,t)=>e===t||Gh(e)===Gh(t)&&qh(e,(e,n)=>(e!==void 0||Jh(t,n))&&Bh(t[n],e)),Xh=Object.freeze,Zh=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Zh(e[t])}return Xh(e)},Qh=(e,t,n=0)=>{try{for(;ne,eg=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[zh]!=null)return e[zh](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;nt.includes(e),ng=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,rg=typeof window<`u`&&typeof document<`u`&&!ng;typeof navigator<`u`&&/Mac/.test(navigator.platform);var ig,ag=[],og=()=>{if(ig===void 0){if(ng){ig=Qp();let e=process.argv,t=null;for(let n=0;n{if(e.length!==0){let[t,n]=e.split(`=`);ig.set(`--${Dm(t,`-`)}`,n),ig.set(`-${Dm(t,`-`)}`,n)}})):ig=Qp()}return ig},sg=e=>og().has(e),cg=e=>Ih(ng?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Rh.getItem(e)),lg=e=>sg(`--`+e)||cg(e)!==null,ug=lg(`production`),dg=ng&&tg({}.FORCE_COLOR,[`true`,`1`,`2`])||!sg(`--no-colors`)&&!lg(`no-color`)&&(!ng||process.stdout.isTTY)&&(!ng||sg(`--color`)||cg(`COLORTERM`)!==null||(cg(`TERM`)||``).includes(`color`)),fg=e=>new Uint8Array(e),pg=e=>{let t=``;for(let n=0;nBuffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),hg=e=>{let t=atob(e),n=fg(t.length);for(let e=0;enew Uint8Array(Buffer.from(e,`base64`)),_g=rg?pg:mg,vg=rg?hg:gg,yg=e=>{let t=fg(e.byteLength);return t.set(e),t},bg=e=>Fm(t=>$m(t,e)),xg=class{constructor(e,t){this.left=e,this.right=t}},Sg=(e,t)=>new xg(e,t),Cg=e=>e.next()>=.5,wg=(e,t,n)=>pm(e.next()*(n+1-t)+t),Tg=(e,t,n)=>pm(e.next()*(n+1-t)+t),Eg=(e,t,n)=>Tg(e,t,n),Dg=e=>Sm(Eg(e,97,122)),Og=(e,t=0,n=20)=>{let r=Eg(e,t,n),i=``;for(let t=0;tt[Eg(e,0,t.length-1)],Ag=Symbol(`0schema`),jg=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Mm(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(` +`)}},Mg=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[zh]?Bh(e,t):um(e)?sm(e,e=>cm(t,t=>Mg(e,t))):Vh(e)?qh(e,(e,n)=>Mg(e,t[n])):!1,Ng=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Mg(t,n)}equals(e){return this.constructor===e.constructor&&eg(this.shape,e.shape)}[Ag](){return!0}[zh](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){sh()}get nullable(){return f_(this,D_)}get optional(){return new Wg(this)}cast(e){return j_(e,this),e}expect(e){return j_(e,this),e}},Pg=class extends Ng{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},Fg=(e,t=null)=>new Pg(e,t);Fg(Pg);var Ig=class extends Ng{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},Lg=e=>new Ig(e);Fg(Ig);var Rg=class extends Ng{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},zg=(...e)=>new Rg(e),Bg=Fg(Rg),Vg=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Hg=e=>{if(S_.check(e))return[Vg(e)];if(Bg.check(e))return e.shape.map(e=>e+``);if(x_.check(e))return[`[+-]?\\d+.?\\d*`];if(C_.check(e))return[`.*`];if(p_.check(e))return e.shape.map(Hg).flat(1);ch()};Fg(class extends Ng{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Hg).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Ug=Symbol(`optional`),Wg=class extends Ng{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Ug](){return!0}},Gg=Fg(Wg),Kg=class extends Ng{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Kg,Fg(Kg);var qg=class e extends Ng{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):qh(this.shape,(n,r)=>{let i=this._isPartial&&!Jh(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Jg=e=>new qg(e),Yg=Fg(qg),Xg=Lg(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Zg=class extends Ng{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&qh(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},Qg=(e,t)=>new Zg(e,t),$g=Fg(Zg),e_=class extends Ng{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&qh(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},t_=(...e)=>new e_(e);Fg(e_);var n_=class extends Ng{constructor(e){super(),this.shape=e.length===1?e[0]:new d_(e)}check(e,t){let n=um(e)&&sm(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},r_=(...e)=>new n_(e),i_=Fg(n_),a_=Lg(e=>um(e)),o_=class extends Ng{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},s_=(e,t=null)=>new o_(e,t);Fg(o_);var c_=s_(Ng),l_=Fg(class extends Ng{constructor(e){super(),this.len=e.length-1,this.args=t_(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),u_=Lg(e=>typeof e==`function`);Fg(class extends Ng{constructor(e){super(),this.shape=e}check(e,t){let n=sm(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var d_=class extends Ng{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=cm(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},f_=(...e)=>e.findIndex(e=>p_.check(e))>=0?f_(...e.map(e=>A_(e)).map(e=>p_.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new d_(e),p_=Fg(d_),m_=()=>!0,h_=Lg(m_),g_=Fg(Ig,e=>e.shape===m_),__=Lg(e=>typeof e==`bigint`),v_=Lg(e=>e===__),y_=Lg(e=>typeof e==`symbol`);Lg(e=>e===y_);var b_=Lg(e=>typeof e==`number`),x_=Lg(e=>e===b_),S_=Lg(e=>typeof e==`string`),C_=Lg(e=>e===S_),w_=Lg(e=>typeof e==`boolean`),T_=Lg(e=>e===w_),E_=zg(void 0);Fg(Rg,e=>e.shape.length===1&&e.shape[0]===void 0),zg(void 0);var D_=zg(null),O_=Fg(Rg,e=>e.shape.length===1&&e.shape[0]===null);Fg(Uint8Array),Fg(Pg,e=>e.shape===Uint8Array);var k_=f_(b_,S_,D_,E_,__,w_,y_);(()=>{let e=r_(h_),t=Qg(S_,h_),n=f_(b_,S_,D_,w_,e,t);return e.shape=n,t.shape.values=n,n})();var A_=e=>{if(c_.check(e))return e;if(Xg.check(e)){let t={};for(let n in e)t[n]=A_(e[n]);return Jg(t)}if(a_.check(e))return f_(...e.map(A_));if(k_.check(e))return zg(e);if(u_.check(e))return Fg(e);ch()},j_=ug?()=>{}:(e,t)=>{let n=new jg;if(!t.check(e,n))throw oh(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},M_=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:A_(e),h:t}),this}else(e){return this.if(h_,e)}done(){return(e,t)=>{for(let n=0;nnew M_(e))(h_).if(x_,(e,t)=>wg(t,bm,ym)).if(C_,(e,t)=>Og(t)).if(T_,(e,t)=>Cg(t)).if(v_,(e,t)=>BigInt(wg(t,bm,ym))).if(p_,(e,t)=>P_(t,kg(t,e.shape))).if(Yg,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Gg.check(i)){if(Cg(t))continue;i=i.shape}n[r]=N_(i,t)}return n}).if(i_,(e,t)=>{let n=[],r=Tg(t,0,42);for(let i=0;ikg(t,e.shape)).if(O_,(e,t)=>null).if(l_,(e,t)=>{let n=P_(t,e.res);return()=>n}).if(g_,(e,t)=>P_(t,kg(t,[b_,S_,D_,E_,__,w_,r_(b_),Qg(f_(`a`,`b`,`c`),b_)]))).if($g,(e,t)=>{let n={},r=wg(t,0,3);for(let i=0;iN_(A_(t),e),F_=typeof document<`u`?document:{};Lg(e=>e.nodeType===B_),typeof DOMParser<`u`&&new DOMParser,Lg(e=>e.nodeType===L_),Lg(e=>e.nodeType===R_);var I_=e=>tm(e,(e,t)=>`${t}:${e};`).join(``),L_=F_.ELEMENT_NODE,R_=F_.TEXT_NODE;F_.CDATA_SECTION_NODE,F_.COMMENT_NODE;var z_=F_.DOCUMENT_NODE;F_.DOCUMENT_TYPE_NODE;var B_=F_.DOCUMENT_FRAGMENT_NODE;Lg(e=>e.nodeType===z_);var V_=(e=>class{constructor(e){this._=e}destroy(){e(this._)}})(clearTimeout),H_=(e,t)=>new V_(setTimeout(t,e)),U_=Symbol,W_=U_(),G_=U_(),K_=U_(),q_=U_(),J_=U_(),Y_=U_(),X_=U_(),Z_=U_(),Q_=U_(),$_=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r0&&n.push(t.join(``));r{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=Qp(),i=[],a=0;for(;a0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a{console.log(...tv(e)),iv.forEach(t=>t.print(e))},rv=(...e)=>{console.warn(...tv(e)),e.unshift(Z_),iv.forEach(t=>t.print(e))},iv=rm(),av=e=>({[Symbol.iterator](){return this},next:e}),ov=(e,t)=>av(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),sv=(e,t)=>av(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),cv=class{constructor(e,t){this.clock=e,this.len=t}},lv=class{constructor(){this.clients=new Map}},uv=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r{let n=0,r=e.length-1;for(;n<=r;){let i=pm((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t{let n=e.clients.get(t.client);return n!==void 0&&dv(n,t.clock)!==null},pv=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t=i.clock?e[n-1]=new cv(r.clock,gm(r.len,i.clock+i.len-r.clock)):(n{let t=new lv;for(let n=0;n{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t{em(e.clients,t,()=>[]).push(new cv(n,r))},gv=()=>new lv,_v=e=>{let t=gv();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t0&&t.clients.set(n,r)}),t},vv=(e,t)=>{M(e.restEncoder,t.clients.size),om(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),M(e.restEncoder,t);let r=n.length;M(e.restEncoder,r);for(let t=0;t{let t=new lv,n=N(e.restDecoder);for(let r=0;r0){let i=em(t.clients,n,()=>[]);for(let t=0;t{let r=new lv,i=N(e.restDecoder);for(let a=0;a0){let e=new Av;return M(e.restEncoder,0),vv(e,r),e.toUint8Array()}return null},xv=Ah,Sv=class e extends dm{constructor({guid:e=Nh(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=xv(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new xy,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Fh(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Fh(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&zy(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(om(this.subdocs).map(e=>e.guid))}transact(e,t=null){return zy(this,e,t)}get(e,t=hb){let n=em(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==hb&&r!==t){if(r===hb){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Ib)}getText(e=``){return this.get(e,rx)}getMap(e=``){return this.get(e,zb)}getXmlElement(e=``){return this.get(e,cx)}getXmlFragment(e=``){return this.get(e,ox)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,om(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,zy(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},Cv=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return N(this.restDecoder)}readDsLen(){return N(this.restDecoder)}},wv=class extends Cv{readLeftID(){return P(N(this.restDecoder),N(this.restDecoder))}readRightID(){return P(N(this.restDecoder),N(this.restDecoder))}readClient(){return N(this.restDecoder)}readInfo(){return vh(this.restDecoder)}readString(){return bh(this.restDecoder)}readParentInfo(){return N(this.restDecoder)===1}readTypeRef(){return N(this.restDecoder)}readLen(){return N(this.restDecoder)}readAny(){return Ch(this.restDecoder)}readBuf(){return yg(_h(this.restDecoder))}readJSON(){return JSON.parse(bh(this.restDecoder))}readKey(){return bh(this.restDecoder)}},Tv=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=N(this.restDecoder),this.dsCurrVal}readDsLen(){let e=N(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Ev=class extends Tv{constructor(e){super(e),this.keys=[],N(e),this.keyClockDecoder=new Eh(_h(e)),this.clientDecoder=new Th(_h(e)),this.leftClockDecoder=new Eh(_h(e)),this.rightClockDecoder=new Eh(_h(e)),this.infoDecoder=new wh(_h(e),vh),this.stringDecoder=new Dh(_h(e)),this.parentInfoDecoder=new wh(_h(e),vh),this.typeRefDecoder=new Th(_h(e)),this.lenDecoder=new Th(_h(e))}readLeftID(){return new $v(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new $v(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Ch(this.restDecoder)}readBuf(){return _h(this.restDecoder)}readJSON(){return Ch(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e{r=gm(r,t[0].id.clock);let i=Ty(t,r);M(e.restEncoder,t.length-i),e.writeClient(n),M(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n{let r=new Map;n.forEach((e,n)=>{Cy(t,n)>e&&r.set(n,e)}),Sy(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),M(e.restEncoder,r.size),om(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{jv(e,t.clients.get(n),n,r)})},Nv=(e,t)=>{let n=Qp(),r=N(e.restDecoder);for(let i=0;i{let r=[],i=om(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new xy,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==tS){let i=em(d,u.id.client,()=>Cy(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,Cy(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i0)u=r.pop();else if(o!==null&&o.i0){let e=new Av;return Mv(e,s,new Map),M(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Fv=(e,t)=>Mv(e,t.doc.store,t.beforeState),Iv=(e,t,n,r=new Ev(e))=>zy(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Pv(e,i,Nv(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(nt)&&o.missing.set(e,t)}o.update=Yy([o.update,a.update])}}else i.pendingStructs=a;let s=bv(r,e,i);if(i.pendingDs){let t=new Ev(mh(i.pendingDs));N(t.restDecoder);let n=bv(t,e,i);i.pendingDs=s&&n?Yy([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Lv(e.doc,t)}},n,!1),Lv=(e,t,n,r=Ev)=>{let i=mh(t);Iv(i,e,n,new r(i))},Rv=(e,t,n)=>Lv(e,t,n,wv),zv=(e,t,n=new Map)=>{Mv(e,t.store,n),vv(e,_v(t.store))},Bv=(e,t=new Uint8Array([0]),n=new Av)=>{zv(n,e,Uv(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Xy(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Ov)return qy(r.map((e,t)=>t===0?e:tb(e)));if(n.constructor===Av)return Yy(r)}return r[0]},Vv=(e,t)=>Bv(e,t,new Ov),Hv=e=>{let t=new Map,n=N(e.restDecoder);for(let r=0;rHv(new Cv(mh(e))),Wv=(e,t)=>(M(e.restEncoder,t.size),om(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{M(e.restEncoder,t),M(e.restEncoder,n)}),e),Gv=(e,t)=>Wv(e,Sy(t.store)),Kv=(e,t=new kv)=>(e instanceof Map?Wv(t,e):Gv(t,e),t.toUint8Array()),qv=e=>Kv(e,new Dv),Jv=class{constructor(){this.l=[]}},Yv=()=>new Jv,Xv=(e,t)=>e.l.push(t),Zv=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},Qv=(e,t,n)=>Qh(e.l,[t,n]),$v=class{constructor(e,t){this.client=e,this.clock=t}},ey=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,P=(e,t)=>new $v(e,t),ty=e=>P(N(e),N(e)),ny=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw ch()},ry=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},iy=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},ay=e=>new iy(e.type==null?null:P(e.type.client,e.type.clock),e.tname??null,e.item==null?null:P(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),oy=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},sy=(e,t,n=0)=>new oy(e,t,n),cy=(e,t,n)=>{let r=null,i=null;return e._item===null?i=ny(e):r=P(e._item.id.client,e._item.id.clock),new iy(r,i,t,n)},ly=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return cy(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return cy(e,P(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return cy(e,r.lastId,n);r=r.right}return cy(e,null,n)},uy=e=>{let t=null,n=null,r=null;switch(N(e)){case 0:r=ty(e);break;case 1:n=bh(e);break;case 2:t=ty(e)}let i=hh(e)?yh(e):0;return new iy(t,n,r,i)},dy=e=>uy(mh(e)),fy=(e,t)=>{let n=Ey(e,t);return{item:n,diff:t.clock-n.id.clock}},py=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(Cy(r,i.client)<=i.clock)return null;let e=n?Kx(r,i):fy(r,i),t=e.item;if(!(t instanceof Zx))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(Cy(r,a.client)<=a.clock)return null;let{item:e}=n?Kx(r,a):{item:Ey(r,a)};if(e instanceof Zx&&e.content instanceof Wx)c=e.content.type;else return null}else throw ch();l=s>=0?c._length:0}return sy(c,l,e.assoc)},my=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&ey(e.item,t.item)&&ey(e.type,t.type)&&e.assoc===t.assoc,hy=class{constructor(e,t){this.ds=e,this.sv=t}},gy=(e,t)=>new hy(e,t),_y=gy(gv(),new Map),vy=e=>gy(_v(e.store),Sy(e.store)),yy=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!fv(t.ds,e.id),by=(e,t)=>{let n=em(e.meta,by,rm),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t{}),n.add(t))},xy=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Sy=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},Cy=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},wy=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw ch()}n.push(t)},Ty=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=pm(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t{let n=e.clients.get(t.client);return n[Ty(n,t.clock)]},Dy=(e,t,n)=>{let r=Ty(t,n),i=t[r];return i.id.clock{let n=e.doc.store.clients.get(t.client);return n[Dy(e,n,t.clock)]},ky=(e,t,n)=>{let r=t.clients.get(n.client),i=Ty(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==_x&&r.splice(i+1,0,Jx(e,a,n.clock-a.id.clock+1)),a},Ay=(e,t,n)=>{let r=e.clients.get(t.id.client);r[Ty(r,t.id.clock)]=n},jy=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=Dy(e,t,n),s;do s=t[o++],at.deleteSet.clients.size===0&&!nm(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(pv(t.deleteSet),Fv(e,t),vv(e,t.deleteSet),!0),Py=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&em(e.changed,t,rm).add(n)},Fy=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Zx&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},Iy=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=Ty(e,a.clock),i=e[r];r{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=hm(r.length-1,1+Ty(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Fy(r,e)}})},Ry=(e,t)=>{if(te.push(()=>{r._item!==null&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&e.push(()=>{t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),Qv(r._dEH,t,n)})}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&ex(n)})}),Qh(e,[])}finally{r.gc&&Iy(a,i,r.gcFilter),Ly(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=gm(Ty(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Fy(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=Ty(r,n);a+11||a>0&&Fy(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(nv(Z_,W_,`[yjs] `,G_,Y_,`Changed the client-id because another client seems to be using it.`),r.clientID=xv()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Ov;Ny(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Av;Ny(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):Ry(e,t+1)}}},zy=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new My(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&Ry(i,0)}}return o},By=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Vy=(e,t,n)=>{uv(e,n.deletions,n=>{n instanceof Zx&&t.scope.some(t=>t===e.doc||ry(t,n))&&qx(n,!1)})},Hy=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;zy(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;uv(n,o.insertions,e=>{if(e instanceof Zx){if(e.redone!==null){let{item:t,diff:i}=Kx(r,e.id);i>0&&(t=Oy(n,P(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||ry(t,e))&&c.push(e)}}),uv(n,o.deletions,e=>{e instanceof Zx&&a.some(t=>t===n.doc||ry(t,e))&&!fv(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Xx(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Uy=class extends dm{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=um(e)?e[0].doc:e instanceof Sv?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new lv;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&hv(i,n,r,a)});let a=Ph(),o=!1;if(this.lastChange>0&&a-this.lastChange0&&!t&&!n){let t=r[r.length-1];t.deletions=mv([t.deletions,e.deleteSet]),t.insertions=mv([t.insertions,i])}else r.push(new By(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),uv(e,e.deleteSet,t=>{t instanceof Zx&&this.scope.some(n=>n===e.doc||ry(n,t))&&qx(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.destroy=this.destroy.bind(this),this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,this.destroy)}addToScope(e){let t=new Set(this.scope);e=um(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof hb?e.doc!==this.doc:e!==this.doc)&&rv(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Vy(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Vy(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Hy(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Hy(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),this.doc.off(`destroy`,this.destroy),super.destroy()}};function*Wy(e){let t=N(e.restDecoder);for(let n=0;nYy(e,wv,Ov),Jy=(e,t)=>{if(e.constructor===_x){let{client:n,clock:r}=e.id;return new _x(P(n,r+t),e.length-t)}if(e.constructor===tS){let{client:n,clock:r}=e.id;return new tS(P(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Zx(P(r,i+t),null,P(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Yy=(e,t=Ev,n=Av)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(mh(e))),i=r.map(e=>new Gy(e,!0)),a=null,o=new n,s=new Ky(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===tS?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Qy(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length0&&(a.struct.constructor===tS?a.struct.length-=t:n=Jy(n,t)),a.struct.mergeWith(n)||(Qy(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==tS;n=e.next())Qy(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Qy(s,a.struct,a.offset),a=null),$y(s),vv(o,mv(r.map(e=>yv(e)))),o.toUint8Array()},Xy=(e,t,n=Ev,r=Av)=>{let i=Uv(t),a=new r,o=new Ky(a),s=new n(mh(e)),c=new Gy(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===tS)c.next();else if(e.id.clock+e.length>n)for(Qy(o,e,gm(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Qy(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return $y(o),vv(a,yv(s)),a.toUint8Array()},Zy=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Lm(e.encoder.restEncoder)}),e.encoder.restEncoder=Pm(),e.written=0)},Qy=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Zy(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),M(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},$y=e=>{Zy(e);let t=e.encoder.restEncoder;M(t,e.clientStructs.length);for(let n=0;n{let i=new n(mh(e)),a=new Gy(i,!1),o=new r,s=new Ky(o);for(let e=a.curr;e!==null;e=a.next())Qy(s,t(e),0);return $y(s),vv(o,yv(i)),o.toUint8Array()},tb=e=>eb(e,$h,Ev,Ov),nb=`You must not compute changes after the event-handler fired.`,rb=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=ib(this.currentTarget,this.target)}deletes(e){return fv(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw oh(nb);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=im(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=im(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=im(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw oh(nb);let t=this.target,n=rm(),r=rm(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},ib=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},ab=()=>{rv(`Invalid access: Add Yjs type to a document before reading data.`)},ob=80,sb=0,cb=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=sb++}},lb=e=>{e.timestamp=sb++},ub=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=sb++},db=(e,t,n)=>{if(e.length>=ob){let r=e.reduce((e,t)=>e.timestamp{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>mm(t-e.index)t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&mm(n.index-i){for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t0&&t===i.index)&&(i.index=gm(t,i.index+n))}},mb=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;em(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Qv(r._eH,n,t)},hb=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Yv(),this._dEH=Yv(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw sh()}clone(){throw sh()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Xv(this._eH,e)}observeDeep(e){Xv(this._dEH,e)}unobserve(e){Zv(this._eH,e)}unobserveDeep(e){Zv(this._dEH,e)}toJSON(){}},gb=(e,t,n)=>{e.doc??ab(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},_b=e=>{e.doc??ab();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n{let n=[],r=e._start;for(;r!==null;){if(r.countable&&yy(r,t)){let e=r.content.getContent();for(let t=0;t{let n=0,r=e._start;for(e.doc??ab();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r{let n=[];return yb(e,(r,i)=>{n.push(t(r,i,e))}),n},xb=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},Sb=(e,t)=>{e.doc??ab();let n=fb(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Zx(P(o,Cy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Mx(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Zx(P(o,Cy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new vx(new Uint8Array(n))),i.integrate(e,0);break;case Sv:i=new Zx(P(o,Cy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Cx(n)),i.integrate(e,0);break;default:if(n instanceof hb)i=new Zx(P(o,Cy(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Wx(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},wb=()=>oh(`Length exceeded!`),Tb=(e,t,n,r)=>{if(n>t._length)throw wb();if(n===0)return t._searchMarker&&pb(t._searchMarker,n,r.length),Cb(e,t,null,r);let i=n,a=fb(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return Cb(e,t,r,n)},Db=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=fb(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n0&&s!==null;)s.deleted||(r0)throw wb();t._searchMarker&&pb(t._searchMarker,i,-a+r)},Ob=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},kb=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Mx([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Mx([r]);break;case Uint8Array:s=new vx(r);break;case Sv:s=new Cx(r);break;default:if(r instanceof hb)s=new Wx(r);else throw Error(`Unexpected content type`)}new Zx(P(o,Cy(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Ab=(e,t)=>{e.doc??ab();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},jb=e=>{let t={};return e.doc??ab(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Mb=(e,t)=>{e.doc??ab();let n=e._map.get(t);return n!==void 0&&!n.deleted},Nb=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&yy(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},Pb=e=>(e.doc??ab(),ov(e._map.entries(),e=>!e[1].deleted)),Fb=class extends rb{},Ib=class e extends hb{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof hb?e.clone():e)),t}get length(){return this.doc??ab(),this._length}_callObserver(e,t){super._callObserver(e,t),mb(this,e,new Fb(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):zy(this.doc,n=>{Tb(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):zy(this.doc,t=>{Eb(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):zy(this.doc,n=>{Db(n,this,e,t)})}get(e){return Sb(this,e)}toArray(){return _b(this)}slice(e=0,t=this.length){return gb(this,e,t)}toJSON(){return this.map(e=>e instanceof hb?e.toJSON():e)}map(e){return bb(this,e)}forEach(e){yb(this,e)}[Symbol.iterator](){return xb(this)}_write(e){e.writeTypeRef(Lx)}},Lb=e=>new Ib,Rb=class extends rb{constructor(e,t,n){super(e,t),this.keysChanged=n}},zb=class e extends hb{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof hb?e.clone():e)}),t}_callObserver(e,t){mb(this,e,new Rb(this,e,t))}toJSON(){this.doc??ab();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof hb?r.toJSON():r}}),e}get size(){return[...Pb(this)].length}keys(){return sv(Pb(this),e=>e[0])}values(){return sv(Pb(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return sv(Pb(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ab(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):zy(this.doc,t=>{Ob(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):zy(this.doc,n=>{kb(n,this,e,t)}),t}get(e){return Ab(this,e)}has(e){return Mb(this,e)}clear(){this.doc===null?this._prelimContent.clear():zy(this.doc,e=>{this.forEach(function(t,n,r){Ob(e,r,n)})})}_write(e){e.writeTypeRef(Rx)}},Bb=e=>new zb,Vb=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Yh(e,t),Hb=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&ch(),this.right.content.constructor){case Dx:this.right.deleted||Kb(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Ub=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case Dx:t.right.deleted||Kb(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n{let i=new Map,a=r?fb(t,n):null;return a?Ub(e,new Hb(a.p.left,a.p,a.index,i),n-a.index):Ub(e,new Hb(null,t._start,0,i),n)},Gb=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===Dx&&Vb(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Zx(P(a,Cy(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new Dx(o,r));l.integrate(e,0),n.right=l,n.forward()})},Kb=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},qb=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===Dx&&Vb(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Jb=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Vb(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Zx(P(a,Cy(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new Dx(s,c)),n.right.integrate(e,0),n.forward()}}return o},Yb=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;qb(n,i);let s=Jb(e,t,n,i),c=r.constructor===String?new Px(r):r instanceof hb?new Wx(r):new Tx(r),{left:l,right:u,index:d}=n;t._searchMarker&&pb(t._searchMarker,n.index,c.getLength()),u=new Zx(P(o,Cy(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Gb(e,t,n,s)},Xb=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;qb(n,i);let s=Jb(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===Dx));){if(!n.right.deleted)switch(n.right.content.constructor){case Dx:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Vb(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r0){let i=``;for(;r>0;r--)i+=` +`;n.right=new Zx(P(o,Cy(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Px(i)),n.right.integrate(e,0),n.forward()}Gb(e,t,n,s)},Zb=(e,t,n,r,i)=>{let a=t,o=Qp();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===Dx){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case Dx:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Kb(i,n);break}}}t=t.right}return s},Qb=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===Dx){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},$b=e=>{let t=0;return zy(e.doc,n=>{let r=e._start,i=e._start,a=Qp(),o=$p(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case Dx:Kb(o,i.content);break;default:t+=Zb(n,r,i,a,o),a=$p(o),r=i}i=i.right}}),t},ex=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&jy(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===Dx&&e.constructor!==_x&&t.add(e.parent)})}zy(n,n=>{uv(e,e.deleteSet,e=>{if(e instanceof _x||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===Dx?t.add(r):Qb(n,e)});for(let e of t)$b(e)})},tx=(e,t,n)=>{let r=n,i=$p(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Wx:case Tx:case Px:n{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];zy(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},Kh(o)||(e.attributes=Hh({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Wx:case Tx:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case Px:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case Dx:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Vb(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Vb(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Vb(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Vb(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Kb(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},rx=class e extends hb{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ab(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new nx(this,e,t);mb(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ab();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Px&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):zy(this.doc,n=>{let r=new Hb(null,this._start,0,new Map);for(let i=0;i0)&&Yb(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&tx(n,r,a.delete):Xb(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??ab();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(yy(s,e)||t!==void 0&&yy(s,t))switch(s.content.constructor){case Px:{let r=i.get(`ychange`);e!==void 0&&!yy(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!yy(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Wx:case Tx:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case Dx:yy(s,e)&&(c(),Kb(i,s.content))}s=s.right}c()};return e||t?zy(a,n=>{e&&by(n,e),t&&by(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):zy(r,r=>{let i=Wb(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Yb(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):zy(r,r=>{let i=Wb(r,this,e,!n);Yb(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):zy(n,n=>{tx(n,Wb(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):zy(r,r=>{let i=Wb(r,this,e,!1);i.right!==null&&Xb(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):zy(this.doc,t=>{Ob(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):zy(this.doc,n=>{kb(n,this,e,t)})}getAttribute(e){return Ab(this,e)}getAttributes(){return jb(this)}_write(e){e.writeTypeRef(zx)}},ix=e=>new rx,ax=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ab()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===cx||t.constructor===ox)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},ox=class e extends hb{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof hb?e.clone():e)),t}get length(){return this.doc??ab(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new ax(this,e)}querySelector(e){e=e.toUpperCase();let t=new ax(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),om(new ax(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){mb(this,e,new ux(this,t,e))}toString(){return bb(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),yb(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):zy(this.doc,n=>{Tb(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)zy(this.doc,n=>{let r=e&&e instanceof hb?e._item:e;Cb(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw oh(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):zy(this.doc,n=>{Db(n,this,e,t)})}toArray(){return _b(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Sb(this,e)}slice(e=0,t=this.length){return gb(this,e,t)}forEach(e){yb(this,e)}_write(e){e.writeTypeRef(Vx)}},sx=e=>new ox,cx=class e extends ox{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return Wh(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof hb?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i0?` `+t.join(` `):``}>${super.toString()}`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):zy(this.doc,t=>{Ob(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):zy(this.doc,n=>{kb(n,this,e,t)})}getAttribute(e){return Ab(this,e)}hasAttribute(e){return Mb(this,e)}getAttributes(e){return e?Nb(this,e):jb(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return yb(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Bx),e.writeKey(this.nodeName)}},lx=e=>new cx(e.readKey()),ux=class extends rb{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},dx=class e extends zb{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Hx),e.writeKey(this.hookName)}},fx=e=>new dx(e.readKey()),px=class e extends rx{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.keye.nodeName`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=``;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Ux)}},mx=e=>new px,hx=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw sh()}mergeWith(e){return!1}write(e,t,n){throw sh()}integrate(e,t){throw sh()}},gx=0,_x=class extends hx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),wy(e.doc.store,this)}write(e,t){e.writeInfo(gx),e.writeLen(this.length-t)}getMissing(e,t){return null}},vx=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw sh()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},yx=e=>new vx(e.readBuf()),bx=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){hv(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},xx=e=>new bx(e.readLen()),Sx=(e,t)=>new Sv({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),Cx=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(Sx(this.doc.guid,this.opts))}splice(e){throw sh()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},wx=e=>new Cx(Sx(e.readString(),e.readAny())),Tx=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw sh()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},Ex=e=>new Tx(e.readJSON()),Dx=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw sh()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},Ox=e=>new Dx(e.readKey(),e.readJSON()),kx=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r{let t=e.readLen(),n=[];for(let r=0;r{let t=e.readLen(),n=[];for(let r=0;r=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},Fx=e=>new Px(e.readString()),Ix=[Lb,Bb,ix,lx,sx,fx,mx],Lx=0,Rx=1,zx=2,Bx=3,Vx=4,Hx=5,Ux=6,Wx=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw sh()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Gx=e=>new Wx(Ix[e.readTypeRef()](e)),Kx=(e,t)=>{let n=t,r=0,i;do r>0&&(n=P(n.client,n.clock+r)),i=Ey(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Zx);return{item:i,diff:r}},qx=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Jx=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Zx(P(r,i+n),t,P(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=P(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Yx=(e,t)=>cm(e,e=>fv(e.deletions,t)),Xx=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return Oy(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Xx(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=Oy(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:Oy(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:Oy(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||fv(r,d.right.id)||Yx(a.undoStack,d.right.id)||Yx(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=Oy(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=P(c,Cy(s,c)),h=new Zx(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,qx(h,!0),h.integrate(e,0),h},Zx=class e extends hx{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Cy(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Cy(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===$v&&this.id.client!==this.parent.client&&this.parent.clock>=Cy(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=ky(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=Oy(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===_x||this.right&&this.right.constructor===_x)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===$v){let e=Ey(n,this.parent);this.parent=e.constructor===_x?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=ky(e,e.doc.store,P(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),ey(this.origin,n.origin)){if(n.id.client{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),hv(e.deleteSet,this.id.client,this.id.clock,this.length),Py(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw ch();this.content.gc(e),t?Ay(e,this,new _x(this.id,this.length)):this.content=new bx(this.length)}write(e,t){let n=t>0?P(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=ny(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===$v?(e.writeParentInfo(!1),e.writeLeftID(t)):ch();i!==null&&e.writeString(i)}this.content.write(e,t)}},Qx=(e,t)=>$x[t&31](e),$x=[()=>{ch()},xx,Ax,yx,Fx,Ex,Ox,Gx,Nx,wx,()=>{ch()}],eS=10,tS=class extends hx{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){ch()}write(e,t){e.writeInfo(eS),M(e.restEncoder,this.length-t)}getMissing(e,t){return null}},nS=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},rS=`__ $YJS$ __`;nS[rS]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),nS[rS]=!0;var iS=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}},aS=(e,t)=>e>>>t|e<<32-t,oS=e=>aS(e,2)^aS(e,13)^aS(e,22),sS=e=>aS(e,6)^aS(e,11)^aS(e,25),cS=e=>aS(e,7)^aS(e,18)^e>>>3,lS=e=>aS(e,17)^aS(e,19)^e>>>10,uS=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),dS=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),fS=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(dS),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=lS(t[e-2])+t[e-7]+cS(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+sS(o)+(o&s^~o&c)+uS[e]+t[e]>>>0,d=oS(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3=0&&t>>(3-t)*8;return i}},pS=e=>new fS().digest(e),mS=/[\uD800-\uDBFF]/,hS=/[\uDC00-\uDFFF]/,gS=(e,t)=>{let n=0,r=0;for(;n0&&mS.test(e[n-1])&&n--;r+n0&&hS.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}};function _S(e){if(!e||!(e.content instanceof Wx))return null;let t=e.content.type;if(!(t instanceof ox||t instanceof rx||t instanceof dx))throw Error(`Expected a Yjs XML type`);return t}function vS(e){if(e===null)return null;if(!(e.parent instanceof hb))throw Error(`Expected an integrated Yjs parent`);let t=e.parent;if(!(t instanceof ox||t instanceof rx||t instanceof dx))throw Error(`Expected a Yjs XML type`);return t}var yS=(e,t)=>{let n=null,r=null;return e._item===null?r=ny(e):n=P(e._item.id.client,e._item.id.clock),new iy(n,r,t.id)},bS=(e,t,n)=>{if(e===0)return ly(t,0,-1);let r=_S(t._first);for(;r!==null&&t!==r;){if(r instanceof px){if(r._length>=e)return ly(r,e,-1);if(e-=r._length,r._item!==null&&r._item.next!==null)r=_S(r._item.next);else{do r=vS(r._item),e--;while(r!==t&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==t&&(r=r._item===null?null:_S(r._item.next))}}else{let i=n.get(r),a=i instanceof ce?i.nodeSize:0;if(r._first!==null&&e1)return new iy(r._item===null?null:r._item.id,r._item===null?ny(r):null,null);if(e-=a,r._item!==null&&r._item.next!==null)r=_S(r._item.next);else{if(e===0){if(r=r._item===null?r:vS(r._item),r===null)throw ch();return new iy(r._item===null?null:r._item.id,r._item===null?ny(r):null,null)}do{if(r=vS(r._item),r===null)throw ch();e--}while(r!==t&&r._item?.next===null);r!==t&&(r=_S(r._item?.next))}}}if(r===null)throw ch();if(e===0&&r.constructor!==px&&r!==t){let e=r._item,t=vS(e);if(e===null||t===null)throw ch();return yS(t,e)}}return ly(t,t._length,-1)},xS=(e,t)=>{if(!e.docChanged)return!1;if(e.doc.childCount!==t.childCount)return!0;for(let n of e.steps)if(n instanceof Et){if(n.from===0&&n.to===t.content.size)return!0;if(n.slice.content.size>0){let e=!1;if(n.slice.content.forEach(t=>{t.isBlock&&(e=!0)}),e)return!0}else if(n.to>n.from){let e=t.resolve(n.from),r=t.resolve(n.to);if(e.depth===0&&r.depth===0&&e.index()!==r.index())return!0}}return!1};function SS(e,t){if(e instanceof px)return e._length;let n=t.get(e);return n instanceof ce?n.nodeSize:null}function CS(e,t,n){let r=0,i=e._first;for(;i!==null;){let e=_S(i);if(e===t)break;let a=i.deleted;if(i=i.right,a)continue;if(e===null)return null;let o=SS(e,n);if(o===null)return null;r+=o}return r}function wS(e,t,n){let r=0,i=0,a=e._first;for(;i{if(n===null)return!1;let r=py(t,e);return r!==null&&r.type instanceof px&&t.item!==null&&r.type._item?.deleted===!0},ES=e=>{if(!e.doc)throw Error(`The Yjs fragment must belong to a document`);let t=e._item?`item:${e._item.id.client}:${e._item.id.clock}`:`root:${ny(e)}`;return e.doc.getMap(`__tiptap_position_migrations:${t}`)},DS=new WeakMap,OS=(e,t)=>{let n=t.item??t.type;if(!n)return[];let r;t.item||(r=t.assoc<0?`start`:`end`);let i=DS.get(e);if(!i||i.size!==e.size){let t=new Map;e.forEach(e=>e.transfers.forEach(n=>{let r=t.get(n.source.client)??[];r.push({migration:e,transfer:n}),t.set(n.source.client,r)})),i={size:e.size,clients:t},DS.set(e,i)}let a=(i.clients.get(n.client)??[]).filter(({transfer:e})=>e.source.boundary===r&&e.source.clock<=n.clock&&n.clock!a.some(t=>t.migration!==e.migration&&t.migration.seen.some(([t,n])=>t===e.migration.client&&n>e.migration.clock)))},kS=(e,t,n)=>{let{source:r,target:i}=e.transfer;return i?new iy(i.boundary?P(i.client,i.clock):i.type,i.tname??null,i.boundary?null:P(i.client,i.clock+t.clock-r.clock),i.assoc??n):null},AS=(e,t,n)=>{let r=kS(e[0],t,n);return!r||e.some(e=>{let i=kS(e,t,n);return!i||!my(r,i)})?null:r},jS=e=>{let t=e.item??e.type;if(!t)return null;let n=e.assoc<0?`start`:`end`;return e.item&&(n=`item`),`${t.client}:${t.clock}:${n}`},MS=(e,t)=>{let n=ES(e),r=new Set,i=t,a=i.item??i.type;for(;a;){let e=jS(i);if(r.has(e))return null;r.add(e);let t=OS(n,i);if(t.length===0)return i;let o=AS(t,a,i.assoc);if(!o)return null;if(jS(o)===e)return o;i=o,a=o.item??o.type}return i},NS=(e,t,n,r)=>{let i=MS(t,n);if(!i)return null;n=i;let a=py(n,e);if(a===null||a.type!==t&&!ry(t,a.type._item))return null;let o=a.type,s=0;if(o.constructor===px)s=a.index;else if(!o._item?.deleted){let e=wS(o,a.index,r);if(e===null)return null;s=e+1}for(;o!==t&&o._item!==null;){let e=vS(o._item);if(e===null)return null;if(e._item?.deleted){o=e;continue}let t=CS(e,o,r);if(t===null)return null;s+=t+1,o=e}let c=s-1;return TS(e,n,c)?null:c},PS=new O(`y-sync`),FS=new O(`y-undo`),IS=new O(`yjs-cursor`),LS=null;function RS(){let e=LS;LS=null;let t=[];return e?.forEach((e,n)=>{e.forEach((e,r)=>t.push({view:n,key:r,value:e}))}),t}function zS(e=RS(),t=!1){let n=!0;for(;e.length>0;){let{view:r,key:i,value:a}=e[0];try{let e=PS.getState(r.state);e&&e.binding.prosemirrorView!==null&&r.dispatch(r.state.tr.setMeta(i,a))}catch(r){if(!(r instanceof RangeError))throw r;t&&n&&e.shift(),e.length>0&&H_(0,()=>zS(e,!0));return}n=!1,e.shift()}}function BS(e,t,n){LS===null&&(LS=new Map,H_(0,zS));let r=LS.get(e);r||(r=new Map,LS.set(e,r)),r.set(t,n)}var VS=(e,t,n)=>e!==t,HS=e=>{let t=document.createElement(`span`);t.classList.add(`ProseMirror-yjs-cursor`),t.setAttribute(`style`,`border-color: ${e.color}`);let n=document.createElement(`div`);n.setAttribute(`style`,`background-color: ${e.color}`),n.insertBefore(document.createTextNode(e.name),null);let r=document.createTextNode(`⁠`),i=document.createTextNode(`⁠`);return t.insertBefore(r,null),t.insertBefore(n,null),t.insertBefore(i,null),t},US=e=>({style:`background-color: ${e.color}70`,class:`ProseMirror-yjs-selection`}),WS=/^#[0-9a-fA-F]{6}$/,GS=e=>typeof e.name==`string`&&typeof e.color==`string`,KS=(e,t,n,r,i)=>{let a=PS.getState(e);if(a==null||a.doc==null||a.binding==null)return bs.create(e.doc,[]);let o=a.doc,s=[];return a.snapshot!=null||a.prevSnapshot!=null||a.binding.mapping.size===0?bs.create(e.doc,[]):(t.getStates().forEach((t,c)=>{if(n(o.clientID,c,t)&&t&&t.cursor!=null){let n={...t.user};if(n.color==null?n.color=`#ffa500`:WS.test(n.color)||console.warn(`A user uses an unsupported color format`,n),n.name??=`User: ${c}`,!GS(n))return;let l=NS(o,a.type,ay(t.cursor.anchor),a.binding.mapping),u=NS(o,a.type,ay(t.cursor.head),a.binding.mapping);if(l!==null&&u!==null){let t=gm(e.doc.content.size-1,0);l=hm(l,t),u=hm(u,t),s.push(_s.widget(u,()=>r(n,c),{key:c+``,side:10}));let a=hm(l,u),o=gm(l,u);s.push(_s.inline(a,o,i(n,c),{inclusiveEnd:!0,inclusiveStart:!1}))}}}),bs.create(e.doc,s))},qS=(e,{awarenessStateFilter:t=VS,cursorBuilder:n=HS,selectionBuilder:r=US,getSelection:i=e=>e.selection}={},a=`cursor`)=>new D({key:IS,state:{init(i,a){return KS(a,e,t,n,r)},apply(i,a,o,s){let c=PS.getState(s),l=i.getMeta(IS),u=c&&c.isChangeOrigin;return i.docChanged&&!u&&xS(i,o.doc)?bs.empty:u||l&&l.awarenessUpdated?KS(s,e,t,n,r):i.docChanged?a.map(i.mapping,i.doc):a}},props:{decorations:e=>IS.getState(e)??bs.empty},view:t=>{let n=()=>{t.isDestroyed||BS(t,IS,{awarenessUpdated:!0})},r=t=>{let n=PS.getState(t.state);if(!n||!n.binding)return;let r=e.getLocalState()||{};if(t.hasFocus()){let o=i(t.state),s=bS(o.anchor,n.type,n.binding.mapping),c=bS(o.head,n.type,n.binding.mapping);r.cursor!=null&&my(ay(r.cursor.anchor),s)&&my(ay(r.cursor.head),c)||e.setLocalStateField(a,{anchor:s,head:c})}else r.cursor!=null&&NS(n.doc,n.type,ay(r.cursor.anchor),n.binding.mapping)!==null&&e.setLocalStateField(a,null)},o=()=>r(t);return e.on(`change`,n),t.dom.addEventListener(`focusin`,o),t.dom.addEventListener(`focusout`,o),{update:r,destroy:()=>{t.dom.removeEventListener(`focusin`,o),t.dom.removeEventListener(`focusout`,o),e.off(`change`,n),e.setLocalStateField(a,null)}}}});function JS(e){let t=PS.getState(e);if(!t)throw Error(`The editor requires ySyncPlugin`);return t}var YS=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)??0)>e.id.clock&&!fv(t.ds,e.id),XS=(e,t,n)=>{if(!e.has(n)){if(e.sizen.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,jh(t))}let r=e.get(n);if(!r)throw Error(`At least one snapshot color is required`);return r},ZS=(e,t)=>{if(e===t)return!0;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])},QS=e=>{let t=e.type.spec.attrs||{};return Object.keys(e.attrs).some(n=>{let r=t[n];return r==null||!Object.prototype.hasOwnProperty.call(r,`default`)||r.default!==e.attrs[n]})},$S=(e,t,n)=>{let r=0,i=0;for(;in)break;r+=t.nodeSize}if(i>=e.childCount)return null;let a=e.child(i),o=e.resolve(n),s=(e,t)=>{if(o.depth===0){let i=e+(n-r),a=e+1,o=e+t.nodeSize-1;return Math.max(a,Math.min(i,o))}if(o.depth>1){let n=$S(o.node(1),t,o.pos-o.start(1));return n===null?null:e+1+n}return t.isTextblock?e+1+Math.min(o.parentOffset,t.content.size):null},c=(n,r=!1)=>{let a=0;for(let t=0;t<=i;t++)n(e.child(t))&&a++;let o=0,c=-1,l=null,u=0;for(let e=0;ee.type===a.type&&ZS(e.attrs,a.attrs),u=a.textContent,d=c(e=>l(e)&&e.textContent===u);if(d!==null)return d;let f=c(e=>e.type===a.type&&e.textContent===u);if(f!==null)return f;if(!a.isTextblock||QS(a)){let e=c(l,!0);if(e!==null)return e}return c(e=>l(e)&&u!==``&&e.textContent!==``&&(u.startsWith(e.textContent)||e.textContent.startsWith(u)),!0)},eC=(e,t,n,r)=>{if(r===null)return!1;let i=e.resolve(n),a=t.resolve(r);if(!i.parent.isTextblock)return!1;if(!a.parent.isTextblock||i.parent.textContent!==a.parent.textContent||i.parentOffset!==0&&a.parentOffset===0)return!0;let o=i.parentOffset===0&&a.parentOffset===0,s=i.parentOffset!==a.parentOffset||i.parent.type!==a.parent.type||!ZS(i.parent.attrs,a.parent.attrs);if(o||s){let i=$S(e,t,n);return i!==null&&i!==r}return!1},tC=(e,t,n,r)=>{if(n==null||n<0||n>t.content.size||!(r===null||n>1&&r<=1||eC(t,e,n,r)))return r;let i=$S(t,e,n);return i===null?r:i},nC=(e,t,n,r)=>{if(t!==null&&t.anchor!==null&&t.head!==null){if(t.type===`all`)e.setSelection(new Dn(e.doc));else if(t.type===`node`){let r=NS(n.doc,n.type,t.anchor,n.mapping);r!==null&&e.setSelection(rC(e,r))}else if(t.type===`nodeRange`){let r=iC(e,NS(n.doc,n.type,t.anchor,n.mapping),NS(n.doc,n.type,t.head,n.mapping),t.depth);r!==null&&e.setSelection(r)}else{let i=NS(n.doc,n.type,t.anchor,n.mapping),a=NS(n.doc,n.type,t.head,n.mapping);r!=null&&(MS(n.type,t.anchor)===t.anchor&&(i=tC(e.doc,r,t.absAnchor,i)),MS(n.type,t.head)===t.head&&(a=tC(e.doc,r,t.absHead,a))),i===null&&(i=a),a===null&&(a=i),i!==null&&a!==null&&e.setSelection(T.between(e.doc.resolve(i),e.doc.resolve(a)))}}},rC=(e,t)=>{let n=e.doc.resolve(t);return n.nodeAfter?E.create(e.doc,t):T.near(n)},iC=(e,t,n,r)=>{if(t===null||n===null)return null;let i=Math.min(Math.max(t,0),e.doc.content.size),a=Math.min(Math.max(n,0),e.doc.content.size);try{let t=w.fromJSON(e.doc,{type:`nodeRange`,anchor:i,head:a,depth:r});return t.ranges.length?t:T.near(e.doc.resolve(i))}catch{return T.near(e.doc.resolve(i))}},aC=(e,t)=>{let n=t.selection,r=n.toJSON(),i=typeof r.type==`string`?r.type:`text`;return{type:i,depth:i===`nodeRange`&&`depth`in n&&typeof n.depth==`number`?n.depth:void 0,anchor:bS(t.selection.anchor,e.type,e.mapping),head:bS(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},oC=new WeakMap,sC=(e,t)=>{var n;(t instanceof ox||t instanceof rx||t instanceof dx)&&(e.delete(t),(n=oC.get(e))==null||n.delete(t))},cC=/(.*)(--[a-zA-Z0-9+/=]{8})$/,lC=e=>cC.exec(e)?.[1]??e,uC=(e,t)=>{let n=[];for(let r in e)n.push(t.mark(lC(r),e[r]));return n},dC=e=>{let t=e.doc,n=e._item;if(!t||!n)throw ch();t.transact(e=>{n.delete(e)},PS)},fC=(e,t,n,r,i,a)=>{let o=e.toDelta(r,i,a);try{return o.map(e=>t.text(e.insert,uC(e.attributes,t)))}catch{return dC(e),null}},pC=e=>{var t;let n=(t=e._item)==null||(t=t.right)==null?void 0:t.content,r=n instanceof Wx?n.type:null;if(!(r instanceof rx))return;let i=r._item,a=r.doc;i&&a&&!i.deleted&&i.id.client===a.clientID&&(e.applyDelta([{retain:e.length},...r.toDelta()]),a.transact(e=>{i.delete(e)}))},mC=(e,t,n,r)=>{if(e._item){if(!YS(e._item,t))return r?r(`removed`,e._item.id):{type:`removed`};if(!YS(e._item,n))return r?r(`added`,e._item.id):{type:`added`}}},hC=(e,t,n)=>{e.mapping.set(t,n);let r=oC.get(e.mapping);r===void 0&&(r=new WeakMap,oC.set(e.mapping,r)),r.set(t,n)},gC=(e,t,n,r,i,a)=>{let o=n.mapping.get(e),s=Array.isArray(o)?void 0:o;if(s!==void 0&&oC.get(n.mapping)?.get(e)===s)return s;let c=[],l=e=>{if(e instanceof cx){let o=gC(e,t,n,r,i,a);o!==null&&c.push(o)}else e instanceof px&&(pC(e),fC(e,t,n,r,i,a)?.forEach(e=>c.push(e)))};r===void 0||i===void 0?e.toArray().forEach(l):vb(e,new hy(i.ds,r.sv)).forEach(l);try{let o=e.getAttributes(r),l=r?mC(e,r,i,a):void 0;l!==void 0&&(o.ychange=l);let u=t.node(e.nodeName,o,c);return s?.eq(u)&&(u=s),hC(n,e,u),u}catch{return dC(e),sC(n.mapping,e),null}},_C=e=>{for(let t=6;t_g(_C(pS(bg(e)))),yC=(e,t)=>{let n={};return e.forEach(e=>{if(e.type.name!==`ychange`){let r=em(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${vC(e.toJSON())}`:e.type.name]=e.attrs}}),n},bC=(e,t)=>{let n=new px,r=e.map(e=>({insert:e.text??``,attributes:yC(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n},xC=e=>{let t=e.content.content,n=[];for(let e=0;ee instanceof Array?bC(e,t):CC(e,t),CC=(e,t)=>{let n=new cx(e.type.name);for(let t in e.attrs){let r=e.attrs[t];r!==null&&t!==`ychange`&&n.setAttribute(t,r)}return n.insert(0,xC(e).map(e=>SC(e,t))),t.mapping.set(n,e),n},wC=e=>typeof e==`object`&&!!e,TC=(e,t)=>{let n=Object.keys(e).filter(t=>e[t]!==null),r=n.length===Object.keys(t).filter(e=>t[e]!==null).length;for(let i=0;i{let n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&Uh(e.attributes||{}).length===t[n].marks.length&&Object.entries(e.attributes??{}).every(([e,r])=>{let i=lC(e),a=t[n].marks.find(e=>e.type.name===i);return a?TC(r,a.attrs):!1}))},DC=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,OC=(e,t)=>{if(e instanceof cx&&!(t instanceof Array)&&DC(e,t)){let n=xC(t);return e._length===n.length&&TC(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>OC(e,n[t]))}return e instanceof px&&t instanceof Array&&EC(e,t)},kC=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),AC=(e,t,n)=>{let r=new Map;t.forEach((e,t)=>{r.has(e)||r.set(e,t)});let i=[];if(e.forEach((e,a)=>{let o=n.mapping.get(e),s=o===void 0?void 0:r.get(o);s!==void 0&&kC(o,t[s])&&i.push({yIndex:a,pIndex:s,yChild:e})}),i.length===0)return[];let a=[],o=[];for(let e=0;e>1;i[o[r]].pIndex0?o[t-1]:-1,o[t]=e}let s=[];for(let e=o[o.length-1];e!==-1;e=a[e])s.push(i[e]);return s.reverse()},jC=e=>{let t=``,n=e._start,r={};for(;n!==null;)n.deleted||(n.countable&&n.content instanceof Px?t+=n.content.str:n.content instanceof Dx&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}},MC=(e,t,n)=>{n.mapping.set(e,t);let{nAttrs:r,str:i}=jC(e),a=t.map(e=>({insert:e.text??``,attributes:Object.assign({},r,yC(e.marks,n))})),{insert:o,remove:s,index:c}=gS(i,a.map(e=>e.insert).join(``));e.delete(c,s),e.insert(c,o),e.applyDelta(a.map(e=>({retain:e.insert.length,attributes:e.attributes})))},NC=(e,t,n,r,i)=>t instanceof px&&n instanceof Array?(EC(t,n)?r.mapping.set(t,n):MC(t,n,r),!0):t instanceof cx&&!(n instanceof Array)&&DC(t,n)?(OC(t,n)?r.mapping.set(t,n):i(e,t,n,r),!0):!1,PC=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>sC(r.mapping,e)),e.delete(t,n))},FC=(e,t,n,r,i,a)=>{if(r{let u=hm(a-i,s-o);for(let a=0;a{let o=AC(r,n,i);if(o.length<2||!o.some(e=>e.yIndex!==e.pIndex)||o.some(e=>{let t=n[e.pIndex];return!(e.yChild instanceof px&&t instanceof Array||e.yChild instanceof cx&&!(t instanceof Array))}))return!1;let s=0,c=0;for(let l of o){IC(e,t,n,r,s,l.yIndex,c,l.pIndex,i,a);let o=n[l.pIndex];NC(e,l.yChild,o,i,a),s=l.yIndex+1,c=l.pIndex+1}return IC(e,t,n,r,s,r.length,c,n.length,i,a),!0},RC=(e,t,n)=>{let r=e.toArray(),i=xC(t),a=i.length,o=r.length,s=hm(o,a),c=0,l=0,u=!1;for(;c{if(t instanceof cx&&t.nodeName!==n.type.name)throw Error(`node name mismatch!`);if(r.mapping.set(t,n),t instanceof cx){let e=t.getAttributes(),r=n.attrs;for(let n in r)r[n]===null?t.removeAttribute(n):e[n]!==r[n]&&n!==`ychange`&&t.setAttribute(n,r[n]);for(let n in e)r[n]===void 0&&t.removeAttribute(n)}let i=xC(n),a=i.length,o=t.toArray(),s=o.length,c=hm(a,s),l=!1;if(e.transact(()=>{l=LC(e,t,i,o,r,zC)},PS),l)return;let u=0,d=0;for(;u{for(;s-u-d>0&&a-u-d>0;){let n=o[u],c=i[u],l=o[s-d-1],f=i[a-d-1];if(n instanceof px&&c instanceof Array){EC(n,c)||MC(n,c,r),u+=1;continue}let p=n instanceof cx&&DC(n,c),m=l instanceof cx&&DC(l,f);if(p&&m&&n instanceof cx&&l instanceof cx&&!Array.isArray(c)&&!Array.isArray(f)){let e=RC(n,c,r),t=RC(l,f,r);e.foundMappedChild&&!t.foundMappedChild?m=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor0&&(t.slice(u,u+n).forEach(e=>sC(r.mapping,e)),t.delete(u,n)),u+d>=a)return;let c=[];for(let e=u;e{let n=[];if(!e._item)throw Error(`Position tracking requires integrated text`);for(let r=e._start;r;r=r.right)if(!r.deleted&&r.countable){if(!(r.content instanceof Px))throw Error(`Position tracking requires string text content`);for(let i=0;i{let r=[{current:-1,target:-1}];return e.forEach((e,n)=>{let i=t.get(`${e.client}:${e.clock}`);i!==void 0&&i>r[r.length-1].target&&r.push({current:n,target:i})}),r.push({current:e.length,target:n}),r},HC=(e,t,n,r,i)=>{let a=BC(e),o=new Map;for(let e=0;e0;--n){let r=s[n-1],o=s[n],c=a.slice(r.current+1,o.current),l=t.slice(r.target+1,o.target);(c.some(e=>i.has(`${e.client}:${e.clock}`))||c.map(e=>e.text).join(``)!==l)&&(e.delete(r.current+1,c.length),e.insert(r.current+1,l))}return BC(e,n)},UC=(e,t)=>!e.target||!t.target?e.target===t.target:e.target.client===t.target.client&&e.target.assoc===t.target.assoc&&e.target.boundary===t.target.boundary&&e.target.tname===t.target.tname&&e.target.clock+e.source.length===t.target.clock&&ey(e.target.type,t.target.type),WC=e=>{let t=[];return e.forEach(e=>{let n=t[t.length-1];n&&n.source.client===e.source.client&&n.source.boundary===e.source.boundary&&n.source.clock+n.source.length===e.source.clock&&UC(n,e)?n.source.length+=e.source.length:t.push({...e,source:{...e.source}})}),t},GC=(e,t)=>{let n=e.doc;if(!n||t.length===0)return;let r=Cy(n.store,n.clientID);e.set(`${n.clientID}:${r}`,{version:1,client:n.clientID,clock:r,seen:[...Uv(qv(n))],transfers:WC(t)})},KC=(e,t)=>{let n=new Map;e.forEach(e=>{let t=`${e.type.client}:${e.type.clock}`,r=n.get(t)??[];r.push(e),n.set(t,r)});let r=[];return n.forEach(e=>{let n=e[0],i=e[e.length-1],a=n.position===null?void 0:t.get(n.position),o=i.position===null?void 0:t.get(i.position);a&&ey(n.type,a.type)||r.push({source:{...n.type,length:1,boundary:`start`},target:a?{...a,assoc:0}:null}),o&&ey(i.type,o.type)||r.push({source:{...n.type,length:1,boundary:`end`},target:o?{...o,assoc:-1}:null})}),r},qC=(e,t,n,r)=>{let i=[];e.forEach(e=>{let n=e.position===null?null:t.get(e.position)??null;n&&ey(e.id,n)||i.push({source:{...e.id,length:1},target:n})});let a=[...e,...r];for(let e of[`start`,`end`]){let r=e===`start`?t:n;a.forEach(t=>{let n=e===`start`?t.position:t.end,a=n===null?null:r.get(n)??null;a&&ey(t.id,a)||i.push({source:{...t.id,length:1,boundary:e},target:a?{client:a.client,clock:a.clock,type:null,boundary:e}:null})})}return i},JC=(e,t,n,r,i,a)=>{let o=e.get(t);if(!(o instanceof cx)||!o._item)throw Error(`Position migration requires synchronized elements`);let s=i.get(`${o._item.id.client}:${o._item.id.clock}`);if(s&&s.position!==r&&(sC(a.mapping,o),e.delete(t,1),o=SC(n,a),e.insert(t,[o])),!(o instanceof cx)||!o._item)throw Error(`Position migration requires integrated elements`);return o},YC=(e,t,n,r)=>{let i=new Map(t.characters.map(e=>[e.position,e])),a=new Set(t.characters.map(e=>`${e.client}:${e.clock}`)),o=new Map,s=new Map(t.nodes.map(e=>[`${e.id.client}:${e.id.clock}`,e])),c=new Map,l=new Map,u=(e,t,r)=>{let d=e.toArray(),f=r;xC(t).forEach((t,r)=>{let p=d[r];if(Array.isArray(t)){if(!(p instanceof px)||!p._item)throw Error(`Position migration requires integrated text`);let e=t.map(e=>e.text??``).join(``),r=HC(p,e,f,i,a),s=p._item.id;r.forEach(e=>o.set(e.position,{client:e.client,clock:e.clock,type:s})),MC(p,t,n),f+=e.length;return}let m=JC(e,r,t,f,s,n),h=m._item.id,g={client:h.client,clock:h.clock,type:e._item?.id??null,...e._item?{}:{tname:ny(e)}};c.set(f,g),l.set(f+t.nodeSize-1,g),t.isLeaf||u(m,t,f+1),f+=t.nodeSize})};u(e,t.doc,0);let d=[];t.characters.forEach(e=>{let t=e.position===null?null:o.get(e.position)??null;t&&ey(e,t)&&ey(e.type,t.type)||d.push({source:{client:e.client,clock:e.clock,length:1},target:t})}),d.push(...KC(t.characters,o)),d.push(...qC(t.nodes,c,l,t.emptyTexts)),GC(r,d)},XC=(e,t)=>{let n=e.doc.content,r=0,i=0;for(;rr&&o>r&&n.child(a-1)===t.child(o-1);)s+=n.child(a-1).nodeSize,a--,o--;if(r===a&&r===o)return e;let c=new p(t.cut(i,t.size-s),0,0),l=en(e.doc,i,n.size-s,c);return l!==null&&l.apply(e.doc).doc?.content.eq(t)?e.step(l):e.replace(0,n.size,new p(t,0,0))},ZC=class{constructor(e,t=new Map){if(this.prosemirrorView=null,this.mux=iS(),this.isOMark=new Map,this.beforeTransactionSelection=null,this._domSelectionInView=null,this.syncedDoc=null,this.type=e,this.mapping=t,this._observeFunction=this._typeChanged.bind(this),e.doc===null)throw Error(`The Yjs fragment must belong to a document`);this.doc=e.doc,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=aC(this,this.view.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null}}get view(){if(!this.prosemirrorView)throw Error(`The binding has no editor view`);return this.prosemirrorView}get _tr(){return this.view.state.tr.setMeta(`addToHistory`,!1)}_isLocalCursorInView(){return this.view.hasFocus()?(rg&&this._domSelectionInView===null&&(H_(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.view.root,t=`getSelection`in e&&typeof e.getSelection==`function`?e.getSelection():this.view.dom.ownerDocument.getSelection();if(t==null||t.anchorNode==null||t.focusNode==null)return!1;let n=this.view.dom.ownerDocument.createRange();n.setStart(t.anchorNode,t.anchorOffset),n.setEnd(t.focusNode,t.focusOffset),n.getClientRects().length===0&&n.startContainer&&n.collapsed&&n.selectNodeContents(n.startContainer);let r=n.getBoundingClientRect(),i=F_.documentElement;return r.bottom>=0&&r.right>=0&&r.left<=(window.innerWidth||i.clientWidth||0)&&r.top<=(window.innerHeight||i.clientHeight||0)}renderSnapshot(e,t){t||=gy(gv(),new Map),this.view.dispatch(this._tr.setMeta(PS,{snapshot:e,prevSnapshot:t}))}createDocumentTransaction(){let e=this.type.toArray().map(e=>{if(!(e instanceof cx))throw sh();return gC(e,this.view.state.schema,this)}).filter(e=>e!==null);return this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(e),0,0))}unrenderSnapshot(){this.mapping.clear(),oC.delete(this.mapping),this.mux(()=>{let e=this.createDocumentTransaction();e.setMeta(PS,{snapshot:null,prevSnapshot:null}),this.view.dispatch(e)})}_forceRerender(){this.mapping.clear(),oC.delete(this.mapping),this.mux(()=>{let e=this.beforeTransactionSelection===null?this.view.state.selection:null,t=this.createDocumentTransaction();if(e){let n=hm(gm(e.anchor,0),t.doc.content.size),r=hm(gm(e.head,0),t.doc.content.size);t.setSelection(T.create(t.doc,n,r))}this.view.dispatch(t.setMeta(PS,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,i=this.type;if(e||=vy(this.doc),e instanceof Uint8Array||t instanceof Uint8Array){if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array))throw ch();if(r=new Sv({gc:!1}),Lv(r,t),t=vy(r),Lv(r,e),e=vy(r),i._item===null){let e=Array.from(this.doc.share.keys()).find(e=>Object.is(this.doc.share.get(e),i));i=r.getXmlFragment(e)}else{let e=r.store.clients.get(i._item.id.client)??[],t=e[Ty(e,i._item.id.clock)];if(!(t instanceof Zx&&t.content instanceof Wx&&t.content.type instanceof ox))throw ch();i=t.content.type}}let a=e,o=t??_y;this.mapping.clear(),oC.delete(this.mapping),this.mux(()=>{r.transact(e=>{let t=n.permanentUserData;t&&t.dss.forEach(t=>{uv(e,t,e=>{})});let r=(e,r)=>{let i=t?e===`added`?t.getUserByClientId(r.client):t.getUserByDeletedId(r):null;return{user:i,type:e,color:XS(n.colorMapping,n.colors,i)}},c=vb(i,new hy(o.ds,a.sv)).map(e=>!(e instanceof cx)||!e._item?null:!e._item.deleted||YS(e._item,a)||YS(e._item,o)?gC(e,this.view.state.schema,{mapping:new Map,isOMark:new Map},a,o,r):null).filter(e=>e!==null),l=this._tr.replace(0,this.view.state.doc.content.size,new p(s.from(c),0,0));this.view.dispatch(l.setMeta(PS,{isChangeOrigin:!0}))},PS)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let n=JS(this.view.state);if(e.length===0||n.snapshot!=null||n.prevSnapshot!=null){this.renderSnapshot(n.snapshot,n.prevSnapshot);return}let r=t.origin instanceof Uy,i=r?t.origin.currStackItem?.meta.get(this):void 0,a=i||this.beforeTransactionSelection,o=i?void 0:this.view.state.doc;this.mux(()=>{let e=(e,t)=>sC(this.mapping,t);uv(t,t.deleteSet,e=>{e instanceof Zx&&e.content instanceof Wx&&sC(this.mapping,e.content.type)}),t.changed.forEach(e),t.changedParentTypes.forEach(e);let n=this.type.toArray().map(e=>{if(!(e instanceof cx))throw sh();return gC(e,this.view.state.schema,this)}).filter(e=>e!==null),i=XC(this._tr,s.from(n));nC(i,a,this,o),i=i.setMeta(PS,{isChangeOrigin:!0,isUndoRedoOperation:r}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&i.scrollIntoView(),this.view.dispatch(i)})}_prosemirrorChanged(e,t=null){let n=JS(this.view.state);n.snapshot==null&&n.prevSnapshot==null&&this.doc.transact(()=>{zC(this.doc,this.type,e,this),t?.doc===e&&YC(this.type,t,this,ES(this.type)),this.syncedDoc=e,this.beforeTransactionSelection=aC(this,this.view.state)},PS)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on(`beforeAllTransactions`,this.beforeAllTransactions),this.doc.on(`afterAllTransactions`,this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off(`beforeAllTransactions`,this.beforeAllTransactions),this.doc.off(`afterAllTransactions`,this.afterAllTransactions))}},QC=(e,t)=>{let n=[],r=[],i=[];if(e.length===0)return{characters:n,nodes:r,emptyTexts:i};let a=(e,t,o)=>{let s=e.toArray(),c=xC(t),l=o;t.content.size===0&&s.forEach(e=>{e instanceof px&&e._item&&i.push({id:e._item.id,position:o-1,end:o})}),c.forEach((e,t)=>{let i=s[t];if(!Array.isArray(e)){if(!(i instanceof cx)||!i._item)throw Error(`Position tracking requires synchronized editor content`);r.push({id:i._item.id,position:l,end:l+e.nodeSize-1}),e.isLeaf||a(i,e,l+1),l+=e.nodeSize;return}if(!(i instanceof px))throw Error(`Position tracking requires synchronized editor text`);let o=BC(i,l);n.push(...o),l+=o.length})};return a(e,t,0),{characters:n,nodes:r,emptyTexts:i}},$C=(e,t,n,r)=>{let i=e.toJSON();if(i.stepType!==`replace`&&i.stepType!==`replaceAround`||r!==i.from&&r!==i.to-1)return!1;let a=t.nodeAt(i.from),o=n.nodeAt(i.from);return!a||!o||a.nodeSize!==i.to-i.from?!1:ew(a,o)},ew=(e,t)=>e.type===t.type&&e.content.eq(t.content)&&!e.sameMarkup(t),tw=(e,t)=>{let n=e.toJSON(),r=n.slice??{content:[]};if(n.stepType!==`replace`||r.openStart>0||r.openEnd>0)return!1;let i=t.resolve(n.from),a=t.resolve(n.to);return r.content.every(e=>e.type===`text`)&&i.parent.isTextblock&&i.sameParent(a)},nw=e=>{let t=new Map;return e.descendants((e,n)=>{let r=t.get(e)??[];r.push(n),t.set(e,r)}),t},rw=(e,t,n,r)=>{if(r[n].get(e)?.length!==1)return null;for(let i=n+1;i{let i=n[t].resolve(e),a=[],o=n[t].nodeAt(e);o&&!o.isText&&a.push({node:o,offset:0});for(let t=i.depth;t>0;--t)a.push({node:i.node(t),offset:e-i.before(t)});for(let e of a){let n=rw(e.node,e.offset,t,r);if(n)return n}return null},aw=(e,t,n,r)=>{for(let i=0;i{let r=n?.doc===e.before&&n.doc!==t.syncedDoc?n:null;if(!e.docChanged||!t.prosemirrorView||!r&&e.steps.every((t,n)=>tw(t,e.docs[n])))return r;let i=r??QC(t.type,e.before),a=[...e.docs,e.doc],o=a.map(nw),s=i.characters.map(t=>({...t,position:t.position===null?null:aw(t.position,e,a,o)})),c=t=>({...t,position:t.position===null?null:aw(t.position,e,a,o),end:t.end===null?null:aw(t.end,e,a,o)});return{doc:e.doc,characters:s,nodes:i.nodes.map(c),emptyTexts:i.emptyTexts.map(c)}},sw=[{light:`#ecd44433`,dark:`#ecd444`}],cw=(e,{colors:t=sw,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:a}={})=>{let o=!1,s=new ZC(e,a);return new D({props:{editable:e=>{let t=JS(e);return t.snapshot==null&&t.prevSnapshot==null}},key:PS,state:{init:(i,a)=>({type:e,doc:s.doc,binding:s,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:r,positionMigration:null}),apply:(e,t)=>{let n=e.getMeta(PS);return n!==void 0&&(t=Object.assign({},t,n)),e.docChanged&&(t.addToHistory=e.getMeta(`addToHistory`)!==!1),t.isChangeOrigin=n!==void 0&&!!n.isChangeOrigin,t.isUndoRedoOperation=n!==void 0&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,t={...t,positionMigration:t.isChangeOrigin||t.snapshot||t.prevSnapshot||n?.snapshot!==void 0||n?.prevSnapshot!==void 0?null:ow(e,s,t.positionMigration??null)},s.prosemirrorView===null||n===void 0||n.snapshot==null&&n.prevSnapshot==null||H_(0,()=>{s.prosemirrorView!=null&&(n.restore==null?s._renderSnapshot(n.snapshot,n.prevSnapshot,t):(s._renderSnapshot(n.snapshot,n.snapshot,t),s.mux(()=>{let e=s.prosemirrorView;e&&(e.dispatch(s._tr.setMeta(PS,{restore:!1,snapshot:null,prevSnapshot:null,isChangeOrigin:!0})),s._prosemirrorChanged(e.state.doc))})))}),t}},view:e=>(s.initView(e),a??s._forceRerender(),i(),{update:()=>{let t=JS(e.state);if(t.snapshot==null&&t.prevSnapshot==null){let n=e.state.doc.type.createAndFill();if(!n)throw Error(`The schema cannot create an empty document`);if(o||e.state.doc.content.findDiffStart(n.content)!==null){if(o=!0,t.addToHistory===!1&&!t.isChangeOrigin){let t=FS.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}s.mux(()=>{t.doc.transact(n=>{n.meta.set(`addToHistory`,t.addToHistory),s._prosemirrorChanged(e.state.doc,t.positionMigration??null)},PS)})}}},destroy:()=>{s.destroy()}})})};function lw(e){let t=FS.getState(e);if(!t)throw Error(`The editor requires yUndoPlugin`);return t}var uw=e=>{let t=new Map,n=e=>{e.toArray().forEach(r=>{if(r instanceof cx){let i=r._item.id;t.set(`${i.client}:${i.clock}`,{client:i.client,clock:i.clock,type:e._item?.id??null,...e._item?{}:{tname:ny(e)}}),n(r);return}if(!(r instanceof px)||!r._item)return;let i=r._item.id;BC(r).forEach(e=>{t.set(`${e.client}:${e.clock}`,{client:e.client,clock:e.clock,type:i})})})};return n(e),t},dw=(e,t)=>{let n=e.doc;if(!n)return;let r=uw(e),i=new Map,a=new Map,o=(e,t)=>{let n=`${e.client}:${e.clock}`,r=`${t.client}:${t.clock}`;i.set(n,e),i.set(r,t);let o=a.get(n)??new Set,s=a.get(r)??new Set;o.add(r),s.add(n),a.set(n,o),a.set(r,s)};t.forEach(e=>e.transfers.forEach(({source:e,target:t})=>{if(t&&!e.boundary)for(let n=0;ne.forEach(e=>{if(e instanceof Zx&&e.redone&&(e.content instanceof Px||e.content instanceof Wx))for(let t=0;t{if(c.has(t))return;let o=[t],l=[],u=[];for(;o.length>0;){let e=o.pop();if(c.has(e))continue;c.add(e),l.push(e);let t=r.get(e);t&&u.push(t),o.push(...a.get(e)??[])}u.length===1&&l.forEach(e=>{if(r.has(e))return;let t=i.get(e);s.push({source:{client:t.client,clock:t.clock,length:1},target:u[0]});let a=Ey(n.store,t);if(a.content instanceof Wx&&a.content.type instanceof cx)for(let e of[`start`,`end`])s.push({source:{client:t.client,clock:t.clock,length:1,boundary:e},target:{client:u[0].client,clock:u[0].clock,type:null,boundary:e}})})}),GC(t,s)},fw=(e,t,n)=>{let r=ES(e);if(r.size===0)return t[n]();let i=n===`undo`?`undoing`:`redoing`,a=null,o=({stackItem:e})=>{a=e};t.on(`stack-item-popped`,o);try{t.doc.transact(()=>{t[n](),t[i]=!0,t.currStackItem=a,a&&dw(e,r)},t)}finally{t.off(`stack-item-popped`,o),t[i]=!1,t.currStackItem=null}return a},pw=(e,t)=>{let n=JS(e);if(n.snapshot!=null||n.prevSnapshot!=null)return!1;let r=lw(e).undoManager;if(r!=null)return fw(n.type,r,t),!0},mw=e=>pw(e,`undo`),hw=e=>pw(e,`redo`),gw=new Set([`paragraph`]),_w=(e,t)=>!(e instanceof Zx)||!(e.content instanceof Wx)||!(e.content.type instanceof rx||e.content.type instanceof cx&&t.has(e.content.type.nodeName))||e.content.type._length===0,vw=({protectedNodes:e=gw,trackedOrigins:t=[],undoManager:n=null}={})=>new D({key:FS,state:{init:(r,i)=>{let a=JS(i),o=new Set,s=n;if(!s){let n=new Set(a.doc._observers.get(`destroy`));s=new Uy(a.type,{trackedOrigins:new Set([PS,...t]),deleteFilter:t=>_w(t,e),captureTransaction:e=>e.meta.get(`addToHistory`)!==!1}),(a.doc._observers.get(`destroy`)??new Set).forEach(e=>{n.has(e)||o.add(e)})}return{undoManager:s,prevSel:null,hasUndoOps:s.undoStack.length>0,hasRedoOps:s.redoStack.length>0,destroyListeners:o}},apply:(e,t,n,r)=>{let i=JS(r).binding;return{...t,prevSel:i?aC(i,n):t.prevSel,hasUndoOps:t.undoManager.undoStack.length>0,hasRedoOps:t.undoManager.redoStack.length>0}}},view:e=>{let t=JS(e.state),{undoManager:n,destroyListeners:r}=lw(e.state);return n.on(`stack-item-added`,({stackItem:r})=>{let i=t.binding;if(i){let t=n.undoing||n.redoing?i.beforeTransactionSelection:lw(e.state).prevSel;r.meta.set(i,t)}}),{destroy:()=>{n.destroy(),r.forEach(e=>n.doc.off(`destroy`,e)),r.clear()}}}});function yw(e,t){let n=t||new ox;return zC(n.doc??{transact:e=>e()},n,e,{mapping:new Map,isOMark:new Map}),n}function bw(e){let t=e.toArray(),n=e=>{let t;if(e instanceof px)t=e.toDelta().map(e=>{let t={type:`text`,text:e.insert},n=e.attributes;return n&&(t.marks=Object.keys(n).map(e=>{let t=n[e],r={type:lC(e)};return Object.keys(t).length&&(r.attrs=t),r})),t});else if(e instanceof cx){t={type:e.nodeName};let r=e.getAttributes();Object.keys(r).length&&(t.attrs=r);let i=e.toArray();i.length&&(t.content=i.map(n).flat())}else ch();return t};return{type:`doc`,content:t.map(n)}}function xw(e,t,n){return yw(ce.fromJSON(e,t),n)}function Sw(e){return!!e.getMeta(PS)}function Cw(e,t){if(t===null)return 0;let n=Tw(e);return NS(n.doc,n.type,t,n.binding.mapping)||0}function ww(e,t){let n=Tw(e);return bS(t,n.type,n.binding.mapping)}function Tw(e){let t=PS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs sync plugin`);return t}var Ew=class e extends hd{constructor(e,t){super(e),this.yRelativePosition=t}static fromJSON(t){return new e(t.position,t.yRelativePosition)}toJSON(){return{position:this.position,yRelativePosition:this.yRelativePosition}}};function Dw(e,t){return new Ew(e,ww(t,e))}function Ow(e,t,n){let r=e instanceof Ew?e.yRelativePosition:null;if(Sw(t)&&r)return{position:new Ew(Cw(n,r),r),mapResult:null};let i=gd(e,t),a=i.position.position;return{position:new Ew(a,r??ww(n,a)),mapResult:i.mapResult}}function kw(e){let t=FS.getState(e);if(!t)throw Error(`Collaboration requires the Yjs undo plugin`);return t.undoManager}var Aw=wp.create({name:`collaboration`,priority:1e3,addOptions(){return{document:null,field:`default`,fragment:null,provider:null}},addStorage(){return{isDisabled:!1}},onCreate(){this.editor.extensionManager.extensions.find(e=>e.name===`undoRedo`)&&console.warn(`[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-undo-redo".`)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>Ow(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>Dw(e,this.editor.state)},addCommands(){return{undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),kw(t).undoStack.length===0?!1:n?mw(t)??!1:!0),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta(`preventDispatch`,!0),kw(t).redoStack.length===0?!1:n?hw(t)??!1:!0)}},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){let e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=vw(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{let t=kw(e.state);t.restore&&=(t.restore(),()=>{});let r=n?n(e):void 0;return{destroy:()=>{let e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on(`afterTransaction`,t.afterTransactionHandler),t._observers=n},r?.destroy&&r.destroy()}}},[cw(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,new D({filterTransaction:(e,t)=>(e.getMeta(`inputRule`)&&kw(t).stopCapturing(),!0)}),this.editor.options.enableContentCheck&&new D({key:new O(`filterInvalidContent`),filterTransaction:t=>{if(!Sw(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(t){return this.storage.isDisabled=!0,this.editor.emit(`contentError`,{error:t,editor:this.editor,disableCollaboration:()=>{var t;(t=e.doc)==null||t.destroy()}}),!0}}})].filter(e=>e!==!1)}}),jw=e=>Array.from(e.entries()).map(([e,t])=>t&&t.user?{clientId:e,...t.user}:{clientId:e}),Mw=()=>null,Nw=e=>Nf(e)&&/^#[0-9a-fA-F]{6}$/.test(e),Pw=e=>({...e,color:Nw(e.color)?e.color:`transparent`}),Fw=wp.create({name:`collaborationCaret`,priority:999,addOptions(){return{provider:null,user:{name:null,color:null},render:e=>{let t=document.createElement(`span`),{color:n}=Pw(e);t.classList.add(`collaboration-carets__caret`),t.style.borderColor=n;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.style.backgroundColor=n,r.insertBefore(document.createTextNode(e.name),null),t.insertBefore(r,null),t},selectionRender:e=>Nw(e.color)?US({name:e.name,color:e.color}):{},onUpdate:Mw}},onCreate(){if(this.options.onUpdate!==Mw&&console.warn('[tiptap warn]: DEPRECATED: The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCaret.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret'),!this.options.provider)throw Error(`The "provider" option is required for the CollaborationCaret extension`)},addStorage(){return{users:[]}},addCommands(){return{updateUser:e=>()=>(this.options.provider.awareness.setLocalStateField(`user`,e),!0),user:e=>({editor:t})=>(console.warn(`[tiptap warn]: DEPRECATED: The "user" command is deprecated. Please use "updateUser" instead. Read more: https://tiptap.dev/api/extensions/collaboration-caret`),t.commands.updateUser(e))}},addProseMirrorPlugins(){let{provider:e}=this.options,t=this.storage,n=this.options.user;return[new D({key:new O(`collaborationCaretAwarenessListener`),view:()=>{let r=()=>{t.users=jw(e.awareness.states)};return e.awareness.setLocalStateField(`user`,n),t.users=jw(e.awareness.states),e.awareness.on(`update`,r),{destroy:()=>{e.awareness.off(`update`,r),t.users=[]}}}}),qS(e.awareness,{cursorBuilder:e=>this.options.render(Pw(e)),selectionBuilder:e=>this.options.selectionRender(Pw(e))})]}});function Iw(e={}){return new D({view(t){return new Lw(t,e)}})}var Lw=class{constructor(e,t){this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.lastDragEvent=null,this.width=t.width??1,this.color=t.color===!1?void 0:t.color||`black`,this.class=t.class,this.handlers=[`dragover`,`dragend`,`drop`,`dragleave`].map(t=>{let n=e=>{this[t](e)};return e.dom.addEventListener(t,n),{name:t,handler:n}})}destroy(){this.setCursor(null),this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){if(this.cursorPos!=null&&t.doc!=e.state.doc){if(this.lastDragEvent){let e=this.computeTarget(this.lastDragEvent);e==this.cursorPos?this.updateOverlay():this.setCursor(e)}else this.updateOverlay()}}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,n,r=this.editorView.dom,i=r.getBoundingClientRect(),a=i.width/r.offsetWidth,o=i.height/r.offsetHeight;if(t){let t=e.nodeBefore,r=e.nodeAfter;if(t||r){let e=this.editorView.nodeDOM(this.cursorPos-(t?t.nodeSize:0));if(e){let i=e.getBoundingClientRect(),a=t?i.bottom:i.top;t&&r&&(a=(a+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let s=this.width/2*o;n={left:i.left,right:i.right,top:a-s,bottom:a+s}}}}if(!n){let e=this.editorView.coordsAtPos(this.cursorPos),t=this.width/2*a;n={left:e.left-t,right:e.left+t,top:e.top,bottom:e.bottom}}let s=this.editorView.dom.offsetParent;this.element||(this.element=s.appendChild(document.createElement(`div`)),this.class&&(this.element.className=this.class),this.element.style.cssText=`position: absolute; z-index: 50; pointer-events: none;`,this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle(`prosemirror-dropcursor-block`,t),this.element.classList.toggle(`prosemirror-dropcursor-inline`,!t);let c,l;if(!s||s==document.body&&getComputedStyle(s).position==`static`)c=-pageXOffset,l=-pageYOffset;else{let e=s.getBoundingClientRect(),t=e.width/s.offsetWidth,n=e.height/s.offsetHeight;c=e.left-s.scrollLeft*t,l=e.top-s.scrollTop*n}this.element.style.left=(n.left-c)/a+`px`,this.element.style.top=(n.top-l)/o+`px`,this.element.style.width=(n.right-n.left)/a+`px`,this.element.style.height=(n.bottom-n.top)/o+`px`}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}computeTarget(e){let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),n=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=n&&n.type.spec.disableDropCursor,i=typeof r==`function`?r(this.editorView,t,e):r;if(!t||i)return null;let a=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let e=$t(this.editorView.state.doc,a,this.editorView.dragging.slice);e!=null&&(a=e)}return a}dragover(e){if(!this.editorView.editable)return;this.lastDragEvent=e;let t=this.computeTarget(e);t!=null&&(this.setCursor(t),this.scheduleRemoval(5e3))}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}},Rw=class e extends w{constructor(e){super(e,e)}map(t,n){let r=t.resolve(n.map(this.head));return e.valid(r)?new e(r):w.near(r)}content(){return p.empty}eq(t){return t instanceof e&&t.head==this.head}toJSON(){return{type:`gapcursor`,pos:this.head}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for GapCursor.fromJSON`);return new e(t.resolve(n.pos))}getBookmark(){return new zw(this.anchor)}static valid(e){let t=e.parent;if(t.inlineContent||!Vw(e)||!Hw(e))return!1;let n=t.type.spec.allowGapCursor;if(n!=null)return n;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(t,n,r=!1){search:for(;;){if(!r&&e.valid(t))return t;let i=t.pos,a=null;for(let r=t.depth;;r--){let o=t.node(r);if(n>0?t.indexAfter(r)0){a=o.child(n>0?t.indexAfter(r):t.index(r)-1);break}if(r==0)return null;i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}for(;;){let o=n>0?a.firstChild:a.lastChild;if(!o){if(a.isAtom&&!a.isText&&!E.isSelectable(a)){t=t.doc.resolve(i+a.nodeSize*n),r=!1;continue search}break}a=o,i+=n;let s=t.doc.resolve(i);if(e.valid(s))return s}return null}}};Rw.prototype.visible=!1,Rw.findFrom=Rw.findGapCursorFrom,w.jsonID(`gapcursor`,Rw);var zw=class e{constructor(e){this.pos=e}map(t){return new e(t.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return Rw.valid(t)?new Rw(t):w.near(t)}};function Bw(e){return e.isAtom||e.spec.isolating||e.spec.createGapCursor}function Vw(e){for(let t=e.depth;t>=0;t--){let n=e.index(t),r=e.node(t);if(n==0){if(r.type.spec.isolating)return!0}else for(let e=r.child(n-1);;e=e.lastChild){if(e.childCount==0&&!e.inlineContent||Bw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Hw(e){for(let t=e.depth;t>=0;t--){let n=e.indexAfter(t),r=e.node(t);if(n==r.childCount){if(r.type.spec.isolating)return!0}else for(let e=r.child(n);;e=e.firstChild){if(e.childCount==0&&!e.inlineContent||Bw(e.type))return!0;if(e.inlineContent)return!1}}return!0}function Uw(){return new D({props:{decorations:Jw,createSelectionBetween(e,t,n){return t.pos==n.pos&&Rw.valid(n)?new Rw(n):null},handleClick:Kw,handleKeyDown:Ww,handleDOMEvents:{beforeinput:qw}}})}var Ww=xc({ArrowLeft:Gw(`horiz`,-1),ArrowRight:Gw(`horiz`,1),ArrowUp:Gw(`vert`,-1),ArrowDown:Gw(`vert`,1)});function Gw(e,t){let n=e==`vert`?t>0?`down`:`up`:t>0?`right`:`left`;return function(e,r,i){let a=e.selection,o=t>0?a.$to:a.$from,s=a.empty;if(a instanceof T){if(!i.endOfTextblock(n)||o.depth==0)return!1;s=!1,o=e.doc.resolve(t>0?o.after():o.before())}let c=Rw.findGapCursorFrom(o,t,s);return c?(r&&r(e.tr.setSelection(new Rw(c))),!0):!1}}function Kw(e,t,n){if(!e||!e.editable)return!1;let r=e.state.doc.resolve(t);if(!Rw.valid(r))return!1;let i=e.posAtCoords({left:n.clientX,top:n.clientY});return i&&i.inside>-1&&E.isSelectable(e.state.doc.nodeAt(i.inside))?!1:(e.dispatch(e.state.tr.setSelection(new Rw(r))),!0)}function qw(e,t){if(t.inputType!=`insertCompositionText`||!(e.state.selection instanceof Rw))return!1;let{$from:n}=e.state.selection,r=n.parent.contentMatchAt(n.index()).findWrapping(e.state.schema.nodes.text);if(!r)return!1;let i=s.empty;for(let e=r.length-1;e>=0;e--)i=s.from(r[e].createAndFill(null,i));let a=e.state.tr.replace(n.pos,n.pos,new p(i,0,0));return a.setSelection(T.near(a.doc.resolve(n.pos+1))),e.dispatch(a),!1}function Jw(e){if(!(e.selection instanceof Rw))return null;let t=document.createElement(`div`);return t.className=`ProseMirror-gapcursor`,bs.create(e.doc,[_s.widget(e.selection.head,t,{key:`gapcursor`})])}wp.create({name:`characterCount`,addOptions(){return{limit:null,autoTrim:!0,mode:`textSize`,textCounter:e=>e.length,wordCounter:e=>e.split(` `).filter(e=>e!==``).length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=e=>{let t=e?.node||this.editor.state.doc;if((e?.mode||this.options.mode)===`textSize`){let e=t.textBetween(0,t.content.size,void 0,` `);return this.options.textCounter(e)}return t.nodeSize},this.storage.words=e=>{let t=e?.node||this.editor.state.doc,n=t.textBetween(0,t.content.size,` `,` `);return this.options.wordCounter(n)}},addProseMirrorPlugins(){let e=!1;return[new D({key:new O(`characterCount`),appendTransaction:(t,n,r)=>{if(e)return;let i=this.options.limit,a=this.options.autoTrim;if(i==null||i===0||a===!1){e=!0;return}let o=this.storage.characters({node:r.doc});if(o>i){let t=o-i;console.warn(`[CharacterCount] Initial content exceeded limit of ${i} characters. Content was automatically trimmed.`);let n=r.tr.deleteRange(0,t);return e=!0,n}e=!0},filterTransaction:(e,t)=>{let n=this.options.limit;if(!e.docChanged||n===0||n==null)return!0;let r=this.storage.characters({node:t.doc}),i=this.storage.characters({node:e.doc});if(i<=n||r>n&&i>n&&i<=r)return!0;if(r>n&&i>n&&i>r||!e.getMeta(`paste`))return!1;let a=e.selection.$head.pos,o=a-(i-n),s=a;return e.deleteRange(o,s),!(this.storage.characters({node:e.doc})>n)}})]}});var Yw=wp.create({name:`dropCursor`,addOptions(){return{color:`currentColor`,width:1,class:void 0}},addProseMirrorPlugins(){return[Iw(this.options)]}});wp.create({name:`focus`,addOptions(){return{className:`has-focus`,mode:`all`}},addProseMirrorPlugins(){return[new D({key:new O(`focus`),props:{decorations:({doc:e,selection:t})=>{let{isEditable:n,isFocused:r}=this.editor,{anchor:i}=t,a=[];if(!n||!r)return bs.create(e,[]);let o=0;this.options.mode===`deepest`&&e.descendants((e,t)=>{if(!e.isText){if(!(i>=t&&i<=t+e.nodeSize-1))return!1;o+=1}});let s=0;return e.descendants((e,t)=>{if(e.isText||!(i>=t&&i<=t+e.nodeSize-1))return!1;if(s+=1,this.options.mode===`deepest`&&o-s>0||this.options.mode===`shallowest`&&s>1)return this.options.mode===`deepest`;a.push(_s.node(t,t+e.nodeSize,{class:this.options.className}))}),bs.create(e,a)}}})]}});var Xw=wp.create({name:`gapCursor`,addProseMirrorPlugins(){return[Uw()]},extendNodeSchema(e){return{allowGapCursor:Mu(A(e,`allowGapCursor`,{name:e.name,options:e.options,storage:e.storage}))??null}}}),Zw=`placeholder`,Qw=new O(`tiptap__placeholder`);function $w(e){let{editor:t,placeholder:n,dataAttribute:r,pos:i,node:a,isEmptyDoc:o,hasAnchor:s,classes:{emptyNode:c,emptyEditor:l}}=e,u=[c];return o&&u.push(l),_s.node(i,i+a.nodeSize,{class:u.join(` `),[r]:typeof n==`function`?n({editor:t,node:a,pos:i,hasAnchor:s}):n})}function eT(e,t){return typeof e==`function`?e(t):e}function tT({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:a,to:o}){let{anchor:s}=i,c=[],l=e.isEmpty;return r.nodesBetween(a,o,(r,i)=>{let a=s>=i&&s<=i+r.nodeSize,o=!r.isLeaf&&dd(r);return r.type.isTextblock&&(a||!t.showOnlyCurrent)&&o&&c.push($w({editor:e,isEmptyDoc:l,dataAttribute:n,hasAnchor:a,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:eT(t.emptyNodeClass,{editor:e,node:r,pos:i,hasAnchor:a})},node:r,pos:i})),t.includeChildren}),c}function nT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}){if(!e.isEditable&&t.showOnlyWhenEditable)return null;let{anchor:a}=i,o=[],s=e.isEmpty;if(t.showOnlyCurrent&&!t.includeChildren){let i=r.resolve(a),c=i.depth>0?i.node(1):i.nodeAfter,l=i.depth>0?i.before(1):a;if(c&&c.type.isTextblock&&dd(c)){let r=a>=l&&a<=l+c.nodeSize;o.push($w({editor:e,isEmptyDoc:s,dataAttribute:n,hasAnchor:r,placeholder:t.placeholder,classes:{emptyEditor:t.emptyEditorClass,emptyNode:eT(t.emptyNodeClass,{editor:e,node:c,pos:l,hasAnchor:r})},node:c,pos:l}))}}else o.push(...tT({editor:e,options:t,dataAttribute:n,doc:r,selection:i,from:0,to:r.content.size}));return bs.create(r,o)}function rT(e,t){let n=e.resolve(t);if(n.depth===0){let e=n.nodeAfter??n.nodeBefore;if(!e)return{from:t,to:t};let r=n.nodeAfter?t:t-e.nodeSize;return{from:r,to:r+e.nodeSize}}let r=n.before(1);return{from:r,to:r+n.node(1).nodeSize}}function iT(e,t){return{from:Math.max(0,t.from-1),to:Math.min(e.content.size,t.to-1)}}function aT(e,t,n){let r=[];return e.forEach((e,i)=>{let a=i,o=a+e.nodeSize,s=a+1,c=o+1;st&&r.push({from:a,to:o})}),r}function oT(e){if(e.length===0)return[];let t=[...e].sort((e,t)=>e.from-t.from),n=[{...t[0]}];for(let e=1;et.from?n.push(iT(e,rT(e,Math.min(t.to,e.content.size+1)-1))):t.frome.from>=t&&e.to<=c);l.length&&(s=s.remove(l));let u=tT({editor:n,options:r,dataAttribute:i,doc:a,selection:o,from:t,to:c});u.length&&(s=s.add(a,u))}return s}function dT({editor:e,options:t,dataAttribute:n}){return{init(r,i){return nT({editor:e,options:t,dataAttribute:n,doc:i.doc,selection:i.selection})??bs.empty},apply(r,i,a,o){return!r.docChanged&&!r.selectionSet?i:uT({decorations:i.map(r.mapping,r.doc),ranges:cT(r,a,o),editor:e,options:t,dataAttribute:n,doc:o.doc,selection:o.selection})}}}function fT(e){return e.replace(/\s+/g,`-`).replace(/[^a-zA-Z0-9-]/g,``).replace(/^[0-9-]+/,``).replace(/^-+/,``).toLowerCase()}function pT({editor:e,options:t}){let n=t.dataAttribute?`data-${fT(t.dataAttribute)}`:`data-${Zw}`,r=t.showOnlyCurrent&&!t.includeChildren;return new D({key:Qw,...r?{}:{state:dT({editor:e,options:t,dataAttribute:n})},props:{decorations:r?({doc:r,selection:i})=>nT({editor:e,options:t,dataAttribute:n,doc:r,selection:i}):n=>t.showOnlyWhenEditable&&!e.isEditable?bs.empty:Qw.getState(n)??bs.empty}})}var mT=wp.create({name:`placeholder`,addOptions(){return{emptyEditorClass:`is-editor-empty`,emptyNodeClass:`is-empty`,dataAttribute:Zw,placeholder:`Write something …`,showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){return[pT({editor:this.editor,options:this.options})]}});function hT(e,t){return!e.selection.empty&&!fd(e.selection)&&t.isEditable}function gT(e,t){return hT(e,t)&&!t.isFocused&&!t.view.dragging}function _T(){var e;(e=window.getSelection())==null||e.removeAllRanges()}function vT(e){e.focus()}wp.create({name:`selection`,addOptions(){return{className:`selection`}},addProseMirrorPlugins(){let{editor:e,options:t}=this;return[new D({key:new O(`selection`),props:{decorations(n){return gT(n,e)?bs.create(n.doc,[_s.inline(n.selection.from,n.selection.to,{class:t.className})]):null},handleDOMEvents:{blur(t){return hT(t.state,e)&&_T(),!1},focus(t){return hT(t.state,e)&&requestAnimationFrame(()=>{!e.isDestroyed&&t.hasFocus()&&vT(t)}),!1}}}})]}});function yT({types:e,node:t}){return t&&Array.isArray(e)&&e.includes(t.type)||t?.type===e}var bT=wp.create({name:`trailingNode`,addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){let e=new O(this.name),t=this.options.node||this.editor.schema.topNodeType.contentMatch.defaultType?.name||`paragraph`,n=Object.entries(this.editor.schema.nodes).map(([,e])=>e).filter(e=>(this.options.notAfter||[]).concat(t).includes(e.name));return[new D({key:e,appendTransaction:(n,r,i)=>{let{doc:a,tr:o,schema:s}=i,c=e.getState(i),l=a.content.size,u=s.nodes[t];if(!n.some(e=>e.getMeta(`skipTrailingNode`))&&c)return o.insert(l,u.create())},state:{init:(e,t)=>{let r=t.tr.doc.lastChild;return!yT({node:r,types:n})},apply:(e,t)=>{if(!e.docChanged||e.getMeta(`__uniqueIDTransaction`))return t;let r=e.doc.lastChild;return!yT({node:r,types:n})}}})]}}),xT=wp.create({name:`undoRedo`,addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>Gc(e,t),redo:()=>({state:e,dispatch:t})=>Kc(e,t)}},addProseMirrorPlugins(){return[Uc(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),ST=new WeakSet,CT=new WeakSet;function wT(e){let t=e;return ST.add(t),t}function TT(e){return Array.isArray(e)&&ST.has(e)}function ET(e){return e.flatMap(e=>e==null?[]:Array.isArray(e)&&CT.has(e)&&!TT(e)?ET(e):[e])}function DT(e,t){if(e===`slot`)return 0;if(e instanceof Function){let n=e(t);return Array.isArray(n)&&!TT(n)&&!CT.has(n)?wT(n):n}let{children:n,...r}=t??{};if(e===`svg`)throw Error(`SVG elements are not supported in the JSX syntax, use the array syntax instead`);if(Array.isArray(n)){if(TT(n))return wT([e,r,n]);if(n.length===0)return wT([e,r]);let t=ET(n);return t.length===0?wT([e,r]):wT([e,r,...t])}return wT(n==null?[e,r]:[e,r,n])}var OT=(e,t)=>DT(e,t),kT=(e,t)=>{let{state:n}=e,{selection:r}=n;if(!r.empty)return!1;let{$from:i}=r;if(i.parentOffset!==0)return!1;let a=i.depth-1;if(a<0)return!1;let o=i.node(a),s=i.index(a);if(s===0)return!1;if(o.type===t)return e.commands.lift(t.name);let c=o.child(s-1);if(c.type!==t||!c.lastChild?.isTextblock)return!1;let l=i.before()-1-1;return e.commands.command(({tr:e,dispatch:t})=>{if(!t)return!0;let n=i.parent.content,r=new p(n,0,0);return e.replace(l,i.after(),r),e.setSelection(T.create(e.doc,l+n.size)),e.scrollIntoView(),t(e),!0})},AT=/^\s*>\s$/,jT=qp.create({name:`blockquote`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,group:`block`,defining:!0,parseHTML(){return[{tag:`blockquote`}]},renderHTML({HTMLAttributes:e}){return OT(`blockquote`,{...j(this.options.HTMLAttributes,e),children:OT(`slot`,{})})},parseMarkdown:(e,t)=>{let n=t.parseBlockChildren??t.parseChildren;return t.createNode(`blockquote`,void 0,n(e.tokens||[]))},renderMarkdown:(e,t)=>{if(!e.content)return``;let n=[];return e.content.forEach((e,r)=>{let i=(t.renderChild?.call(t,e,r)??t.renderChildren([e])).split(` `).map(e=>e.trim()===``?`>`:`> ${e}`);n.push(i.join(` `))}),n.join(` > -`)},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote(),Backspace:()=>AT(this.editor,this.type)}},addInputRules(){return[Gp({find:jT,type:this.type})]}}),NT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,PT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,FT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,IT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,LT=_p.create({name:`bold`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!==`normal`&&null},{style:`font-weight=400`,clearMark:e=>e.type.name===this.name},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return kT(`strong`,{...A(this.options.HTMLAttributes,e),children:kT(`slot`,{})})},markdownTokenName:`strong`,parseMarkdown:(e,t)=>t.applyMark(`bold`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`**${t.renderChildren(e)}**`,addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Hp({find:NT,type:this.type}),Hp({find:FT,type:this.type})]},addPasteRules(){return[Yp({find:PT,type:this.type}),Yp({find:IT,type:this.type})]}}),RT=e=>{let t=/`([^`]+)`(?!`)$/.exec(e);return!t||t.index>0&&e[t.index-1]==="`"?null:{index:t.index,text:t[0],replaceWith:t[1]}},zT=e=>{let t=/`([^`]+)`(?!`)/g,n=[],r;for(;(r=t.exec(e))!==null;)r.index>0&&e[r.index-1]==="`"||n.push({index:r.index,text:r[0],replaceWith:r[1]});return n};function BT(e){let t=new Set((e.match(/`+/g)||[]).map(e=>e.length)),n=1;for(;t.has(n);)n+=1;return n}var VT=_p.create({name:`code`,addOptions(){return{HTMLAttributes:{}}},excludes:`_`,code:!0,exitable:!0,parseHTML(){return[{tag:`code`}]},renderHTML({HTMLAttributes:e}){return[`code`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`codespan`,parseMarkdown:(e,t)=>t.applyMark(`code`,[{type:`text`,text:e.text||``}]),renderMarkdown:(e,t,n)=>{var r;if(!e.content)return``;let i=typeof(n==null||(r=n.meta)==null?void 0:r.markText)==`string`?n.meta.markText:``,a="`".repeat(BT(i)),o=i.startsWith("`")||i.endsWith("`")?` `:``;return`${a}${o}${t.renderChildren(e.content)}${o}${a}`},addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[Hp({find:RT,type:this.type})]},addPasteRules(){return[Yp({find:zT,type:this.type})]}}),HT=4,UT=/^```([a-z]+)?[\s\n]$/,WT=/^~~~([a-z]+)?[\s\n]$/,GT=Jp.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,exitOnArrowUp:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:HT,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,A(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.raw?.startsWith(`~~~`)===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(` -`):`\`\`\`${r}\n\n\`\`\``,n},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,`paragraph`,e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??HT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;if(i.parent.type!==this.type)return!1;let o=` `.repeat(t);return a?e.commands.insertContent(o):e.commands.command(({tr:e})=>{let{from:t,to:i}=r,a=n.doc.textBetween(t,i,` +`)},addCommands(){return{setBlockquote:()=>({commands:e})=>e.wrapIn(this.name),toggleBlockquote:()=>({commands:e})=>e.toggleWrap(this.name),unsetBlockquote:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote(),Backspace:()=>kT(this.editor,this.type)}},addInputRules(){return[Wp({find:AT,type:this.type})]}}),MT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,NT=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,PT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,FT=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,IT=gp.create({name:`bold`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`strong`},{tag:`b`,getAttrs:e=>e.style.fontWeight!==`normal`&&null},{style:`font-weight=400`,clearMark:e=>e.type.name===this.name},{style:`font-weight`,getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}]},renderHTML({HTMLAttributes:e}){return OT(`strong`,{...j(this.options.HTMLAttributes,e),children:OT(`slot`,{})})},markdownTokenName:`strong`,parseMarkdown:(e,t)=>t.applyMark(`bold`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`**${t.renderChildren(e)}**`,addCommands(){return{setBold:()=>({commands:e})=>e.setMark(this.name),toggleBold:()=>({commands:e})=>e.toggleMark(this.name),unsetBold:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[Vp({find:MT,type:this.type}),Vp({find:PT,type:this.type})]},addPasteRules(){return[Jp({find:NT,type:this.type}),Jp({find:FT,type:this.type})]}}),LT=e=>{let t=/`([^`]+)`(?!`)$/.exec(e);return!t||t.index>0&&e[t.index-1]==="`"?null:{index:t.index,text:t[0],replaceWith:t[1]}},RT=e=>{let t=/`([^`]+)`(?!`)/g,n=[],r;for(;(r=t.exec(e))!==null;)r.index>0&&e[r.index-1]==="`"||n.push({index:r.index,text:r[0],replaceWith:r[1]});return n};function zT(e){let t=new Set((e.match(/`+/g)||[]).map(e=>e.length)),n=1;for(;t.has(n);)n+=1;return n}var BT=gp.create({name:`code`,addOptions(){return{HTMLAttributes:{}}},excludes:`_`,code:!0,exitable:!0,parseHTML(){return[{tag:`code`}]},renderHTML({HTMLAttributes:e}){return[`code`,j(this.options.HTMLAttributes,e),0]},markdownTokenName:`codespan`,parseMarkdown:(e,t)=>t.applyMark(`code`,[{type:`text`,text:e.text||``}]),renderMarkdown:(e,t,n)=>{var r;if(!e.content)return``;let i=typeof(n==null||(r=n.meta)==null?void 0:r.markText)==`string`?n.meta.markText:``,a="`".repeat(zT(i)),o=i.startsWith("`")||i.endsWith("`")?` `:``;return`${a}${o}${t.renderChildren(e.content)}${o}${a}`},addCommands(){return{setCode:()=>({commands:e})=>e.setMark(this.name),toggleCode:()=>({commands:e})=>e.toggleMark(this.name),unsetCode:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[Vp({find:LT,type:this.type})]},addPasteRules(){return[Jp({find:RT,type:this.type})]}}),VT=4,HT=/^```([a-z]+)?[\s\n]$/,UT=/^~~~([a-z]+)?[\s\n]$/,WT=qp.create({name:`codeBlock`,addOptions(){return{languageClassPrefix:`language-`,exitOnTripleEnter:!0,exitOnArrowDown:!0,exitOnArrowUp:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:VT,HTMLAttributes:{}}},content:`text*`,marks:``,group:`block`,code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:e=>{let{languageClassPrefix:t}=this.options;return t&&[...e.firstElementChild?.classList||[]].filter(e=>e.startsWith(t)).map(e=>e.replace(t,``))[0]||null},rendered:!1}}},parseHTML(){return[{tag:`pre`,preserveWhitespace:`full`}]},renderHTML({node:e,HTMLAttributes:t}){return[`pre`,j(this.options.HTMLAttributes,t),[`code`,{class:e.attrs.language?this.options.languageClassPrefix+e.attrs.language:null},0]]},markdownTokenName:`code`,parseMarkdown:(e,t)=>e.raw?.startsWith("```")===!1&&e.raw?.startsWith(`~~~`)===!1&&e.codeBlockStyle!==`indented`?[]:t.createNode(`codeBlock`,{language:e.lang||null},e.text?[t.createTextNode(e.text)]:[]),renderMarkdown:(e,t)=>{let n=``,r=e.attrs?.language||``;return n=e.content?[`\`\`\`${r}`,t.renderChildren(e.content),"```"].join(` +`):`\`\`\`${r}\n\n\`\`\``,n},addCommands(){return{setCodeBlock:e=>({commands:t})=>t.setNode(this.name,e),toggleCodeBlock:e=>({commands:t})=>t.toggleNode(this.name,`paragraph`,e)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{let{empty:e,$anchor:t}=this.editor.state.selection,n=t.pos===1;return!e||t.parent.type.name!==this.name?!1:n||!t.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??VT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;if(i.parent.type!==this.type)return!1;let o=` `.repeat(t);return a?e.commands.insertContent(o):e.commands.command(({tr:e})=>{let{from:t,to:i}=r,a=n.doc.textBetween(t,i,` `,` `).split(` `).map(e=>o+e).join(` -`);return e.replaceWith(t,i,n.schema.text(a)),!0})},"Shift-Tab":({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??HT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;return i.parent.type===this.type?a?e.commands.command(({tr:e})=>{let{pos:r}=i,a=i.start(),o=i.end(),s=n.doc.textBetween(a,o,` +`);return e.replaceWith(t,i,n.schema.text(a)),!0})},"Shift-Tab":({editor:e})=>{if(!this.options.enableTabIndentation)return!1;let t=this.options.tabSize??VT,{state:n}=e,{selection:r}=n,{$from:i,empty:a}=r;return i.parent.type===this.type?a?e.commands.command(({tr:e})=>{let{pos:r}=i,a=i.start(),o=i.end(),s=n.doc.textBetween(a,o,` `,` `).split(` `),c=0,l=0,u=r-a;for(let e=0;e=u){c=e;break}l+=s[e].length+1}let d=s[c].match(/^ */)?.[0]||``,f=Math.min(d.length,t);if(f===0)return!0;let p=a;for(let e=0;e{let{from:i,to:a}=r,o=n.doc.textBetween(i,a,` @@ -123,51 +123,53 @@ img.ProseMirror-separator { `).map(e=>{let n=e.match(/^ */)?.[0]||``,r=Math.min(n.length,t);return e.slice(r)}).join(` `);return e.replaceWith(i,a,n.schema.text(o)),!0}):!1},Enter:({editor:e})=>{if(!this.options.exitOnTripleEnter)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type)return!1;let a=r.parentOffset===r.parent.nodeSize-2,o=r.parent.textContent.endsWith(` -`);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowUp:({editor:e})=>{if(!this.options.exitOnArrowUp)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type||r.parentOffset!==0)return!1;let a=r.before();return a>0?!1:e.commands.insertDefaultBlock({pos:a})},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(w.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[Wp({find:UT,type:this.type,getAttributes:e=>({language:e[1]})}),Wp({find:WT,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new D({key:new Un(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,` -`));return a.replaceSelectionWith(this.type.create({language:i},s)),a.selection.$from.parent.type!==this.type&&a.setSelection(T.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta(`paste`,!0),e.dispatch(a),!0}}})]}}),KT=GT,qT=Jp.create({name:`doc`,topNode:!0,content:`block+`,renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`);return!a||!o?!1:e.chain().command(({tr:e})=>(e.delete(r.pos-2,r.pos),!0)).exitCode().run()},ArrowUp:({editor:e})=>{if(!this.options.exitOnArrowUp)return!1;let{state:t}=e,{selection:n}=t,{$from:r,empty:i}=n;if(!i||r.parent.type!==this.type||r.parentOffset!==0)return!1;let a=r.before();return a>0?!1:e.commands.insertDefaultBlock({pos:a})},ArrowDown:({editor:e})=>{if(!this.options.exitOnArrowDown)return!1;let{state:t}=e,{selection:n,doc:r}=t,{$from:i,empty:a}=n;if(!a||i.parent.type!==this.type||i.parentOffset!==i.parent.nodeSize-2)return!1;let o=i.after();return o===void 0?!1:r.nodeAt(o)?e.commands.command(({tr:e})=>(e.setSelection(w.near(r.resolve(o))),!0)):e.commands.exitCode()}}},addInputRules(){return[Up({find:HT,type:this.type,getAttributes:e=>({language:e[1]})}),Up({find:UT,type:this.type,getAttributes:e=>({language:e[1]})})]},addProseMirrorPlugins(){return[new D({key:new O(`codeBlockVSCodeHandler`),props:{handlePaste:(e,t)=>{if(!t.clipboardData||this.editor.isActive(this.type.name))return!1;let n=t.clipboardData.getData(`text/plain`),r=t.clipboardData.getData(`vscode-editor-data`),i=(r?JSON.parse(r):void 0)?.mode;if(!n||!i)return!1;let{tr:a,schema:o}=e.state,s=o.text(n.replace(/\r\n?/g,` +`));return a.replaceSelectionWith(this.type.create({language:i},s)),a.selection.$from.parent.type!==this.type&&a.setSelection(T.near(a.doc.resolve(Math.max(0,a.selection.from-2)))),a.setMeta(`paste`,!0),e.dispatch(a),!0}}})]}}),GT=WT,KT=qp.create({name:`doc`,topNode:!0,content:`block+`,renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``}),JT=Jp.create({name:`hardBreak`,markdownTokenName:`br`,addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,A(this.options.HTMLAttributes,e)]},renderText(){return` +`):``}),qT=qp.create({name:`hardBreak`,markdownTokenName:`br`,addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:`inline`,selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:`br`}]},renderHTML({HTMLAttributes:e}){return[`br`,j(this.options.HTMLAttributes,e)]},renderText(){return` `},renderMarkdown:()=>` -`,parseMarkdown:()=>({type:`hardBreak`}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:a}=this.options,{splittableMarks:o}=r.extensionManager,s=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&s&&a){let t=s.filter(e=>o.includes(e.type.name));e.ensureMarks(t)}return!0}).scrollIntoView().run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),YT=Jp.create({name:`heading`,addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:`inline*`,group:`block`,defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,A(this.options.HTMLAttributes,t),0]},parseMarkdown(e,t){let n=e.depth||1;return this.options.levels.includes(n)?t.createNode(`heading`,{level:n},t.parseInline(e.tokens||[])):t.createNode(`paragraph`,void 0,t.parseInline(e.tokens||[]))},renderMarkdown:(e,t)=>{let n=e.attrs?.level?parseInt(e.attrs.level,10):1,r=`#`.repeat(n);return e.content?`${r} ${t.renderChildren(e.content)}`:``},addCommands(){return{setHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.setNode(this.name,e):!1,toggleHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.toggleNode(this.name,`paragraph`,e):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>Wp({find:RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),XT=Jp.create({name:`horizontalRule`,addOptions(){return{HTMLAttributes:{},nextNodeType:`paragraph`}},group:`block`,parseHTML(){return[{tag:`hr`}]},renderHTML({HTMLAttributes:e}){return[`hr`,A(this.options.HTMLAttributes,e)]},markdownTokenName:`hr`,parseMarkdown:(e,t)=>t.createNode(`horizontalRule`),renderMarkdown:()=>`---`,addCommands(){return{setHorizontalRule:()=>({chain:e,state:t})=>{if(!Df(t,t.schema.nodes[this.name]))return!1;let{selection:n}=t,{$to:r}=n,i=e();return pd(n)?i.insertContentAt(r.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({state:e,tr:t,dispatch:n})=>{if(n){let{$to:n}=t.selection,r=n.end();if(n.nodeAfter)n.nodeAfter.isTextblock?t.setSelection(T.create(t.doc,n.pos+1)):n.nodeAfter.isBlock?t.setSelection(E.create(t.doc,n.pos)):t.setSelection(T.create(t.doc,n.pos));else{let i=(e.schema.nodes[this.options.nextNodeType]||n.parent.type.contentMatch.defaultType)?.create();i&&(t.insert(r,i),t.setSelection(T.create(t.doc,r+1)))}t.scrollIntoView()}return!0}).run()}}},addInputRules(){return[Up({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),ZT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,QT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,$T=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,eE=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,tE=_p.create({name:`italic`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`em`},{tag:`i`,getAttrs:e=>e.style.fontStyle!==`normal`&&null},{style:`font-style=normal`,clearMark:e=>e.type.name===this.name},{style:`font-style=italic`}]},renderHTML({HTMLAttributes:e}){return[`em`,A(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},markdownTokenName:`em`,parseMarkdown:(e,t)=>t.applyMark(`italic`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`*${t.renderChildren(e)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Hp({find:ZT,type:this.type}),Hp({find:$T,type:this.type})]},addPasteRules(){return[Yp({find:QT,type:this.type}),Yp({find:eE,type:this.type})]}}),nE=`aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos6kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12b0cam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2`,rE=`ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2`,iE=`numeric`,aE=`ascii`,oE=`alpha`,sE=`asciinumeric`,cE=`alphanumeric`,lE=`domain`,uE=`emoji`,dE=`scheme`,fE=`slashscheme`,pE=`whitespace`;function mE(e,t){return e in t||(t[e]=[]),t[e]}function hE(e,t,n){t[iE]&&(t[sE]=!0,t[cE]=!0),t[aE]&&(t[sE]=!0,t[oE]=!0),t[sE]&&(t[cE]=!0),t[oE]&&(t[cE]=!0),t[cE]&&(t[lE]=!0),t[uE]&&(t[lE]=!0);for(let r in t){let t=mE(r,n);t.indexOf(e)<0&&t.push(e)}}function gE(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}function _E(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}_E.groups={},_E.prototype={accepts(){return!!this.t},go(e){let t=this,n=t.j[e];if(n)return n;for(let n=0;ne.ta(t,n,r,i),yE=(e,t,n,r,i)=>e.tr(t,n,r,i),bE=(e,t,n,r,i)=>e.ts(t,n,r,i),P=(e,t,n,r,i)=>e.tt(t,n,r,i),xE=`WORD`,SE=`UWORD`,CE=`ASCIINUMERICAL`,wE=`ALPHANUMERICAL`,TE=`LOCALHOST`,EE=`TLD`,DE=`UTLD`,OE=`SCHEME`,kE=`SLASH_SCHEME`,AE=`NUM`,jE=`WS`,ME=`NL`,NE=`OPENBRACE`,PE=`CLOSEBRACE`,FE=`OPENBRACKET`,IE=`CLOSEBRACKET`,LE=`OPENPAREN`,RE=`CLOSEPAREN`,zE=`OPENANGLEBRACKET`,BE=`CLOSEANGLEBRACKET`,VE=`FULLWIDTHLEFTPAREN`,HE=`FULLWIDTHRIGHTPAREN`,UE=`LEFTCORNERBRACKET`,WE=`RIGHTCORNERBRACKET`,GE=`LEFTWHITECORNERBRACKET`,KE=`RIGHTWHITECORNERBRACKET`,qE=`FULLWIDTHLESSTHAN`,JE=`FULLWIDTHGREATERTHAN`,YE=`AMPERSAND`,XE=`APOSTROPHE`,ZE=`ASTERISK`,QE=`AT`,$E=`BACKSLASH`,eD=`BACKTICK`,tD=`CARET`,nD=`COLON`,rD=`COMMA`,iD=`DOLLAR`,aD=`DOT`,oD=`EQUALS`,sD=`EXCLAMATION`,cD=`HYPHEN`,lD=`PERCENT`,uD=`PIPE`,dD=`PLUS`,fD=`POUND`,pD=`QUERY`,mD=`QUOTE`,hD=`FULLWIDTHMIDDLEDOT`,gD=`SEMI`,_D=`SLASH`,vD=`TILDE`,yD=`UNDERSCORE`,bD=`EMOJI`,xD=`SYM`,SD=Object.freeze({__proto__:null,ALPHANUMERICAL:wE,AMPERSAND:YE,APOSTROPHE:XE,ASCIINUMERICAL:CE,ASTERISK:ZE,AT:QE,BACKSLASH:$E,BACKTICK:eD,CARET:tD,CLOSEANGLEBRACKET:BE,CLOSEBRACE:PE,CLOSEBRACKET:IE,CLOSEPAREN:RE,COLON:nD,COMMA:rD,DOLLAR:iD,DOT:aD,EMOJI:bD,EQUALS:oD,EXCLAMATION:sD,FULLWIDTHGREATERTHAN:JE,FULLWIDTHLEFTPAREN:VE,FULLWIDTHLESSTHAN:qE,FULLWIDTHMIDDLEDOT:hD,FULLWIDTHRIGHTPAREN:HE,HYPHEN:cD,LEFTCORNERBRACKET:UE,LEFTWHITECORNERBRACKET:GE,LOCALHOST:TE,NL:ME,NUM:AE,OPENANGLEBRACKET:zE,OPENBRACE:NE,OPENBRACKET:FE,OPENPAREN:LE,PERCENT:lD,PIPE:uD,PLUS:dD,POUND:fD,QUERY:pD,QUOTE:mD,RIGHTCORNERBRACKET:WE,RIGHTWHITECORNERBRACKET:KE,SCHEME:OE,SEMI:gD,SLASH:_D,SLASH_SCHEME:kE,SYM:xD,TILDE:vD,TLD:EE,UNDERSCORE:yD,UTLD:DE,UWORD:SE,WORD:xE,WS:jE}),CD=/[a-z]/,wD=/[a-z]/i,TD=/[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}]|\u{FE0F}/u;try{wD=RegExp(`\\p{L}`,`u`),TD=RegExp(`\\p{Emoji}`,`u`)}catch{}var ED=/\d/,DD=/\s/,OD=`\r`,kD=` -`,AD=`️`,jD=`‍`,MD=``,ND=null,PD=null;function FD(e=[]){let t={};_E.groups=t;let n=new _E;ND??=zD(nE),PD??=zD(rE),P(n,`'`,XE),P(n,`{`,NE),P(n,`}`,PE),P(n,`[`,FE),P(n,`]`,IE),P(n,`(`,LE),P(n,`)`,RE),P(n,`<`,zE),P(n,`>`,BE),P(n,`(`,VE),P(n,`)`,HE),P(n,`「`,UE),P(n,`」`,WE),P(n,`『`,GE),P(n,`』`,KE),P(n,`<`,qE),P(n,`>`,JE),P(n,`&`,YE),P(n,`*`,ZE),P(n,`@`,QE),P(n,"`",eD),P(n,`^`,tD),P(n,`:`,nD),P(n,`,`,rD),P(n,`$`,iD),P(n,`.`,aD),P(n,`=`,oD),P(n,`!`,sD),P(n,`-`,cD),P(n,`%`,lD),P(n,`|`,uD),P(n,`+`,dD),P(n,`#`,fD),P(n,`?`,pD),P(n,`"`,mD),P(n,`/`,_D),P(n,`;`,gD),P(n,`~`,vD),P(n,`_`,yD),P(n,`\\`,$E),P(n,`・`,hD);let r=yE(n,ED,AE,{[iE]:!0});yE(r,ED,r);let i=yE(r,CD,CE,{[sE]:!0}),a=yE(r,wD,wE,{[cE]:!0}),o=yE(n,CD,xE,{[aE]:!0});yE(o,ED,i),yE(o,CD,o),yE(i,ED,i),yE(i,CD,i);let s=yE(n,wD,SE,{[oE]:!0});yE(s,CD),yE(s,ED,a),yE(s,wD,s),yE(a,ED,a),yE(a,CD),yE(a,wD,a);let c=P(n,kD,ME,{[pE]:!0}),l=P(n,OD,jE,{[pE]:!0}),u=yE(n,DD,jE,{[pE]:!0});P(n,MD,u),P(l,kD,c),P(l,MD,u),yE(l,DD,u),P(u,OD),P(u,kD),yE(u,DD,u),P(u,MD,u);let d=yE(n,TD,bD,{[uE]:!0});P(d,`#`),yE(d,TD,d),P(d,AD,d);let f=P(d,jD);P(f,`#`),yE(f,TD,d);let p=[[CD,o],[ED,i]],m=[[CD,null],[wD,s],[ED,a]];for(let e=0;ee[0]>t[0]?1:-1);for(let t=0;t=0?i[lE]=!0:CD.test(r)?ED.test(r)?i[sE]=!0:i[aE]=!0:i[iE]=!0,bE(n,r,r,i)}return bE(n,`localhost`,TE,{ascii:!0}),n.jd=new _E(xD),{start:n,tokens:Object.assign({groups:t},SD)}}function ID(e,t){let n=LD(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function LD(e){let t=[],n=e.length,r=0;for(;r56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function RD(e,t,n,r,i){let a,o=t.length;for(let n=0;n=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var BD={defaultProtocol:`http`,events:null,format:HD,formatHref:HD,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],ignoreClasses:[],render:null};function VD(e,t=null){let n=Object.assign({},BD);e&&(n=Object.assign(n,e instanceof VD?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;e=0)return!0;return!1},defaultRender(e){return e},check(e){return this.get(`validate`,e.toString(),e)},get(e,t,n){let r=t!=null,i=this.o[e];return i&&(typeof i==`object`?(i=n.t in i?i[n.t]:BD[e],typeof i==`function`&&r&&(i=i(t,n))):typeof i==`function`&&r&&(i=i(t,n.t,n)),i)},getObj(e,t,n){let r=this.o[e];return typeof r==`function`&&t!=null&&(r=r(t,n.t,n)),r},render(e){let t=e.render(this);return(this.get(`render`,null,e)||this.defaultRender)(t,e.t,e)}};function HD(e){return e}function UD(e,t){this.t=`token`,this.v=e,this.tk=t}UD.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){let t=this.toString(),n=e.get(`truncate`,t,this),r=e.get(`format`,t,this);return n&&r.length>n?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=BD.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function WD(e,t){class n extends UD{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var GD=WD(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),KD=WD(`text`),qD=WD(`nl`),JD=WD(`url`,{isLink:!0,toHref(e=BD.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==TE&&e[1].t===nD}}),YD=e=>new _E(e);function XD({groups:e}){let t=e.domain.concat([YE,ZE,QE,$E,eD,tD,iD,oD,cD,AE,lD,uD,dD,fD,_D,xD,vD,yD]),n=[XE,nD,rD,aD,sD,lD,pD,mD,gD,zE,BE,NE,PE,IE,FE,LE,RE,VE,HE,UE,WE,GE,KE,qE,JE],r=[YE,XE,ZE,$E,eD,tD,iD,oD,cD,NE,PE,lD,uD,dD,fD,pD,_D,xD,vD,yD],i=YD(),a=P(i,vD);vE(a,r,a),vE(a,e.domain,a);let o=YD(),s=YD(),c=YD();vE(i,e.domain,o),vE(i,e.scheme,s),vE(i,e.slashscheme,c),vE(o,r,a),vE(o,e.domain,o);let l=P(o,QE);P(a,QE,l),P(s,QE,l),P(c,QE,l);let u=P(a,aD);vE(u,r,a),vE(u,e.domain,a);let d=YD();vE(l,e.domain,d),vE(d,e.domain,d);let f=P(d,aD);vE(f,e.domain,d);let p=YD(GD);vE(f,e.tld,p),vE(f,e.utld,p),P(l,TE,p);let m=P(d,cD);P(m,cD,m),vE(m,e.domain,d),vE(p,e.domain,d),P(p,aD,f),P(p,cD,m);let h=P(o,cD),g=P(o,aD);P(h,cD,h),vE(h,e.domain,o),vE(g,r,a),vE(g,e.domain,o);let _=YD(JD);vE(g,e.tld,_),vE(g,e.utld,_),vE(_,e.domain,o),vE(_,r,a),P(_,aD,g),P(_,cD,h),P(_,QE,l);let v=P(_,nD),y=YD(JD);vE(v,e.numeric,y);let b=YD(JD),x=YD();vE(b,t,b),vE(b,n,x),vE(x,t,b),vE(x,n,x),P(_,_D,b),P(y,_D,b),P(_,pD,x),P(_,fD,b),P(y,pD,x),P(y,fD,b);let S=P(s,nD),C=P(P(P(c,nD),_D),_D);vE(s,e.domain,o),P(s,aD,g),P(s,cD,h),vE(c,e.domain,o),P(c,aD,g),P(c,cD,h),vE(S,e.domain,b),P(S,_D,b),P(S,pD,b),vE(C,e.domain,b),vE(C,t,b),P(C,_D,b);let ee=[[NE,PE],[FE,IE],[LE,RE],[zE,BE],[VE,HE],[UE,WE],[GE,KE],[qE,JE]];for(let e=0;e=0&&p++,m.push(c),s[i]&&s[i].has(c))break;for(let e=0,t=i-m.length+1;e0&&(a.push(QD(KD,t,o)),o=[]),i-=p,d-=p;let e=f.t,r=n.slice(i-d,i);a.push(QD(e,t,r))}}return o.length>0&&a.push(QD(KD,t,o)),a}function QD(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var $D=typeof console<`u`&&console&&console.warn||(()=>{}),eO=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,tO={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function nO(){return _E.groups={},tO.scanner=null,tO.parser=null,tO.tokenQueue=[],tO.pluginQueue=[],tO.customSchemes=[],tO.initialized=!1,tO}function rO(e,t=!1){if(tO.initialized&&$D(`linkifyjs: already initialized - will not register custom scheme "${e}" ${eO}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format. +`,parseMarkdown:()=>({type:`hardBreak`}),addCommands(){return{setHardBreak:()=>({commands:e,chain:t,state:n,editor:r})=>e.first([()=>e.exitCode(),()=>e.command(()=>{let{selection:e,storedMarks:i}=n;if(e.$from.parent.type.spec.isolating)return!1;let{keepMarks:a}=this.options,{splittableMarks:o}=r.extensionManager,s=i||e.$to.parentOffset&&e.$from.marks();return t().insertContent({type:this.name}).command(({tr:e,dispatch:t})=>{if(t&&s&&a){let t=s.filter(e=>o.includes(e.type.name));e.ensureMarks(t)}return!0}).scrollIntoView().run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),JT=qp.create({name:`heading`,addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:`inline*`,group:`block`,defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(e=>({tag:`h${e}`,attrs:{level:e}}))},renderHTML({node:e,HTMLAttributes:t}){return[`h${this.options.levels.includes(e.attrs.level)?e.attrs.level:this.options.levels[0]}`,j(this.options.HTMLAttributes,t),0]},parseMarkdown(e,t){let n=e.depth||1;return this.options.levels.includes(n)?t.createNode(`heading`,{level:n},t.parseInline(e.tokens||[])):t.createNode(`paragraph`,void 0,t.parseInline(e.tokens||[]))},renderMarkdown:(e,t)=>{let n=e.attrs?.level?parseInt(e.attrs.level,10):1,r=`#`.repeat(n);return e.content?`${r} ${t.renderChildren(e.content)}`:``},addCommands(){return{setHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.setNode(this.name,e):!1,toggleHeading:e=>({commands:t})=>this.options.levels.includes(e.level)?t.toggleNode(this.name,`paragraph`,e):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((e,t)=>({...e,[`Mod-Alt-${t}`]:()=>this.editor.commands.toggleHeading({level:t})}),{})},addInputRules(){return this.options.levels.map(e=>Up({find:RegExp(`^(#{${Math.min(...this.options.levels)},${e}})\\s$`),type:this.type,getAttributes:{level:e}}))}}),YT=qp.create({name:`horizontalRule`,addOptions(){return{HTMLAttributes:{},nextNodeType:`paragraph`}},group:`block`,parseHTML(){return[{tag:`hr`}]},renderHTML({HTMLAttributes:e}){return[`hr`,j(this.options.HTMLAttributes,e)]},markdownTokenName:`hr`,parseMarkdown:(e,t)=>t.createNode(`horizontalRule`),renderMarkdown:()=>`---`,addCommands(){return{setHorizontalRule:()=>({chain:e,state:t})=>{if(!Ef(t,t.schema.nodes[this.name]))return!1;let{selection:n}=t,{$to:r}=n,i=e();return fd(n)?i.insertContentAt(r.pos,{type:this.name}):i.insertContent({type:this.name}),i.command(({state:e,tr:t,dispatch:n})=>{if(n){let{$to:n}=t.selection,r=n.end();if(n.nodeAfter)n.nodeAfter.isTextblock?t.setSelection(T.create(t.doc,n.pos+1)):n.nodeAfter.isBlock?t.setSelection(E.create(t.doc,n.pos)):t.setSelection(T.create(t.doc,n.pos));else{let i=(e.schema.nodes[this.options.nextNodeType]||n.parent.type.contentMatch.defaultType)?.create();i&&(t.insert(r,i),t.setSelection(T.create(t.doc,r+1)))}t.scrollIntoView()}return!0}).run()}}},addInputRules(){return[Hp({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),XT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,ZT=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,QT=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,$T=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,eE=gp.create({name:`italic`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`em`},{tag:`i`,getAttrs:e=>e.style.fontStyle!==`normal`&&null},{style:`font-style=normal`,clearMark:e=>e.type.name===this.name},{style:`font-style=italic`}]},renderHTML({HTMLAttributes:e}){return[`em`,j(this.options.HTMLAttributes,e),0]},addCommands(){return{setItalic:()=>({commands:e})=>e.setMark(this.name),toggleItalic:()=>({commands:e})=>e.toggleMark(this.name),unsetItalic:()=>({commands:e})=>e.unsetMark(this.name)}},markdownTokenName:`em`,parseMarkdown:(e,t)=>t.applyMark(`italic`,t.parseInline(e.tokens||[])),markdownOptions:{htmlReopen:{open:``,close:``}},renderMarkdown:(e,t)=>`*${t.renderChildren(e)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[Vp({find:XT,type:this.type}),Vp({find:QT,type:this.type})]},addPasteRules(){return[Jp({find:ZT,type:this.type}),Jp({find:$T,type:this.type})]}}),tE=`aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2odyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos6kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rck0msd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12b0cam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2oodside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2`,nE=`ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2`,rE=`numeric`,iE=`ascii`,aE=`alpha`,oE=`asciinumeric`,sE=`alphanumeric`,cE=`domain`,lE=`emoji`,uE=`scheme`,dE=`slashscheme`,fE=`whitespace`;function pE(e,t){return e in t||(t[e]=[]),t[e]}function mE(e,t,n){t[rE]&&(t[oE]=!0,t[sE]=!0),t[iE]&&(t[oE]=!0,t[aE]=!0),t[oE]&&(t[sE]=!0),t[aE]&&(t[sE]=!0),t[sE]&&(t[cE]=!0),t[lE]&&(t[cE]=!0);for(let r in t){let t=pE(r,n);t.indexOf(e)<0&&t.push(e)}}function hE(e,t){let n={};for(let r in t)t[r].indexOf(e)>=0&&(n[r]=!0);return n}function gE(e=null){this.j={},this.jr=[],this.jd=null,this.t=e}gE.groups={},gE.prototype={accepts(){return!!this.t},go(e){let t=this,n=t.j[e];if(n)return n;for(let n=0;ne.ta(t,n,r,i),vE=(e,t,n,r,i)=>e.tr(t,n,r,i),yE=(e,t,n,r,i)=>e.ts(t,n,r,i),F=(e,t,n,r,i)=>e.tt(t,n,r,i),bE=`WORD`,xE=`UWORD`,SE=`ASCIINUMERICAL`,CE=`ALPHANUMERICAL`,wE=`LOCALHOST`,TE=`TLD`,EE=`UTLD`,DE=`SCHEME`,OE=`SLASH_SCHEME`,kE=`NUM`,AE=`WS`,jE=`NL`,ME=`OPENBRACE`,NE=`CLOSEBRACE`,PE=`OPENBRACKET`,FE=`CLOSEBRACKET`,IE=`OPENPAREN`,LE=`CLOSEPAREN`,RE=`OPENANGLEBRACKET`,zE=`CLOSEANGLEBRACKET`,BE=`FULLWIDTHLEFTPAREN`,VE=`FULLWIDTHRIGHTPAREN`,HE=`LEFTCORNERBRACKET`,UE=`RIGHTCORNERBRACKET`,WE=`LEFTWHITECORNERBRACKET`,GE=`RIGHTWHITECORNERBRACKET`,KE=`FULLWIDTHLESSTHAN`,qE=`FULLWIDTHGREATERTHAN`,JE=`AMPERSAND`,YE=`APOSTROPHE`,XE=`ASTERISK`,ZE=`AT`,QE=`BACKSLASH`,$E=`BACKTICK`,eD=`CARET`,tD=`COLON`,nD=`COMMA`,rD=`DOLLAR`,iD=`DOT`,aD=`EQUALS`,oD=`EXCLAMATION`,sD=`HYPHEN`,cD=`PERCENT`,lD=`PIPE`,uD=`PLUS`,dD=`POUND`,fD=`QUERY`,pD=`QUOTE`,mD=`FULLWIDTHMIDDLEDOT`,hD=`SEMI`,gD=`SLASH`,_D=`TILDE`,vD=`UNDERSCORE`,yD=`EMOJI`,bD=`SYM`,xD=Object.freeze({__proto__:null,ALPHANUMERICAL:CE,AMPERSAND:JE,APOSTROPHE:YE,ASCIINUMERICAL:SE,ASTERISK:XE,AT:ZE,BACKSLASH:QE,BACKTICK:$E,CARET:eD,CLOSEANGLEBRACKET:zE,CLOSEBRACE:NE,CLOSEBRACKET:FE,CLOSEPAREN:LE,COLON:tD,COMMA:nD,DOLLAR:rD,DOT:iD,EMOJI:yD,EQUALS:aD,EXCLAMATION:oD,FULLWIDTHGREATERTHAN:qE,FULLWIDTHLEFTPAREN:BE,FULLWIDTHLESSTHAN:KE,FULLWIDTHMIDDLEDOT:mD,FULLWIDTHRIGHTPAREN:VE,HYPHEN:sD,LEFTCORNERBRACKET:HE,LEFTWHITECORNERBRACKET:WE,LOCALHOST:wE,NL:jE,NUM:kE,OPENANGLEBRACKET:RE,OPENBRACE:ME,OPENBRACKET:PE,OPENPAREN:IE,PERCENT:cD,PIPE:lD,PLUS:uD,POUND:dD,QUERY:fD,QUOTE:pD,RIGHTCORNERBRACKET:UE,RIGHTWHITECORNERBRACKET:GE,SCHEME:DE,SEMI:hD,SLASH:gD,SLASH_SCHEME:OE,SYM:bD,TILDE:_D,TLD:TE,UNDERSCORE:vD,UTLD:EE,UWORD:xE,WORD:bE,WS:AE}),SD=/[a-z]/,CD=/[a-z]/i,wD=/[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}]|\u{FE0F}/u;try{CD=RegExp(`\\p{L}`,`u`),wD=RegExp(`\\p{Emoji}`,`u`)}catch{}var TD=/\d/,ED=/\s/,DD=`\r`,OD=` +`,kD=`️`,AD=`‍`,jD=``,MD=null,ND=null;function PD(e=[]){let t={};gE.groups=t;let n=new gE;MD??=RD(tE),ND??=RD(nE),F(n,`'`,YE),F(n,`{`,ME),F(n,`}`,NE),F(n,`[`,PE),F(n,`]`,FE),F(n,`(`,IE),F(n,`)`,LE),F(n,`<`,RE),F(n,`>`,zE),F(n,`(`,BE),F(n,`)`,VE),F(n,`「`,HE),F(n,`」`,UE),F(n,`『`,WE),F(n,`』`,GE),F(n,`<`,KE),F(n,`>`,qE),F(n,`&`,JE),F(n,`*`,XE),F(n,`@`,ZE),F(n,"`",$E),F(n,`^`,eD),F(n,`:`,tD),F(n,`,`,nD),F(n,`$`,rD),F(n,`.`,iD),F(n,`=`,aD),F(n,`!`,oD),F(n,`-`,sD),F(n,`%`,cD),F(n,`|`,lD),F(n,`+`,uD),F(n,`#`,dD),F(n,`?`,fD),F(n,`"`,pD),F(n,`/`,gD),F(n,`;`,hD),F(n,`~`,_D),F(n,`_`,vD),F(n,`\\`,QE),F(n,`・`,mD);let r=vE(n,TD,kE,{[rE]:!0});vE(r,TD,r);let i=vE(r,SD,SE,{[oE]:!0}),a=vE(r,CD,CE,{[sE]:!0}),o=vE(n,SD,bE,{[iE]:!0});vE(o,TD,i),vE(o,SD,o),vE(i,TD,i),vE(i,SD,i);let s=vE(n,CD,xE,{[aE]:!0});vE(s,SD),vE(s,TD,a),vE(s,CD,s),vE(a,TD,a),vE(a,SD),vE(a,CD,a);let c=F(n,OD,jE,{[fE]:!0}),l=F(n,DD,AE,{[fE]:!0}),u=vE(n,ED,AE,{[fE]:!0});F(n,jD,u),F(l,OD,c),F(l,jD,u),vE(l,ED,u),F(u,DD),F(u,OD),vE(u,ED,u),F(u,jD,u);let d=vE(n,wD,yD,{[lE]:!0});F(d,`#`),vE(d,wD,d),F(d,kD,d);let f=F(d,AD);F(f,`#`),vE(f,wD,d);let p=[[SD,o],[TD,i]],m=[[SD,null],[CD,s],[TD,a]];for(let e=0;ee[0]>t[0]?1:-1);for(let t=0;t=0?i[cE]=!0:SD.test(r)?TD.test(r)?i[oE]=!0:i[iE]=!0:i[rE]=!0,yE(n,r,r,i)}return yE(n,`localhost`,wE,{ascii:!0}),n.jd=new gE(bD),{start:n,tokens:Object.assign({groups:t},xD)}}function FD(e,t){let n=ID(t.replace(/[A-Z]/g,e=>e.toLowerCase())),r=n.length,i=[],a=0,o=0;for(;o=0&&(d+=n[o].length,f++),l+=n[o].length,a+=n[o].length,o++;a-=d,o-=f,l-=d,i.push({t:u.t,v:t.slice(a-l,a),s:a-l,e:a})}return i}function ID(e){let t=[],n=e.length,r=0;for(;r56319||r+1===n||(a=e.charCodeAt(r+1))<56320||a>57343?e[r]:e.slice(r,r+2);t.push(o),r+=o.length}return t}function LD(e,t,n,r,i){let a,o=t.length;for(let n=0;n=0;)i++;if(i>0){t.push(n.join(``));for(let t=parseInt(e.substring(r,r+i),10);t>0;t--)n.pop();r+=i}else n.push(e[r]),r++}return t}var zD={defaultProtocol:`http`,events:null,format:VD,formatHref:VD,nl2br:!1,tagName:`a`,target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],ignoreClasses:[],render:null};function BD(e,t=null){let n=Object.assign({},zD);e&&(n=Object.assign(n,e instanceof BD?e.o:e));let r=n.ignoreTags,i=[];for(let e=0;e=0)return!0;return!1},defaultRender(e){return e},check(e){return this.get(`validate`,e.toString(),e)},get(e,t,n){let r=t!=null,i=this.o[e];return i&&(typeof i==`object`?(i=n.t in i?i[n.t]:zD[e],typeof i==`function`&&r&&(i=i(t,n))):typeof i==`function`&&r&&(i=i(t,n.t,n)),i)},getObj(e,t,n){let r=this.o[e];return typeof r==`function`&&t!=null&&(r=r(t,n.t,n)),r},render(e){let t=e.render(this);return(this.get(`render`,null,e)||this.defaultRender)(t,e.t,e)}};function VD(e){return e}function HD(e,t){this.t=`token`,this.v=e,this.tk=t}HD.prototype={isLink:!1,toString(){return this.v},toHref(e){return this.toString()},toFormattedString(e){let t=this.toString(),n=e.get(`truncate`,t,this),r=e.get(`format`,t,this);return n&&r.length>n?r.substring(0,n)+`…`:r},toFormattedHref(e){return e.get(`formatHref`,this.toHref(e.get(`defaultProtocol`)),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(e=zD.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(e),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(e){return{type:this.t,value:this.toFormattedString(e),isLink:this.isLink,href:this.toFormattedHref(e),start:this.startIndex(),end:this.endIndex()}},validate(e){return e.get(`validate`,this.toString(),this)},render(e){let t=this,n=this.toHref(e.get(`defaultProtocol`)),r=e.get(`formatHref`,n,this),i=e.get(`tagName`,n,t),a=this.toFormattedString(e),o={},s=e.get(`className`,n,t),c=e.get(`target`,n,t),l=e.get(`rel`,n,t),u=e.getObj(`attributes`,n,t),d=e.getObj(`events`,n,t);return o.href=r,s&&(o.class=s),c&&(o.target=c),l&&(o.rel=l),u&&Object.assign(o,u),{tagName:i,attributes:o,content:a,eventListeners:d}}};function UD(e,t){class n extends HD{constructor(t,n){super(t,n),this.t=e}}for(let e in t)n.prototype[e]=t[e];return n.t=e,n}var WD=UD(`email`,{isLink:!0,toHref(){return`mailto:`+this.toString()}}),GD=UD(`text`),KD=UD(`nl`),qD=UD(`url`,{isLink:!0,toHref(e=zD.defaultProtocol){return this.hasProtocol()?this.v:`${e}://${this.v}`},hasProtocol(){let e=this.tk;return e.length>=2&&e[0].t!==wE&&e[1].t===tD}}),JD=e=>new gE(e);function YD({groups:e}){let t=e.domain.concat([JE,XE,ZE,QE,$E,eD,rD,aD,sD,kE,cD,lD,uD,dD,gD,bD,_D,vD]),n=[YE,tD,nD,iD,oD,cD,fD,pD,hD,RE,zE,ME,NE,FE,PE,IE,LE,BE,VE,HE,UE,WE,GE,KE,qE],r=[JE,YE,XE,QE,$E,eD,rD,aD,sD,ME,NE,cD,lD,uD,dD,fD,gD,bD,_D,vD],i=JD(),a=F(i,_D);_E(a,r,a),_E(a,e.domain,a);let o=JD(),s=JD(),c=JD();_E(i,e.domain,o),_E(i,e.scheme,s),_E(i,e.slashscheme,c),_E(o,r,a),_E(o,e.domain,o);let l=F(o,ZE);F(a,ZE,l),F(s,ZE,l),F(c,ZE,l);let u=F(a,iD);_E(u,r,a),_E(u,e.domain,a);let d=JD();_E(l,e.domain,d),_E(d,e.domain,d);let f=F(d,iD);_E(f,e.domain,d);let p=JD(WD);_E(f,e.tld,p),_E(f,e.utld,p),F(l,wE,p);let m=F(d,sD);F(m,sD,m),_E(m,e.domain,d),_E(p,e.domain,d),F(p,iD,f),F(p,sD,m);let h=F(o,sD),g=F(o,iD);F(h,sD,h),_E(h,e.domain,o),_E(g,r,a),_E(g,e.domain,o);let _=JD(qD);_E(g,e.tld,_),_E(g,e.utld,_),_E(_,e.domain,o),_E(_,r,a),F(_,iD,g),F(_,sD,h),F(_,ZE,l);let v=F(_,tD),y=JD(qD);_E(v,e.numeric,y);let b=JD(qD),x=JD();_E(b,t,b),_E(b,n,x),_E(x,t,b),_E(x,n,x),F(_,gD,b),F(y,gD,b),F(_,fD,x),F(_,dD,b),F(y,fD,x),F(y,dD,b);let S=F(s,tD),C=F(F(F(c,tD),gD),gD);_E(s,e.domain,o),F(s,iD,g),F(s,sD,h),_E(c,e.domain,o),F(c,iD,g),F(c,sD,h),_E(S,e.domain,b),F(S,gD,b),F(S,fD,b),_E(C,e.domain,b),_E(C,t,b),F(C,gD,b);let ee=[[ME,NE],[PE,FE],[IE,LE],[RE,zE],[BE,VE],[HE,UE],[WE,GE],[KE,qE]];for(let e=0;e=0&&p++,m.push(c),s[i]&&s[i].has(c))break;for(let e=0,t=i-m.length+1;e0&&(a.push(ZD(GD,t,o)),o=[]),i-=p,d-=p;let e=f.t,r=n.slice(i-d,i);a.push(ZD(e,t,r))}}return o.length>0&&a.push(ZD(GD,t,o)),a}function ZD(e,t,n){let r=n[0].s,i=n[n.length-1].e;return new e(t.slice(r,i),n)}var QD=typeof console<`u`&&console&&console.warn||(()=>{}),$D=`until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.`,eO={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function tO(){return gE.groups={},eO.scanner=null,eO.parser=null,eO.tokenQueue=[],eO.pluginQueue=[],eO.customSchemes=[],eO.initialized=!1,eO}function nO(e,t=!1){if(eO.initialized&&QD(`linkifyjs: already initialized - will not register custom scheme "${e}" ${$D}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(e))throw Error(`linkifyjs: incorrect scheme format. 1. Must only contain digits, lowercase ASCII letters or "-" 2. Cannot start or end with "-" -3. "-" cannot repeat`);tO.customSchemes.push([e,t])}function iO(){tO.scanner=FD(tO.customSchemes);for(let e=0;ee.mark.type===n);if(!o.length)return;let{nodeAfter:s}=r;if(s&&o.some(e=>e.mark.isInSet(s.marks)))return;let c=e.storedMarks;e.removeMark(a,t.to,n),e.setStoredMarks(c),e.selection.empty&&e.selection.from===t.to&&e.removeStoredMark(n)}function pO(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function mO(e){return new D({key:new Un(`autolink`),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r,s=hu(n.doc,[...t]);if(!t.some(Jc)){let t=[];s.steps.forEach((e,n)=>{if(!(e instanceof Et)||!e.slice.size)return;let r=s.mapping.slice(n+1),i=r.map(e.from,1),a=r.map(e.from+e.slice.size,-1);it.to-e.to),t.forEach(t=>fO(o,t,e.type))}if($u(s).forEach(({newRange:t})=>{let n=_u(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!lO.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(cO).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=aO(n).map(t=>t.toObject(e.defaultProtocol));if(!pO(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>!r.schema.marks.code||!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code)).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{ed(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function hO(e){return new D({key:new Un(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=Xu(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}var gO=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)$/,_O=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)/g;function vO(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function yO(e,t){let n=0,r=0;for(;r0}function bO(e,t,n){let[,r,i]=t;return(t.index?e[t.index-1]:void 0)===`!`||vO(e,t.index??0)||yO(e,t.index??0)?!1:!!r.trim()&&n(i)}function xO(e){let[t,n,r,,i,a,o]=e,s=i??a??o;return{index:e.index??0,text:t,replaceWith:n,data:{href:r,title:s||null,markdown:!0}}}function SO(e,t){return e.index{let n=gO.exec(t);return!n||!bO(t,n,e.isAllowedHref)?null:xO(n)},type:e.type,getAttributes:CO});return new lp({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function TO(e){let t=Yp({find:t=>{let n=[];for(let r of t.matchAll(_O))bO(t,r,e.isAllowedHref)&&n.push(xO(r));let r=(e.findPlainUrls?.call(e,t)??[]).filter(e=>!n.some(t=>SO(t,e)));return[...n,...r]},type:e.type,getAttributes:CO});return new vp({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.match.data?.markdown&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function EO(e){return new D({key:new Un(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=oO(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function DO(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(dO,``).match(RegExp(`^(?:(?:${n.map(e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)).join(`|`)}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,`i`))}var OO=_p.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{typeof e==`string`?rO(e):rO(e.scheme,e.optionalSlashes)})},onDestroy(){nO()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,markdownLinks:!1,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!DO(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target??null},rel:{default:this.options.HTMLAttributes.rel??null},class:{default:this.options.HTMLAttributes.class??null},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,A(this.options.HTMLAttributes,e),0]:[`a`,A(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addInputRules(){return this.options.markdownLinks?[wO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})})]:[]},addPasteRules(){let e=e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options;oO(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!DO(e,n),protocols:n,defaultProtocol:r})).forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t};return this.options.markdownLinks?[TO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!DO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}),findPlainUrls:e})]:[Yp({find:e,type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(mO({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!DO(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(hO({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`||this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(EO({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),kO=`listItem`,AO=`textStyle`,jO=/^\s*([-+*])\s$/,MO=Jp.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(kO,this.editor.getAttributes(AO)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=Gp({find:jO,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=Gp({find:jO,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(AO),editor:this.editor})),[e]}}),NO=(e,t,n)=>{let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;if(!i.parent.isTextblock||i.parentOffset!==i.parent.content.size)return null;let a=-1;for(let e=i.depth;e>0;--e)if(i.node(e).type.name===t){a=e;break}if(a<0)return null;let o=i.node(a),s=i.index(a);if(s+1>=o.childCount)return null;let c=o.child(s+1);if(!n.includes(c.type.name))return null;let l=e.schema.nodes[t],u=!1;if(c.forEach(e=>{e.type===l&&e.childCount>1&&(u=!0)}),!u)return null;let d=e.doc.resolve(i.after()).nodeAfter;if(!d||!n.includes(d.type.name))return null;let f=[];return d.forEach(e=>{f.push(e)}),f.length===0?null:{listItemDepth:a,nestedList:d,nestedListPos:i.after(),insertPos:i.after(a),items:f}},PO=(e,t,n,r)=>{let i=NO(e,n,r);if(!i)return!1;let{selection:a}=e,{nestedList:o,nestedListPos:c,insertPos:l,items:u}=i,d=e.tr;d.delete(c,c+o.nodeSize);let f=d.mapping.map(l);return d.insert(f,s.from(u)),d.setSelection(a.map(d.doc,d.mapping)),t&&t(d),!0},FO=(e,t,n)=>PO(e.state,e.view.dispatch,t,n),IO=(e,t)=>Tp.create({name:`${e}BranchingDeleteKeymap`,priority:101,addKeyboardShortcuts(){let n=()=>FO(this.editor,e,t);return{Delete:n,"Mod-Delete":n}}}),LO=[[1e3,`m`],[900,`cm`],[500,`d`],[400,`cd`],[100,`c`],[90,`xc`],[50,`l`],[40,`xl`],[10,`x`],[9,`ix`],[5,`v`],[4,`iv`],[1,`i`]],RO=`abcdefghijklmnopqrstuvwxyz`,zO=String.raw`\d+|[ivxlcdmIVXLCDM]+|${`[a-zA-Z]{1,2}`}`;function BO(e){let t=e,n=``;for(let[e,r]of LO)for(;t>=e;)n+=r,t-=e;return n}function VO(e){return BO(e).toUpperCase()}function HO(e){let t=e.toLowerCase(),n=0,r=0;for(;n0?t:1}let n=parseInt(e,10);return Number.isNaN(n)?1:n}function JO(e,t){if(e===`numeric`)return String(t);switch(e){case`a`:return GO(t);case`A`:return GO(t).toUpperCase();case`i`:return BO(t);case`I`:return VO(t);default:return String(t)}}function YO(e){if(e.length===0)return!1;let t=KO(e[0])??`numeric`,n=qO(e[0]);if(n<1)return!1;for(let r=0;r(e?.level??nk)>nk;function ik(e){let t=e.tokens?.[0];return!!(e.text&&e.tokens?.length===1&&t?.type===`list`&&t.ordered&&t.raw===e.text)}function ak(e,t){return t.tokenizeInline?t.parseInline(t.tokenizeInline(e)):t.parseInline([{type:`text`,raw:e,text:e}])}var ok=Jp.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=t.parseBlockChildren??t.parseChildren,r=[];if(e.tokens&&e.tokens.length>0){if(ik(e))return{type:`listItem`,content:[{type:`paragraph`,content:ak(e.text||``,t)}]};let[i,...a]=e.tokens;if(i.type===`heading`)return{type:`listItem`,content:[{type:`paragraph`,content:t.parseInline(i.tokens??[])},...a.length>0?n(a):[]]};if(e.tokens.some(e=>e.type===`paragraph`))r=n(e.tokens);else if(i.type===`text`&&i.tokens&&i.tokens.length>0){if(r=[{type:`paragraph`,content:t.parseInline(i.tokens)}],e.tokens.length>1){let t=n(e.tokens.slice(1));r.push(...t)}}else r=n(e.tokens)}return r.length===0&&(r=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:$O(r)}},renderMarkdown:(e,t,n)=>{let r=e=>{if(e.parentType===`bulletList`)return`- `;if(e.parentType===`orderedList`){var t,n;let r=((t=e.meta)==null||(t=t.parentAttrs)==null?void 0:t.start)||1;return QO((n=e.meta)==null||(n=n.parentAttrs)==null?void 0:n.type,r-1+(e.index||0),`. `)}return`- `},i=op(e,t,r,n,{alignNestedToPrefix:n?.parentType===`orderedList`});if(!ek(e)||!rk(n))return i;let a=r(n);return`${a}${tk}${i.slice(a.length)}`},addExtensions(){return[IO(this.name,[this.options.bulletListTypeName,this.options.orderedListTypeName])]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),sk=(e,t)=>{let{$from:n}=t.selection,r=il(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},ck=(e,t)=>{let n=sk(e,t);if(!n)return!1;let[,r]=td(t,e,n.$pos.pos+4);return r},lk=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},uk=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!Zl(e.state,t)&&lk(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().command(({tr:e})=>{let t=o.end();return e.delete(n.before(),n.after()).insert(t,n.parent),e.setSelection(T.create(e.doc,t+1)),!0}).command(({state:e,dispatch:t})=>(qn(e,t),!0)).run()}if(!Zl(e.state,t)||!ld(e.state))return!1;let{$from:r}=e.state.selection,i=r.depth-1;return r.node(i).type!==e.schema.nodes[t]||r.index(i)!==0?!1:e.chain().liftListItem(t).run()},dk=(e,t)=>{let n=ck(e,t),r=sk(e,t);return!r||!n?!1:n>r.depth},fk=(e,t)=>{let n=ck(e,t),r=sk(e,t);return!r||!n?!1:n!Zl(e.state,t)||!cd(e.state,t)||!e.state.selection.empty?!1:dk(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():fk(t,e.state)?e.commands.command(({state:e,dispatch:t})=>Jn(e,t)):e.commands.joinItemForward(),mk=(e,t,n)=>{let{state:r}=e,{selection:i}=r;if(!i.empty)return!1;let{$from:a}=i;if(a.parentOffset!==0||!a.parent.isTextblock||Zl(r,t))return!1;let o=nd(a);if(!o||!n.includes(o.type.name))return!1;let c=o.lastChild;if(!c||c.type.name!==t)return!1;let l=a.parent;if(!c.canReplace(c.childCount,c.childCount,s.from(l)))return!1;let u=a.before(),d=a.after(),f=u-2;return e.commands.command(({tr:e,dispatch:t})=>(t&&(e.delete(u,d).insert(f,s.from(l)),e.setSelection(T.create(e.doc,f+1)),e.scrollIntoView()),!0))},hk=Tp.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&pk(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&pk(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&uk(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&uk(e,n,r)&&(t=!0)}),t},Tab:({editor:e})=>{for(let{itemName:t,wrapperNames:n}of this.options.listTypes)if(e.state.schema.nodes[t]!==void 0&&mk(e,t,n))return!0;return!1}}}}),gk=RegExp(`^(\\s*)(${zO})([.)])\\s+(.*)$`),_k=/^\s/,vk={heading:/^#{1,6}(?:\s|$)/,bulletItem:/^[-+*]\s+/,codeFence:/^(?:```|~~~)/,blockMath:/^\$\$/,thematicBreak:/^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/};function yk(e){return gk.test(e.trimStart())}function bk(e){let t=e.trimStart();return vk.bulletItem.test(t)||yk(t)||vk.heading.test(t)||vk.thematicBreak.test(t)&&!t.startsWith(`-`)||/^>\s?/.test(t)||vk.codeFence.test(t)||vk.blockMath.test(t)}function xk(e){return Object.values(vk).some(t=>t.test(e))}function Sk(e){let t=[],n=[],r=!1;return e.forEach(e=>{r?n.push(e):e.trim()===``||t.length>0&&bk(e)?(r=!0,n.push(e)):t.push(e)}),{paragraphLines:t,blockLines:n}}function Ck(e){let t=[],n=0,r=0;for(;ne.mark.type===n);if(!o.length)return;let{nodeAfter:s}=r;if(s&&o.some(e=>e.mark.isInSet(s.marks)))return;let c=e.storedMarks;e.removeMark(a,t.to,n),e.setStoredMarks(c),e.selection.empty&&e.selection.from===t.to&&e.removeStoredMark(n)}function fO(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function pO(e){return new D({key:new O(`autolink`),appendTransaction:(t,n,r)=>{let i=t.some(e=>e.docChanged)&&!n.doc.eq(r.doc),a=t.some(e=>e.getMeta(`preventAutolink`));if(!i||a)return;let{tr:o}=r,s=mu(n.doc,[...t]);if(!t.some(qc)){let t=[];s.steps.forEach((e,n)=>{if(!(e instanceof Et)||!e.slice.size)return;let r=s.mapping.slice(n+1),i=r.map(e.from,1),a=r.map(e.from+e.slice.size,-1);it.to-e.to),t.forEach(t=>dO(o,t,e.type))}if(Qu(s).forEach(({newRange:t})=>{let n=gu(r.doc,t,e=>e.isTextblock),i,a;if(n.length>1)i=n[0],a=r.doc.textBetween(i.pos,i.pos+i.node.nodeSize,void 0,` `);else if(n.length){let e=r.doc.textBetween(t.from,t.to,` `,` `);if(!cO.test(e))return;i=n[0],a=r.doc.textBetween(i.pos,t.to,void 0,` `)}if(i&&a){let t=a.split(sO).filter(Boolean);if(t.length<=0)return!1;let n=t[t.length-1],s=i.pos+a.lastIndexOf(n);if(!n)return!1;let c=iO(n).map(t=>t.toObject(e.defaultProtocol));if(!fO(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:s+e.start+1,to:s+e.end+1})).filter(e=>!r.schema.marks.code||!r.doc.rangeHasMark(e.from,e.to,r.schema.marks.code)).filter(t=>e.validate(t.value)).filter(t=>e.shouldAutoLink(t.value)).forEach(t=>{$u(t.from,t.to,r.doc).some(t=>t.mark.type===e.type)||o.addMark(t.from,t.to,e.type.create({href:t.href}))})}}),o.steps.length)return o}})}function mO(e){return new D({key:new O(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let i=null;if(r.target instanceof HTMLAnchorElement)i=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;i=t.closest(`a`),i&&!n.contains(i)&&(i=null)}if(!i)return!1;let a=!1;if(e.enableClickSelection&&(a=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){let n=Yu(t.state,e.type.name),r=i.href??n.href,o=i.target??n.target;r&&(window.open(r,o),a=!0)}return a}}})}var hO=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)$/,gO=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)/g;function _O(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function vO(e,t){let n=0,r=0;for(;r0}function yO(e,t,n){let[,r,i]=t;return(t.index?e[t.index-1]:void 0)===`!`||_O(e,t.index??0)||vO(e,t.index??0)?!1:!!r.trim()&&n(i)}function bO(e){let[t,n,r,,i,a,o]=e,s=i??a??o;return{index:e.index??0,text:t,replaceWith:n,data:{href:r,title:s||null,markdown:!0}}}function xO(e,t){return e.index{let n=hO.exec(t);return!n||!yO(t,n,e.isAllowedHref)?null:bO(n)},type:e.type,getAttributes:SO});return new cp({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function wO(e){let t=Jp({find:t=>{let n=[];for(let r of t.matchAll(gO))yO(t,r,e.isAllowedHref)&&n.push(bO(r));let r=(e.findPlainUrls?.call(e,t)??[]).filter(e=>!n.some(t=>xO(t,e)));return[...n,...r]},type:e.type,getAttributes:SO});return new _p({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.match.data?.markdown&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function TO(e){return new D({key:new O(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=aO(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}function EO(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(uO,``).match(RegExp(`^(?:(?:${n.map(e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)).join(`|`)}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,`i`))}var DO=gp.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{typeof e==`string`?nO(e):nO(e.scheme,e.optionalSlashes)})},onDestroy(){tO()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,markdownLinks:!1,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>!!EO(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:this.options.HTMLAttributes.target??null},rel:{default:this.options.HTMLAttributes.rel??null},class:{default:this.options.HTMLAttributes.class??null},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!EO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!EO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,j(this.options.HTMLAttributes,e),0]:[`a`,j(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{let n=e.attrs?.href??``,r=e.attrs?.title??``,i=t.renderChildren(e);return r?`[${i}](${n} "${r}")`:`[${i}](${n})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!EO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!EO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addInputRules(){return this.options.markdownLinks?[CO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!EO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})})]:[]},addPasteRules(){let e=e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options;aO(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!EO(e,n),protocols:n,defaultProtocol:r})).forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t};return this.options.markdownLinks?[wO({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!EO(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}),findPlainUrls:e})]:[Jp({find:e,type:this.type,getAttributes:e=>({href:e.data?.href})})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(pO({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!EO(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(mO({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`||this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(TO({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}}),OO=`listItem`,kO=`textStyle`,AO=/^\s*([-+*])\s$/,jO=qp.create({name:`bulletList`,addOptions(){return{itemTypeName:`listItem`,HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul`}]},renderHTML({HTMLAttributes:e}){return[`ul`,j(this.options.HTMLAttributes,e),0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>e.type!==`list`||e.ordered?[]:{type:`bulletList`,content:e.items?t.parseChildren(e.items):[]},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(OO,this.editor.getAttributes(kO)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let e=Wp({find:AO,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(e=Wp({find:AO,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(kO),editor:this.editor})),[e]}}),MO=(e,t,n)=>{let{selection:r}=e;if(!r.empty)return null;let{$from:i}=r;if(!i.parent.isTextblock||i.parentOffset!==i.parent.content.size)return null;let a=-1;for(let e=i.depth;e>0;--e)if(i.node(e).type.name===t){a=e;break}if(a<0)return null;let o=i.node(a),s=i.index(a);if(s+1>=o.childCount)return null;let c=o.child(s+1);if(!n.includes(c.type.name))return null;let l=e.schema.nodes[t],u=!1;if(c.forEach(e=>{e.type===l&&e.childCount>1&&(u=!0)}),!u)return null;let d=e.doc.resolve(i.after()).nodeAfter;if(!d||!n.includes(d.type.name))return null;let f=[];return d.forEach(e=>{f.push(e)}),f.length===0?null:{listItemDepth:a,nestedList:d,nestedListPos:i.after(),insertPos:i.after(a),items:f}},NO=(e,t,n,r)=>{let i=MO(e,n,r);if(!i)return!1;let{selection:a}=e,{nestedList:o,nestedListPos:c,insertPos:l,items:u}=i,d=e.tr;d.delete(c,c+o.nodeSize);let f=d.mapping.map(l);return d.insert(f,s.from(u)),d.setSelection(a.map(d.doc,d.mapping)),t&&t(d),!0},PO=(e,t,n)=>NO(e.state,e.view.dispatch,t,n),FO=(e,t)=>wp.create({name:`${e}BranchingDeleteKeymap`,priority:101,addKeyboardShortcuts(){let n=()=>PO(this.editor,e,t);return{Delete:n,"Mod-Delete":n}}}),IO=[[1e3,`m`],[900,`cm`],[500,`d`],[400,`cd`],[100,`c`],[90,`xc`],[50,`l`],[40,`xl`],[10,`x`],[9,`ix`],[5,`v`],[4,`iv`],[1,`i`]],LO=`abcdefghijklmnopqrstuvwxyz`,RO=String.raw`\d+|[ivxlcdmIVXLCDM]+|${`[a-zA-Z]{1,2}`}`;function zO(e){let t=e,n=``;for(let[e,r]of IO)for(;t>=e;)n+=r,t-=e;return n}function BO(e){return zO(e).toUpperCase()}function VO(e){let t=e.toLowerCase(),n=0,r=0;for(;n0?t:1}let n=parseInt(e,10);return Number.isNaN(n)?1:n}function qO(e,t){if(e===`numeric`)return String(t);switch(e){case`a`:return WO(t);case`A`:return WO(t).toUpperCase();case`i`:return zO(t);case`I`:return BO(t);default:return String(t)}}function JO(e){if(e.length===0)return!1;let t=GO(e[0])??`numeric`,n=KO(e[0]);if(n<1)return!1;for(let r=0;r(e?.level??tk)>tk;function rk(e){let t=e.tokens?.[0];return!!(e.text&&e.tokens?.length===1&&t?.type===`list`&&t.ordered&&t.raw===e.text)}function ik(e,t){return t.tokenizeInline?t.parseInline(t.tokenizeInline(e)):t.parseInline([{type:`text`,raw:e,text:e}])}var ak=qp.create({name:`listItem`,addOptions(){return{HTMLAttributes:{},bulletListTypeName:`bulletList`,orderedListTypeName:`orderedList`}},content:`paragraph block*`,defining:!0,parseHTML(){return[{tag:`li`}]},renderHTML({HTMLAttributes:e}){return[`li`,j(this.options.HTMLAttributes,e),0]},markdownTokenName:`list_item`,parseMarkdown:(e,t)=>{if(e.type!==`list_item`)return[];let n=t.parseBlockChildren??t.parseChildren,r=[];if(e.tokens&&e.tokens.length>0){if(rk(e))return{type:`listItem`,content:[{type:`paragraph`,content:ik(e.text||``,t)}]};let[i,...a]=e.tokens;if(i.type===`heading`)return{type:`listItem`,content:[{type:`paragraph`,content:t.parseInline(i.tokens??[])},...a.length>0?n(a):[]]};if(e.tokens.some(e=>e.type===`paragraph`))r=n(e.tokens);else if(i.type===`text`&&i.tokens&&i.tokens.length>0){if(r=[{type:`paragraph`,content:t.parseInline(i.tokens)}],e.tokens.length>1){let t=n(e.tokens.slice(1));r.push(...t)}}else r=n(e.tokens)}return r.length===0&&(r=[{type:`paragraph`,content:[]}]),{type:`listItem`,content:QO(r)}},renderMarkdown:(e,t,n)=>{let r=e=>{if(e.parentType===`bulletList`)return`- `;if(e.parentType===`orderedList`){var t,n;let r=((t=e.meta)==null||(t=t.parentAttrs)==null?void 0:t.start)||1;return ZO((n=e.meta)==null||(n=n.parentAttrs)==null?void 0:n.type,r-1+(e.index||0),`. `)}return`- `},i=ap(e,t,r,n,{alignNestedToPrefix:n?.parentType===`orderedList`});if(!$O(e)||!nk(n))return i;let a=r(n);return`${a}${ek}${i.slice(a.length)}`},addExtensions(){return[FO(this.name,[this.options.bulletListTypeName,this.options.orderedListTypeName])]},addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),ok=(e,t)=>{let{$from:n}=t.selection,r=rl(e,t.schema),i=null,a=n.depth,o=n.pos,s=null;for(;a>0&&s===null;)i=n.node(a),i.type===r?s=a:(--a,--o);return s===null?null:{$pos:t.doc.resolve(o),depth:s}},sk=(e,t)=>{let n=ok(e,t);if(!n)return!1;let[,r]=ed(t,e,n.$pos.pos+4);return r},ck=(e,t,n)=>{let{$anchor:r}=e.selection,i=Math.max(0,r.pos-2),a=e.doc.resolve(i).node();return!(!a||!n.includes(a.type.name))},lk=(e,t,n)=>{if(e.commands.undoInputRule())return!0;if(e.state.selection.from!==e.state.selection.to)return!1;if(!Xl(e.state,t)&&ck(e.state,t,n)){let{$anchor:n}=e.state.selection,r=e.state.doc.resolve(n.before()-1),i=[];r.node().descendants((e,n)=>{e.type.name===t&&i.push({node:e,pos:n})});let a=i.at(-1);if(!a)return!1;let o=e.state.doc.resolve(r.start()+a.pos+1);return e.chain().command(({tr:e})=>{let t=o.end();return e.delete(n.before(),n.after()).insert(t,n.parent),e.setSelection(T.create(e.doc,t+1)),!0}).command(({state:e,dispatch:t})=>(Kn(e,t),!0)).run()}if(!Xl(e.state,t)||!cd(e.state))return!1;let{$from:r}=e.state.selection,i=r.depth-1;return r.node(i).type!==e.schema.nodes[t]||r.index(i)!==0?!1:e.chain().liftListItem(t).run()},uk=(e,t)=>{let n=sk(e,t),r=ok(e,t);return!r||!n?!1:n>r.depth},dk=(e,t)=>{let n=sk(e,t),r=ok(e,t);return!r||!n?!1:n!Xl(e.state,t)||!sd(e.state,t)||!e.state.selection.empty?!1:uk(t,e.state)?e.chain().focus(e.state.selection.from+4).lift(t).joinBackward().run():dk(t,e.state)?e.commands.command(({state:e,dispatch:t})=>qn(e,t)):e.commands.joinItemForward(),pk=(e,t,n)=>{let{state:r}=e,{selection:i}=r;if(!i.empty)return!1;let{$from:a}=i;if(a.parentOffset!==0||!a.parent.isTextblock||Xl(r,t))return!1;let o=td(a);if(!o||!n.includes(o.type.name))return!1;let c=o.lastChild;if(!c||c.type.name!==t)return!1;let l=a.parent;if(!c.canReplace(c.childCount,c.childCount,s.from(l)))return!1;let u=a.before(),d=a.after(),f=u-2;return e.commands.command(({tr:e,dispatch:t})=>(t&&(e.delete(u,d).insert(f,s.from(l)),e.setSelection(T.create(e.doc,f+1)),e.scrollIntoView()),!0))},mk=wp.create({name:`listKeymap`,addOptions(){return{listTypes:[{itemName:`listItem`,wrapperNames:[`bulletList`,`orderedList`]},{itemName:`taskItem`,wrapperNames:[`taskList`]}]}},addKeyboardShortcuts(){return{Delete:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&fk(e,n)&&(t=!0)}),t},"Mod-Delete":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n})=>{e.state.schema.nodes[n]!==void 0&&fk(e,n)&&(t=!0)}),t},Backspace:({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&lk(e,n,r)&&(t=!0)}),t},"Mod-Backspace":({editor:e})=>{let t=!1;return this.options.listTypes.forEach(({itemName:n,wrapperNames:r})=>{e.state.schema.nodes[n]!==void 0&&lk(e,n,r)&&(t=!0)}),t},Tab:({editor:e})=>{for(let{itemName:t,wrapperNames:n}of this.options.listTypes)if(e.state.schema.nodes[t]!==void 0&&pk(e,t,n))return!0;return!1}}}}),hk=RegExp(`^(\\s*)(${RO})([.)])\\s+(.*)$`),gk=/^\s/,_k={heading:/^#{1,6}(?:\s|$)/,bulletItem:/^[-+*]\s+/,codeFence:/^(?:```|~~~)/,blockMath:/^\$\$/,thematicBreak:/^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/};function vk(e){return hk.test(e.trimStart())}function yk(e){let t=e.trimStart();return _k.bulletItem.test(t)||vk(t)||_k.heading.test(t)||_k.thematicBreak.test(t)&&!t.startsWith(`-`)||/^>\s?/.test(t)||_k.codeFence.test(t)||_k.blockMath.test(t)}function bk(e){return Object.values(_k).some(t=>t.test(e))}function xk(e){let t=[],n=[],r=!1;return e.forEach(e=>{r?n.push(e):e.trim()===``||t.length>0&&yk(e)?(r=!0,n.push(e)):t.push(e)}),{paragraphLines:t,blockLines:n}}function Sk(e){let t=[],n=0,r=0;for(;ne.trim().length>0);if(t.length===0)return null;let n=[];for(let e of t){let t=e.trim().match(wk);if(!t)return null;n.push({marker:t[1],content:t[3]})}return YO(n.map(e=>e.marker))?{type:`orderedList`,attrs:ZO(n[0].marker),content:n.map(e=>({type:`listItem`,content:[{type:`paragraph`,content:[{type:`text`,text:e.content}]}]}))}:null}function Ek(e,t,n){let r=[],i=0;for(;ie.trim().length>0);if(t.length===0)return null;let n=[];for(let e of t){let t=e.trim().match(Ck);if(!t)return null;n.push({marker:t[1],content:t[3]})}return JO(n.map(e=>e.marker))?{type:`orderedList`,attrs:XO(n[0].marker),content:n.map(e=>({type:`listItem`,content:[{type:`paragraph`,content:[{type:`text`,text:e.content}]}]}))}:null}function Tk(e,t,n){let r=[],i=0;for(;it;)f.push(e[d]),d+=1;if(f.length>0){let e=Ek(f,Math.min(...f.map(e=>e.indent)),n);l.push({type:`list`,ordered:!0,start:f[0].number,typeMarker:f[0].type,items:e,raw:f.map(e=>e.raw).join(` -`)})}r.push({type:`list_item`,raw:a.raw,tokens:l}),i=d}else i+=1}return r}function Dk(e,t){return e.map(e=>{if(e.type!==`list_item`)return t.parseChildren([e])[0];let n=[];return e.tokens&&e.tokens.length>0&&e.tokens.forEach(e=>{if(e.type===`paragraph`||e.type===`list`||e.type===`blockquote`||e.type===`code`)n.push(...t.parseChildren([e]));else if(e.type===`text`&&e.tokens){let r=t.parseChildren([e]);n.push({type:`paragraph`,content:r})}else{let r=t.parseChildren([e]);r.length>0&&n.push(...r)}}),{type:`listItem`,content:n}})}var Ok=64;function kk(e,t){let n=[],r=0;for(;n.lengthe.hasAttribute(`start`)?parseInt(e.getAttribute(`start`)||``,10):1},type:{default:null,parseHTML:e=>{let t=e.getAttribute(`type`);if(t)return t;let n=e.getAttribute(`style`);if(n){let e=Pk(n);if(e)return e}let r=e.querySelector(`li`);if(r){let e=r.getAttribute(`style`);if(e){let t=Pk(e);if(t)return t}}return null}}}},parseHTML(){return[{tag:`ol`}]},renderHTML({HTMLAttributes:e}){let{start:t,type:n,...r}=e,i=A(this.options.HTMLAttributes,r);return t!==1&&(i.start=t),n&&n!==`1`&&(i.type=n),[`ol`,i,0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>{if(e.type!==`list`||!e.ordered)return[];let n=e.start||1,r=e.typeMarker,i=e.items?Dk(e.items,t):[],a={};return n!==1&&(a.start=n),r&&(a.type=r),Object.keys(a).length>0?{type:`orderedList`,attrs:a,content:i}:{type:`orderedList`,content:i}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownTokenizer:{name:`orderedList`,level:`block`,start:()=>-1,tokenize:(e,t,n)=>{let[r,i,a]=Ak(e);if(r.length===0)return;let o=Ek(r,r[0].indent,n);if(o.length!==0)return{type:`list`,ordered:!0,start:r[0]?.number||1,typeMarker:r[0]?.type,items:o,raw:a.slice(0,i).join(` -`)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(jk,this.editor.getAttributes(Mk)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addProseMirrorPlugins(){return[new D({props:{handlePaste:(e,t)=>{if((t.clipboardData?.getData(`text/html`))?.trim())return!1;let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=Tk(n);if(!r)return!1;try{let t=e.state.schema.nodeFromJSON(r),n=e.state.tr.replaceSelectionWith(t);return e.dispatch(n),!0}catch{return!1}}}})]},addInputRules(){let e=(e,t)=>(!t.attrs.type||t.attrs.type===`1`)&&t.childCount+t.attrs.start===+e[1],t=Gp({find:Nk,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:e});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Gp({find:Nk,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(Mk)}),joinPredicate:e,editor:this.editor})),[t]}}),Ik=/^\s*(\[([( |x])?\])\s$/,Lk=`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0`,Rk=(e,t,n)=>{var r;return(n==null||(r=n.checkboxLabel)==null?void 0:r.call(n,e,t))||`Task item checkbox for ${e.textContent||`empty task item`}`},zk=Jp.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51,contentElement:e=>e.querySelector(`div`)??e}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,A(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>op(e,t,`- [${e.attrs?.checked?`x`:` `}] `,void 0,{indentMainContent:!0}),addExtensions(){return this.options.nested?[IO(this.name,[this.options.taskListTypeName])]:[]},addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`);o.style.cssText=Lk;let l=e=>{let t=Rk(e,e.attrs.checked,this.options.a11y);s.setAttribute(`aria-label`,t),o.textContent=t};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=Lu(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[Gp({find:Ik,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),Bk=Jp.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,A(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` -`):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=rp(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(t){let r={type:`taskList`,raw:t.raw,items:t.items},i=e.slice(t.raw.length);return i.trim()?[r,...n.blockTokens(i)]:[r]}return n.blockTokens(e)},i=rp(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});Tp.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(MO.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(ok.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(hk.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(Fk.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(zk.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(Bk.configure(this.options.taskList)),e}});var Vk=` `,Hk=`\xA0`,Uk=Jp.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,A(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===Vk||n[0].text===Vk||n[0].raw===Hk||n[0].text===Hk)&&r.length===1&&r[0].type===`text`&&(r[0].text===Vk||r[0].text===Hk)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){var i,a;let e=Array.isArray(n==null||(i=n.previousNode)==null?void 0:i.content)?n.previousNode.content:[];return(n==null||(a=n.previousNode)==null?void 0:a.type)===`paragraph`&&e.length===0?Vk:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Wk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,Gk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,Kk=_p.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,A(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Hp({find:Wk,type:this.type})]},addPasteRules(){return[Yp({find:Gk,type:this.type})]}}),qk=Jp.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),Jk=_p.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,A(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`${t.renderChildren(e)}`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.toLowerCase().indexOf(``)},tokenize(e,t,n){if(!/^/i.test(e))return;let r=/\\[\s\S]|`+|<\/u>/gi;r.lastIndex=3;let i=r.exec(e);for(;i;){if(i[0].startsWith("`")){let t=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/.exec(e.slice(i.index));t&&(r.lastIndex=i.index+t[0].length)}else if(!i[0].startsWith(`\\`)){let t=e.slice(3,i.index);return t?{type:`underline`,raw:e.slice(0,r.lastIndex),text:t,tokens:n.inlineTokens(t)}:void 0}i=r.exec(e)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),Yk=Tp.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(LT.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(MT.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(MO.configure(this.options.bulletList)),this.options.code!==!1&&e.push(VT.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(GT.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(qT.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(Xw.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(Zw.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(JT.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(YT.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(ST.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(XT.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(tE.configure(this.options.italic)),this.options.listItem!==!1&&e.push(ok.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(hk.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(OO.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(Fk.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(Uk.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(Kk.configure(this.options.strike)),this.options.text!==!1&&e.push(qk.configure(this.options.text)),this.options.underline!==!1&&e.push(Jk.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(xT.configure(this.options?.trailingNode)),e}}),Xk=Math.min,Zk=Math.max,Qk=Math.round,$k=Math.floor,eA=e=>({x:e,y:e}),tA={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function nA(e,t,n){return Zk(e,Xk(t,n))}function rA(e,t){return typeof e==`function`?e(t):e}function iA(e){return e.split(`-`)[0]}function aA(e){return e.split(`-`)[1]}function oA(e){return e===`x`?`y`:`x`}function sA(e){return e===`y`?`height`:`width`}function cA(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function lA(e){return oA(cA(e))}function uA(e,t,n){n===void 0&&(n=!1);let r=aA(e),i=lA(e),a=sA(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=yA(o)),[o,yA(o)]}function dA(e){let t=yA(e);return[fA(e),t,fA(t)]}function fA(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var pA=[`left`,`right`],mA=[`right`,`left`],hA=[`top`,`bottom`],gA=[`bottom`,`top`];function _A(e,t,n){switch(e){case`top`:case`bottom`:return n?t?mA:pA:t?pA:mA;case`left`:case`right`:return t?hA:gA;default:return[]}}function vA(e,t,n,r){let i=aA(e),a=_A(iA(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(fA)))),a}function yA(e){let t=iA(e);return tA[t]+e.slice(t.length)}function bA(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function xA(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:bA(e)}function SA(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function CA(e,t,n){let{reference:r,floating:i}=e,a=cA(t),o=lA(t),s=sA(o),c=iA(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=aA(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function wA(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=rA(t,e),p=xA(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=SA(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=SA(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var TA=50,EA=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:wA},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=CA(l,r,c),f=r,p=0,m={};for(let n=0;ne<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===cA(t)||te.every(e=>cA(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:te},reset:{placement:t}};let n=te.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=te.filter(e=>{if(x){let t=cA(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},OA=new Set([`left`,`top`]);async function kA(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=iA(n),s=aA(n),c=cA(n)===`y`,l=OA.has(o)?-1:1,u=a&&c?-1:1,d=rA(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var AA=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await kA(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},jA=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=rA(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=cA(i),p=oA(f),m=u[p],h=u[f],g=(e,t)=>nA(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}};function MA(){return typeof window<`u`}function NA(e){return IA(e)?(e.nodeName||``).toLowerCase():`#document`}function PA(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function FA(e){return((IA(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function IA(e){return MA()?e instanceof Node||e instanceof PA(e).Node:!1}function LA(e){return MA()?e instanceof Element||e instanceof PA(e).Element:!1}function RA(e){return MA()?e instanceof HTMLElement||e instanceof PA(e).HTMLElement:!1}function zA(e){return!MA()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof PA(e).ShadowRoot}function BA(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=ZA(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function VA(e){return/^(table|td|th)$/.test(NA(e))}function HA(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var UA=/transform|translate|scale|rotate|perspective|filter/,WA=/paint|layout|strict|content/,GA=e=>!!e&&e!==`none`,KA;function qA(e){let t=LA(e)?ZA(e):e;return GA(t.transform)||GA(t.translate)||GA(t.scale)||GA(t.rotate)||GA(t.perspective)||!YA()&&(GA(t.backdropFilter)||GA(t.filter))||UA.test(t.willChange||``)||WA.test(t.contain||``)}function JA(e){let t=$A(e);for(;RA(t)&&!XA(t);){if(qA(t))return t;if(HA(t))return null;t=$A(t)}return null}function YA(){return KA??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),KA}function XA(e){return/^(html|body|#document)$/.test(NA(e))}function ZA(e){return PA(e).getComputedStyle(e)}function QA(e){return LA(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $A(e){if(NA(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||zA(e)&&e.host||FA(e);return zA(t)?t.host:t}function ej(e){let t=$A(e);return XA(t)?(e.ownerDocument||e).body:RA(t)&&BA(t)?t:ej(t)}function tj(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=ej(e),i=r===e.ownerDocument?.body,a=PA(r);if(i){let e=nj(a);return t.concat(a,a.visualViewport||[],BA(r)?r:[],e&&n?tj(e):[])}return t.concat(r,tj(r,[],n))}function nj(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function rj(e){let t=ZA(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=RA(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Qk(n)!==a||Qk(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function ij(e){return LA(e)?e:e.contextElement}function aj(e){let t=ij(e);if(!RA(t))return eA(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=rj(t),o=(a?Qk(n.width):n.width)/r,s=(a?Qk(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var oj=eA(0);function sj(e){let t=PA(e);return!YA()||!t.visualViewport?oj:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function cj(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===PA(e)}function lj(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=ij(e),o=eA(1);t&&(r?LA(r)&&(o=aj(r)):o=aj(e));let s=cj(a,n,r)?sj(a):eA(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=PA(a),t=LA(r)?PA(r):r,n=e,i=nj(n);for(;i&&t!==n;){let e=aj(i),t=i.getBoundingClientRect(),r=ZA(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=PA(i),i=nj(n)}}return SA({width:u,height:d,x:c,y:l})}function uj(e,t){let n=QA(e).scrollLeft;return t?t.left+n:lj(FA(e)).left+n}function dj(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-uj(e,n),y:n.top+t.scrollTop}}function fj(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=FA(r),s=t?HA(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=eA(1),u=eA(0),d=RA(r);if((d||!a)&&((NA(r)!==`body`||BA(o))&&(c=QA(r)),d)){let e=lj(r);l=aj(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?dj(o,c):eA(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function pj(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function mj(e){let t=QA(e),n=e.ownerDocument.body,r=Zk(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Zk(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+uj(e),o=-t.scrollTop;return ZA(n).direction===`rtl`&&(a+=Zk(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var hj=25;function gj(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=PA(e),a=FA(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!YA()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(uj(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=hj&&(s-=o)}return{width:s,height:c,x:l,y:u}}function _j(e,t){let n=lj(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=aj(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function vj(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=gj(e,n,t);else if(t===`document`)r=mj(FA(e));else if(LA(t))r=_j(t,n);else{let n=sj(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return SA(r)}function yj(e,t){let n=t.get(e);if(n)return n;let r=tj(e,[],!1).filter(e=>LA(e)&&NA(e)!==`body`),i=null,a=ZA(e).position===`fixed`,o=a?$A(e):e;for(;LA(o)&&!XA(o);){let e=ZA(o),t=qA(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=$A(o)}return t.set(e,r),r}function bj(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?HA(t)?[]:yj(t,this._c):[].concat(n),r],o=vj(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=PA(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function jj(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=ij(e),u=i||a?[...l?tj(l):[],...t?tj(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?Aj(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?lj(e):null;c&&g();function g(){let t=lj(e);h&&!kj(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var Mj=AA,Nj=jA,Pj=DA,Fj=(e,t,n)=>{let r=new Map,i=n??{},a={...Oj,...i.platform,_c:r};return EA(e,t,{...i,platform:a})};function Ij(e,t){return typeof e==`boolean`?e:t}var Lj=KT.extend({addOptions(){return{...this.parent(),lineNumbers:!1}},addAttributes(){return{...this.parent?.(),lineNumbers:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-line-numbers`);return t===`true`||t!==`false`&&null},renderHTML:e=>typeof e.lineNumbers==`boolean`?{"data-line-numbers":String(e.lineNumbers)}:{}}}},addCommands(){return{...this.parent?.(),toggleCodeLineNumbers:()=>({editor:e,commands:t})=>{if(!e.isActive(this.name))return!1;let n=Ij(e.getAttributes(this.name).lineNumbers,this.options.lineNumbers);return t.updateAttributes(this.name,{lineNumbers:!n})}}},addNodeView(){let e=this.options.lineNumbers,t=this.options.languageClassPrefix??`language-`;return({node:n})=>{let r=document.createElement(`pre`);r.className=`dw-code`;let i=document.createElement(`div`);i.className=`dw-code__gutter`,i.contentEditable=`false`,i.setAttribute(`aria-hidden`,`true`);let a=document.createElement(`code`);r.append(i,a);let o=-1,s=n=>{let s=Ij(n.attrs.lineNumbers,e);r.classList.toggle(`dw-code--numbered`,s),a.className=n.attrs.language?`${t}${String(n.attrs.language)}`:``;let c=s?n.textContent.split(` +`).trim();if(u){let e=n.blockTokens(u);l.push(...e)}let d=i+1,f=[];for(;dt;)f.push(e[d]),d+=1;if(f.length>0){let e=Tk(f,Math.min(...f.map(e=>e.indent)),n);l.push({type:`list`,ordered:!0,start:f[0].number,typeMarker:f[0].type,items:e,raw:f.map(e=>e.raw).join(` +`)})}r.push({type:`list_item`,raw:a.raw,tokens:l}),i=d}else i+=1}return r}function Ek(e,t){return e.map(e=>{if(e.type!==`list_item`)return t.parseChildren([e])[0];let n=[];return e.tokens&&e.tokens.length>0&&e.tokens.forEach(e=>{if(e.type===`paragraph`||e.type===`list`||e.type===`blockquote`||e.type===`code`)n.push(...t.parseChildren([e]));else if(e.type===`text`&&e.tokens){let r=t.parseChildren([e]);n.push({type:`paragraph`,content:r})}else{let r=t.parseChildren([e]);r.length>0&&n.push(...r)}}),{type:`listItem`,content:n}})}var Dk=64;function Ok(e,t){let n=[],r=0;for(;n.lengthe.hasAttribute(`start`)?parseInt(e.getAttribute(`start`)||``,10):1},type:{default:null,parseHTML:e=>{let t=e.getAttribute(`type`);if(t)return t;let n=e.getAttribute(`style`);if(n){let e=Nk(n);if(e)return e}let r=e.querySelector(`li`);if(r){let e=r.getAttribute(`style`);if(e){let t=Nk(e);if(t)return t}}return null}}}},parseHTML(){return[{tag:`ol`}]},renderHTML({HTMLAttributes:e}){let{start:t,type:n,...r}=e,i=j(this.options.HTMLAttributes,r);return t!==1&&(i.start=t),n&&n!==`1`&&(i.type=n),[`ol`,i,0]},markdownTokenName:`list`,parseMarkdown:(e,t)=>{if(e.type!==`list`||!e.ordered)return[];let n=e.start||1,r=e.typeMarker,i=e.items?Ek(e.items,t):[],a={};return n!==1&&(a.start=n),r&&(a.type=r),Object.keys(a).length>0?{type:`orderedList`,attrs:a,content:i}:{type:`orderedList`,content:i}},renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownTokenizer:{name:`orderedList`,level:`block`,start:()=>-1,tokenize:(e,t,n)=>{let[r,i,a]=kk(e);if(r.length===0)return;let o=Tk(r,r[0].indent,n);if(o.length!==0)return{type:`list`,ordered:!0,start:r[0]?.number||1,typeMarker:r[0]?.type,items:o,raw:a.slice(0,i).join(` +`)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:e,chain:t})=>this.options.keepAttributes?t().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(Ak,this.editor.getAttributes(jk)).run():e.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addProseMirrorPlugins(){return[new D({props:{handlePaste:(e,t)=>{if((t.clipboardData?.getData(`text/html`))?.trim())return!1;let n=t.clipboardData?.getData(`text/plain`);if(!n)return!1;let r=wk(n);if(!r)return!1;try{let t=e.state.schema.nodeFromJSON(r),n=e.state.tr.replaceSelectionWith(t);return e.dispatch(n),!0}catch{return!1}}}})]},addInputRules(){let e=(e,t)=>(!t.attrs.type||t.attrs.type===`1`)&&t.childCount+t.attrs.start===+e[1],t=Wp({find:Mk,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:e});return(this.options.keepMarks||this.options.keepAttributes)&&(t=Wp({find:Mk,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(jk)}),joinPredicate:e,editor:this.editor})),[t]}}),Fk=/^\s*(\[([( |x])?\])\s$/,Ik=`position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0`,Lk=(e,t,n)=>{var r;return(n==null||(r=n.checkboxLabel)==null?void 0:r.call(n,e,t))||`Task item checkbox for ${e.textContent||`empty task item`}`},Rk=qp.create({name:`taskItem`,addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:`taskList`,a11y:void 0}},content(){return this.options.nested?`paragraph block*`:`paragraph+`},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-checked`);return t===``||t===`true`},renderHTML:e=>({"data-checked":e.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51,contentElement:e=>e.querySelector(`div`)??e}]},renderHTML({node:e,HTMLAttributes:t}){return[`li`,j(this.options.HTMLAttributes,t,{"data-type":this.name}),[`label`,[`input`,{type:`checkbox`,checked:e.attrs.checked?`checked`:null}],[`span`]],[`div`,0]]},parseMarkdown:(e,t)=>{let n=[];if(e.tokens&&e.tokens.length>0?n.push(t.createNode(`paragraph`,{},t.parseInline(e.tokens))):e.text?n.push(t.createNode(`paragraph`,{},[t.createNode(`text`,{text:e.text})])):n.push(t.createNode(`paragraph`,{},[])),e.nestedTokens&&e.nestedTokens.length>0){let r=t.parseChildren(e.nestedTokens);n.push(...r)}return t.createNode(`taskItem`,{checked:e.checked||!1},n)},renderMarkdown:(e,t)=>ap(e,t,`- [${e.attrs?.checked?`x`:` `}] `,void 0,{indentMainContent:!0}),addExtensions(){return this.options.nested?[FO(this.name,[this.options.taskListTypeName])]:[]},addKeyboardShortcuts(){let e={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...e,Tab:()=>this.editor.commands.sinkListItem(this.name)}:e},addNodeView(){return({node:e,HTMLAttributes:t,getPos:n,editor:r})=>{let i=document.createElement(`li`),a=document.createElement(`label`),o=document.createElement(`span`),s=document.createElement(`input`),c=document.createElement(`div`);o.style.cssText=Ik;let l=e=>{let t=Lk(e,e.attrs.checked,this.options.a11y);s.setAttribute(`aria-label`,t),o.textContent=t};l(e),a.contentEditable=`false`,s.type=`checkbox`,s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`change`,t=>{if(!r.isEditable&&!this.options.onReadOnlyChecked){s.checked=!s.checked;return}let{checked:i}=t.target;r.isEditable&&typeof n==`function`&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=n();if(typeof t!=`number`)return!1;let r=e.doc.nodeAt(t);return e.setNodeMarkup(t,void 0,{...r?.attrs,checked:i}),!0}).run(),!r.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(e,i)||(s.checked=!s.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([e,t])=>{i.setAttribute(e,t)}),i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,a.append(s,o),i.append(a,c),Object.entries(t).forEach(([e,t])=>{i.setAttribute(e,t)});let u=new Set(Object.keys(t));return{dom:i,contentDOM:c,update:e=>{if(e.type!==this.type)return!1;i.dataset.checked=e.attrs.checked,s.checked=e.attrs.checked,l(e);let t=r.extensionManager.attributes,n=Iu(e,t),a=new Set(Object.keys(n)),o=this.options.HTMLAttributes;return u.forEach(e=>{a.has(e)||(e in o?i.setAttribute(e,o[e]):i.removeAttribute(e))}),Object.entries(n).forEach(([e,t])=>{t==null?e in o?i.setAttribute(e,o[e]):i.removeAttribute(e):i.setAttribute(e,t)}),u=a,!0}}}},addInputRules(){return[Wp({find:Fk,type:this.type,getAttributes:e=>({checked:e[e.length-1]===`x`})})]}}),zk=qp.create({name:`taskList`,addOptions(){return{itemTypeName:`taskItem`,HTMLAttributes:{}}},group:`block list`,content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:e}){return[`ul`,j(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},parseMarkdown:(e,t)=>t.createNode(`taskList`,{},t.parseChildren(e.items||[])),renderMarkdown:(e,t)=>e.content?t.renderChildren(e.content,` +`):``,markdownTokenizer:{name:`taskList`,level:`block`,start(e){let t=e.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)?.index;return t===void 0?-1:t},tokenize(e,t,n){let r=e=>{let t=np(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(t){let r={type:`taskList`,raw:t.raw,items:t.items},i=e.slice(t.raw.length);return i.trim()?[r,...n.blockTokens(i)]:[r]}return n.blockTokens(e)},i=np(e,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:e=>({indentLevel:e[1].length,mainContent:e[4],checked:e[3].toLowerCase()===`x`}),createToken:(e,t)=>({type:`taskItem`,raw:``,mainContent:e.mainContent,indentLevel:e.indentLevel,checked:e.checked,text:e.mainContent,tokens:n.inlineTokens(e.mainContent),nestedTokens:t}),customNestedParser:r},n);if(i)return{type:`taskList`,raw:i.raw,items:i.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:e})=>e.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});wp.create({name:`listKit`,addExtensions(){let e=[];return this.options.bulletList!==!1&&e.push(jO.configure(this.options.bulletList)),this.options.listItem!==!1&&e.push(ak.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(mk.configure(this.options.listKeymap)),this.options.orderedList!==!1&&e.push(Pk.configure(this.options.orderedList)),this.options.taskItem!==!1&&e.push(Rk.configure(this.options.taskItem)),this.options.taskList!==!1&&e.push(zk.configure(this.options.taskList)),e}});var Bk=` `,Vk=`\xA0`,Hk=qp.create({name:`paragraph`,priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:`block`,content:`inline*`,parseHTML(){return[{tag:`p`}]},renderHTML({HTMLAttributes:e}){return[`p`,j(this.options.HTMLAttributes,e),0]},parseMarkdown:(e,t)=>{let n=e.tokens||[];if(n.length===1&&n[0].type===`image`)return t.parseChildren([n[0]]);let r=t.parseInline(n);return n.length===1&&n[0].type===`text`&&(n[0].raw===Bk||n[0].text===Bk||n[0].raw===Vk||n[0].text===Vk)&&r.length===1&&r[0].type===`text`&&(r[0].text===Bk||r[0].text===Vk)?t.createNode(`paragraph`,void 0,[]):t.createNode(`paragraph`,void 0,r)},renderMarkdown:(e,t,n)=>{if(!e)return``;let r=Array.isArray(e.content)?e.content:[];if(r.length===0){var i,a;let e=Array.isArray(n==null||(i=n.previousNode)==null?void 0:i.content)?n.previousNode.content:[];return(n==null||(a=n.previousNode)==null?void 0:a.type)===`paragraph`&&e.length===0?Bk:``}return t.renderChildren(r)},addCommands(){return{setParagraph:()=>({commands:e})=>e.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Uk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,Wk=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,Gk=gp.create({name:`strike`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`s`},{tag:`del`},{tag:`strike`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`line-through`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`s`,j(this.options.HTMLAttributes,e),0]},markdownTokenName:`del`,parseMarkdown:(e,t)=>t.applyMark(`strike`,t.parseInline(e.tokens||[])),renderMarkdown:(e,t)=>`~~${t.renderChildren(e)}~~`,addCommands(){return{setStrike:()=>({commands:e})=>e.setMark(this.name),toggleStrike:()=>({commands:e})=>e.toggleMark(this.name),unsetStrike:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[Vp({find:Uk,type:this.type})]},addPasteRules(){return[Jp({find:Wk,type:this.type})]}}),Kk=qp.create({name:`text`,group:`inline`,parseMarkdown:e=>({type:`text`,text:e.text||``}),renderMarkdown:e=>e.text||``}),qk=gp.create({name:`underline`,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`u`},{style:`text-decoration`,consuming:!1,getAttrs:e=>e.includes(`underline`)?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`u`,j(this.options.HTMLAttributes,e),0]},parseMarkdown(e,t){return t.applyMark(this.name||`underline`,t.parseInline(e.tokens||[]))},renderMarkdown(e,t){return`${t.renderChildren(e)}`},markdownTokenizer:{name:`underline`,level:`inline`,start(e){return e.toLowerCase().indexOf(``)},tokenize(e,t,n){if(!/^/i.test(e))return;let r=/\\[\s\S]|`+|<\/u>/gi;r.lastIndex=3;let i=r.exec(e);for(;i;){if(i[0].startsWith("`")){let t=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/.exec(e.slice(i.index));t&&(r.lastIndex=i.index+t[0].length)}else if(!i[0].startsWith(`\\`)){let t=e.slice(3,i.index);return t?{type:`underline`,raw:e.slice(0,r.lastIndex),text:t,tokens:n.inlineTokens(t)}:void 0}i=r.exec(e)}}},addCommands(){return{setUnderline:()=>({commands:e})=>e.setMark(this.name),toggleUnderline:()=>({commands:e})=>e.toggleMark(this.name),unsetUnderline:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),Jk=wp.create({name:`starterKit`,addExtensions(){let e=[];return this.options.bold!==!1&&e.push(IT.configure(this.options.bold)),this.options.blockquote!==!1&&e.push(jT.configure(this.options.blockquote)),this.options.bulletList!==!1&&e.push(jO.configure(this.options.bulletList)),this.options.code!==!1&&e.push(BT.configure(this.options.code)),this.options.codeBlock!==!1&&e.push(WT.configure(this.options.codeBlock)),this.options.document!==!1&&e.push(KT.configure(this.options.document)),this.options.dropcursor!==!1&&e.push(Yw.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&e.push(Xw.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&e.push(qT.configure(this.options.hardBreak)),this.options.heading!==!1&&e.push(JT.configure(this.options.heading)),this.options.undoRedo!==!1&&e.push(xT.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&e.push(YT.configure(this.options.horizontalRule)),this.options.italic!==!1&&e.push(eE.configure(this.options.italic)),this.options.listItem!==!1&&e.push(ak.configure(this.options.listItem)),this.options.listKeymap!==!1&&e.push(mk.configure(this.options?.listKeymap)),this.options.link!==!1&&e.push(DO.configure(this.options?.link)),this.options.orderedList!==!1&&e.push(Pk.configure(this.options.orderedList)),this.options.paragraph!==!1&&e.push(Hk.configure(this.options.paragraph)),this.options.strike!==!1&&e.push(Gk.configure(this.options.strike)),this.options.text!==!1&&e.push(Kk.configure(this.options.text)),this.options.underline!==!1&&e.push(qk.configure(this.options?.underline)),this.options.trailingNode!==!1&&e.push(bT.configure(this.options?.trailingNode)),e}}),Yk=Math.min,Xk=Math.max,Zk=Math.round,Qk=Math.floor,$k=e=>({x:e,y:e}),eA={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function tA(e,t,n){return Xk(e,Yk(t,n))}function nA(e,t){return typeof e==`function`?e(t):e}function rA(e){return e.split(`-`)[0]}function iA(e){return e.split(`-`)[1]}function aA(e){return e===`x`?`y`:`x`}function oA(e){return e===`y`?`height`:`width`}function sA(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function cA(e){return aA(sA(e))}function lA(e,t,n){n===void 0&&(n=!1);let r=iA(e),i=cA(e),a=oA(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=vA(o)),[o,vA(o)]}function uA(e){let t=vA(e);return[dA(e),t,dA(t)]}function dA(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var fA=[`left`,`right`],pA=[`right`,`left`],mA=[`top`,`bottom`],hA=[`bottom`,`top`];function gA(e,t,n){switch(e){case`top`:case`bottom`:return n?t?pA:fA:t?fA:pA;case`left`:case`right`:return t?mA:hA;default:return[]}}function _A(e,t,n,r){let i=iA(e),a=gA(rA(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(dA)))),a}function vA(e){let t=rA(e);return eA[t]+e.slice(t.length)}function yA(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function bA(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:yA(e)}function xA(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function SA(e,t,n){let{reference:r,floating:i}=e,a=sA(t),o=cA(t),s=oA(o),c=rA(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=iA(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function CA(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=nA(t,e),p=bA(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=xA(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=xA(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var wA=50,TA=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:CA},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=SA(l,r,c),f=r,p=0,m={};for(let n=0;ne<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===sA(t)||te.every(e=>sA(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:te},reset:{placement:t}};let n=te.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=te.filter(e=>{if(x){let t=sA(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}},DA=new Set([`left`,`top`]);async function OA(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=rA(n),s=iA(n),c=sA(n)===`y`,l=DA.has(o)?-1:1,u=a&&c?-1:1,d=nA(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var kA=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await OA(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},AA=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=nA(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=sA(i),p=aA(f),m=u[p],h=u[f],g=(e,t)=>tA(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}};function jA(){return typeof window<`u`}function MA(e){return FA(e)?(e.nodeName||``).toLowerCase():`#document`}function NA(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function PA(e){return((FA(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function FA(e){return jA()?e instanceof Node||e instanceof NA(e).Node:!1}function IA(e){return jA()?e instanceof Element||e instanceof NA(e).Element:!1}function LA(e){return jA()?e instanceof HTMLElement||e instanceof NA(e).HTMLElement:!1}function RA(e){return!jA()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof NA(e).ShadowRoot}function zA(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=XA(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function BA(e){return/^(table|td|th)$/.test(MA(e))}function VA(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var HA=/transform|translate|scale|rotate|perspective|filter/,UA=/paint|layout|strict|content/,WA=e=>!!e&&e!==`none`,GA;function KA(e){let t=IA(e)?XA(e):e;return WA(t.transform)||WA(t.translate)||WA(t.scale)||WA(t.rotate)||WA(t.perspective)||!JA()&&(WA(t.backdropFilter)||WA(t.filter))||HA.test(t.willChange||``)||UA.test(t.contain||``)}function qA(e){let t=QA(e);for(;LA(t)&&!YA(t);){if(KA(t))return t;if(VA(t))return null;t=QA(t)}return null}function JA(){return GA??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),GA}function YA(e){return/^(html|body|#document)$/.test(MA(e))}function XA(e){return NA(e).getComputedStyle(e)}function ZA(e){return IA(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function QA(e){if(MA(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||RA(e)&&e.host||PA(e);return RA(t)?t.host:t}function $A(e){let t=QA(e);return YA(t)?(e.ownerDocument||e).body:LA(t)&&zA(t)?t:$A(t)}function ej(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=$A(e),i=r===e.ownerDocument?.body,a=NA(r);if(i){let e=tj(a);return t.concat(a,a.visualViewport||[],zA(r)?r:[],e&&n?ej(e):[])}return t.concat(r,ej(r,[],n))}function tj(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function nj(e){let t=XA(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=LA(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=Zk(n)!==a||Zk(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function rj(e){return IA(e)?e:e.contextElement}function ij(e){let t=rj(e);if(!LA(t))return $k(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=nj(t),o=(a?Zk(n.width):n.width)/r,s=(a?Zk(n.height):n.height)/i;return o&&Number.isFinite(o)||(o=1),s&&Number.isFinite(s)||(s=1),{x:o,y:s}}var aj=$k(0);function oj(e){let t=NA(e);return!JA()||!t.visualViewport?aj:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function sj(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===NA(e)}function cj(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=rj(e),o=$k(1);t&&(r?IA(r)&&(o=ij(r)):o=ij(e));let s=sj(a,n,r)?oj(a):$k(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=NA(a),t=IA(r)?NA(r):r,n=e,i=tj(n);for(;i&&t!==n;){let e=ij(i),t=i.getBoundingClientRect(),r=XA(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=NA(i),i=tj(n)}}return xA({width:u,height:d,x:c,y:l})}function lj(e,t){let n=ZA(e).scrollLeft;return t?t.left+n:cj(PA(e)).left+n}function uj(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-lj(e,n),y:n.top+t.scrollTop}}function dj(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=PA(r),s=t?VA(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=$k(1),u=$k(0),d=LA(r);if((d||!a)&&((MA(r)!==`body`||zA(o))&&(c=ZA(r)),d)){let e=cj(r);l=ij(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?uj(o,c):$k(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function fj(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function pj(e){let t=ZA(e),n=e.ownerDocument.body,r=Xk(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Xk(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+lj(e),o=-t.scrollTop;return XA(n).direction===`rtl`&&(a+=Xk(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var mj=25;function hj(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=NA(e),a=PA(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!JA()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if(lj(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=mj&&(s-=o)}return{width:s,height:c,x:l,y:u}}function gj(e,t){let n=cj(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=ij(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function _j(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=hj(e,n,t);else if(t===`document`)r=pj(PA(e));else if(IA(t))r=gj(t,n);else{let n=oj(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return xA(r)}function vj(e,t){let n=t.get(e);if(n)return n;let r=ej(e,[],!1).filter(e=>IA(e)&&MA(e)!==`body`),i=null,a=XA(e).position===`fixed`,o=a?QA(e):e;for(;IA(o)&&!YA(o);){let e=XA(o),t=KA(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=QA(o)}return t.set(e,r),r}function yj(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?VA(t)?[]:vj(t,this._c):[].concat(n),r],o=_j(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=NA(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function Aj(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=rj(e),u=i||a?[...l?ej(l):[],...t?ej(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?kj(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?cj(e):null;c&&g();function g(){let t=cj(e);h&&!Oj(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var jj=kA,Mj=AA,Nj=EA,Pj=(e,t,n)=>{let r=new Map,i=n??{},a={...Dj,...i.platform,_c:r};return TA(e,t,{...i,platform:a})};function Fj(e,t){return typeof e==`boolean`?e:t}var Ij=GT.extend({addOptions(){return{...this.parent(),lineNumbers:!1}},addAttributes(){return{...this.parent?.(),lineNumbers:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-line-numbers`);return t===`true`||t!==`false`&&null},renderHTML:e=>typeof e.lineNumbers==`boolean`?{"data-line-numbers":String(e.lineNumbers)}:{}}}},addCommands(){return{...this.parent?.(),toggleCodeLineNumbers:()=>({editor:e,commands:t})=>{if(!e.isActive(this.name))return!1;let n=Fj(e.getAttributes(this.name).lineNumbers,this.options.lineNumbers);return t.updateAttributes(this.name,{lineNumbers:!n})}}},addNodeView(){let e=this.options.lineNumbers,t=this.options.languageClassPrefix??`language-`;return({node:n})=>{let r=document.createElement(`pre`);r.className=`dw-code`;let i=document.createElement(`div`);i.className=`dw-code__gutter`,i.contentEditable=`false`,i.setAttribute(`aria-hidden`,`true`);let a=document.createElement(`code`);r.append(i,a);let o=-1,s=n=>{let s=Fj(n.attrs.lineNumbers,e);r.classList.toggle(`dw-code--numbered`,s),a.className=n.attrs.language?`${t}${String(n.attrs.language)}`:``;let c=s?n.textContent.split(` `).length:0;c!==o&&(o=c,i.textContent=Array.from({length:c},(e,t)=>t+1).join(` -`))};return s(n),{dom:r,contentDOM:a,update:e=>e.type===n.type&&(s(e),!0),ignoreMutation:e=>i.contains(e.target)}}}}),Rj=(e,t)=>e===`application/pdf`||typeof t==`string`&&/\.pdf$/i.test(t);function zj(e,t,n,r){let i=!1,a=null,o=null,s=document.createElement(`div`);return s.className=`dw-pdf__status`,s.textContent=r.blocks.pdfLoading,e.replaceChildren(s),(async()=>{try{let c=await n();if(i)return;o=c.getDocument({url:t});let l=await o.promise;if(i)return;s.remove();let u=Math.max(e.clientWidth-2,200),d=window.devicePixelRatio||1;a=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=t.target;a?.unobserve(e),p(e,Number(e.dataset.page))}},{root:e,rootMargin:`400px 0px`});let f=(await l.getPage(1)).getViewport({scale:1});for(let t=1;t<=l.numPages;t++){let n=document.createElement(`div`);n.className=`dw-pdf__page`,n.dataset.page=String(t),n.style.aspectRatio=`${f.width} / ${f.height}`,n.setAttribute(`aria-label`,r.blocks.pdfPage.replace(`{n}`,String(t))),e.append(n),a.observe(n)}async function p(e,t){let n=await l.getPage(t);if(i)return;let r=u/n.getViewport({scale:1}).width,a=n.getViewport({scale:r*d}),o=document.createElement(`canvas`);o.width=Math.floor(a.width),o.height=Math.floor(a.height),e.style.aspectRatio=`${a.width} / ${a.height}`,e.append(o),await n.render({canvas:o,viewport:a}).promise}}catch{i||(s.textContent=r.blocks.loadFailed)}})(),()=>{i=!0,a?.disconnect(),o?.destroy()}}var Bj={page:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M9 12h6`,`M9 16h6`],"chevron-right":[`M10 6l6 6-6 6`],"chevron-left":[`M14 6l-6 6 6 6`],"chevron-down":[`M6 10l6 6 6-6`],"chevron-up":[`M6 14l6-6 6 6`],plus:[`M12 5v14`,`M5 12h14`],search:[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`],more:[`M6 12h.01`,`M12 12h.01`,`M18 12h.01`],drop:[`M12 4h7v7a7 7 0 1 1-7-7z`],info:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 11v5`,`M12 8h.01`],check:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8 12.5l2.5 2.5L16 9.5`],alert:[`M12 4l9 16H3z`,`M12 10v4`,`M12 17h.01`],error:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M9 9l6 6`,`M15 9l-6 6`],text:[`M5 6h14`,`M12 6v13`],heading:[`M6 5v14`,`M18 5v14`,`M6 12h12`],list:[`M9 6h11`,`M9 12h11`,`M9 18h11`,`M4.5 6h.01`,`M4.5 12h.01`,`M4.5 18h.01`],todo:[`M4 4h7v7H4z`,`M5.5 7.5l1.5 1.5 2.5-2.5`,`M14 7h6`,`M4 14h7v7H4z`,`M14 17h6`],code:[`M9 7l-5 5 5 5`,`M15 7l5 5-5 5`],quote:[`M6 6v12`,`M10 8h9`,`M10 12h9`,`M10 16h6`],image:[`M4 5h16v14H4z`,`M4 16l5-5 4 4 2-2 5 5`,`M15.5 8.5h.01`],table:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 5v14`],lock:[`M6 11h12v9H6z`,`M8.5 11V8a3.5 3.5 0 0 1 7 0v3`],trash:[`M4 7h16`,`M10 4h4`,`M6 7l1 13h10l1-13`,`M10 11v6`,`M14 11v6`],settings:[`M4 7h9`,`M17 7h3`,`M15 5v4`,`M4 17h3`,`M11 17h9`,`M9 15v4`],menu:[`M4 7h16`,`M4 12h16`,`M4 17h16`],close:[`M6 6l12 12`,`M18 6L6 18`],open:[`M8 16L16 8`,`M9 8h7v7`],restore:[`M4.5 13a7.5 7.5 0 1 0 2.2-6.3`,`M5 4v4h4`],"sign-out":[`M14 4h5v16h-5`,`M10 8l-4 4 4 4`,`M6 12h9`],sidebar:[`M4 5h16v14H4z`,`M9.5 5v14`],home:[`M4 11l8-7 8 7`,`M6 9.5V20h12V9.5`,`M10 20v-5h4v5`],sun:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M12 3v1.5`,`M12 19.5V21`,`M3 12h1.5`,`M19.5 12H21`,`M5.6 5.6l1.1 1.1`,`M17.3 17.3l1.1 1.1`,`M5.6 18.4l1.1-1.1`,`M17.3 6.7l1.1-1.1`],moon:[`M19.5 14.5A8 8 0 0 1 9.5 4.5a8 8 0 1 0 10 10z`],monitor:[`M4 5h16v11H4z`,`M9 20h6`,`M12 16v4`],selector:[`M8 9l4-4 4 4`,`M8 15l4 4 4-4`],star:[`M12 4l2.5 5.2 5.5.8-4 3.9.9 5.6L12 16.9l-4.9 2.6.9-5.6-4-3.9 5.5-.8z`],clock:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 7v5l3 2`],calendar:[`M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z`,`M4 10h16`,`M8 3v4`,`M16 3v4`],share:[`M12 4v11`,`M8 8l4-4 4 4`,`M6 13v7h12v-7`],link:[`M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1`,`M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1`],upload:[`M12 16V4`,`M7 9l5-5 5 5`,`M4 20h16`],download:[`M12 4v12`,`M7 11l5 5 5-5`,`M4 20h16`],file:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`],paperclip:[`M18 11.5l-6.4 6.4a4.2 4.2 0 0 1-6-6l7-7a2.8 2.8 0 0 1 4 4l-7 7a1.4 1.4 0 0 1-2-2l6.4-6.4`],comment:[`M5 5h14v10H9l-4 4z`],at:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M16 12v1.5a2.5 2.5 0 0 0 5 0V12a9 9 0 1 0-3.5 7.1`],bold:[`M7 5h6a3.5 3.5 0 0 1 0 7H7z`,`M7 12h7a3.5 3.5 0 0 1 0 7H7z`],italic:[`M10 5h8`,`M6 19h8`,`M14 5l-4 14`],strike:[`M5 12h14`,`M16 7.5A3.5 3 0 0 0 12.5 5h-1A3.5 3 0 0 0 8 8c0 4 8 3 8 7.5a3.5 3.5 0 0 1-3.5 3.5h-1A3.5 3 0 0 1 8 16.5`],underline:[`M7 4v7a5 5 0 0 0 10 0V4`,`M5 20h14`],"list-ordered":[`M10 6h10`,`M10 12h10`,`M10 18h10`,`M4 5l1.5-1v5`,`M4 15.5a1.5 1.5 0 0 1 3 .5L4 19h3`],divider:[`M4 12h16`],globe:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M3 12h18`,`M12 3c2.5 2.5 3.5 5.5 3.5 9s-1 6.5-3.5 9`,`M12 3C9.5 5.5 8.5 8.5 8.5 12s1 6.5 3.5 9`],bell:[`M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z`,`M10 20a2 2 0 0 0 4 0`],"bell-off":[`M6 16V11a6 6 0 0 1 9.5-4.9`,`M18 11v5l1.5 2H8`,`M10 20a2 2 0 0 0 4 0`,`M4 4l16 16`],smile:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8.5 14a4 4 0 0 0 7 0`,`M9 9.5h.01`,`M15 9.5h.01`],reply:[`M9 7L4 12l5 5`,`M4 12h10a6 6 0 0 1 6 6v1`],pencil:[`M15 5l4 4L8 20H4v-4z`],sigma:[`M18 6V4H6l6 8l-6 8h12v-2`],diagram:[`M4 4h6v5H4z`,`M14 15h6v5h-6z`,`M7 9v4a2 2 0 0 0 2 2h5`],video:[`M4 6h11v12H4z`,`M15 10l5-3v10l-5-3`],archive:[`M4 5h16v4H4z`,`M5 9v10h14V9`,`M10 13h4`],pin:[`M9 4h6`,`M10 4v6l-3 4h10l-3-4V4`,`M12 14v6`],width:[`M3 12h18`,`M7 8l-4 4 4 4`,`M17 8l4 4-4 4`],type:[`M5 7V5h14v2`,`M12 5v14`,`M9 19h6`],server:[`M4 4h16v6H4z`,`M4 14h16v6H4z`,`M8 7h.01`,`M8 17h.01`],users:[`M9 11a3.5 3.5 0 1 0 0-7a3.5 3.5 0 1 0 0 7z`,`M3 20a6 6 0 0 1 12 0`,`M16 4.5a3.5 3.5 0 0 1 0 6.5`,`M18 14a6 6 0 0 1 3 6`],"align-left":[`M4 6h16`,`M4 10h10`,`M4 14h16`,`M4 18h10`],"align-center":[`M4 6h16`,`M7 10h10`,`M4 14h16`,`M7 18h10`],"align-right":[`M4 6h16`,`M10 10h10`,`M4 14h16`,`M10 18h10`],grip:[`M9 6h.01`,`M15 6h.01`,`M9 12h.01`,`M15 12h.01`,`M9 18h.01`,`M15 18h.01`],copy:[`M9 9h11v11H9z`,`M5 15H4V4h11v1`],"arrow-up":[`M12 19V5`,`M6 11l6-6 6 6`],"arrow-down":[`M12 5v14`,`M6 13l6 6 6-6`],callout:[`M4 5h16v14H4z`,`M8 10h.01`,`M11 10h5`,`M8 14h8`],columns:[`M4 5h6v14H4z`,`M14 5h6v14h-6z`],palette:[`M12 3a9 9 0 1 0 0 18c1 0 1.5-.7 1.5-1.5 0-1.2-1-1.5-1-2.5s.8-1.5 2-1.5H17a4 4 0 0 0 4-4c0-4.7-4-8.5-9-8.5z`,`M7.5 11h.01`,`M10 7.5h.01`,`M14.5 7.5h.01`],"page-plus":[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M12 11v6`,`M9 14h6`],tag:[`M4 4h7l9 9-7 7-9-9z`,`M8 8h.01`],grid:[`M4 4h7v7H4z`,`M13 4h7v7h-7z`,`M4 13h7v7H4z`,`M13 13h7v7h-7z`],cards:[`M4 5h16v6H4z`,`M4 15h16v4H4z`],filter:[`M4 5h16l-6 8v6l-4-2v-4z`],layers:[`M12 4l8 4-8 4-8-4z`,`M4 12l8 4 8-4`,`M4 16l8 4 8-4`],journal:[`M6 3h11a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6z`,`M9 3v18`,`M12 8h3`,`M12 12h3`],sliders:[`M5 6h14`,`M5 12h14`,`M5 18h14`,`M9 4v4`,`M15 10v4`,`M11 16v4`],sort:[`M7 4v16`,`M4 7l3-3 3 3`,`M17 20V4`,`M14 17l3 3 3-3`],database:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 10v9`],relation:[`M3 6h7v5H3z`,`M14 13h7v5h-7z`,`M10 8.5h2.5a2 2 0 0 1 2 2V13`],rollup:[`M4 5h16`,`M4 9h16`,`M4 13h16`,`M12 16v5`,`M9 18l3 3 3-3`],edgeless:[`M4 5h16v14H4z`,`M7 15l3-4 3 3 4-5`,`M7 8.5h.01`],cursor:[`M6 4l12 7-5.5 1.5L10 18z`],hand:[`M8 13V6.5a1.5 1.5 0 0 1 3 0V12`,`M11 11V5a1.5 1.5 0 0 1 3 0v6`,`M14 11V6.5a1.5 1.5 0 0 1 3 0V14a6 6 0 0 1-6 6h-1a5 5 0 0 1-4.2-2.3L4.5 14a1.5 1.5 0 0 1 2.5-1.6L8 14`],note:[`M5 4h14v10l-6 6H5z`,`M13 20v-6h6`],shapes:[`M4 13h7v7H4z`,`M16.5 4a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7z`,`M7.5 4l3.5 6H4z`],connector:[`M5 19a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M19 9a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M6.5 15.5C9 10 13 13 17.5 8.5`],pen:[`M4 20l1-4L16 5l3 3L8 19z`,`M14 7l3 3`],eraser:[`M8 20h12`,`M4.5 15.5l9-9 6 6-7.5 7.5H9z`,`M9 11l5 5`],frame:[`M7 3v18`,`M17 3v18`,`M3 7h18`,`M3 17h18`],mindmap:[`M10 10h4v4h-4z`,`M3 4h4v3H3z`,`M17 4h4v3h-4z`,`M3 17h4v3H3z`,`M17 17h4v3h-4z`,`M7 6l3 4`,`M17 6l-3 4`,`M7 18l3-4`,`M17 18l-3-4`],sticker:[`M12 3a9 9 0 1 0 9 9h-5a4 4 0 0 1-4-4z`,`M12 3a9 9 0 0 1 9 9`,`M9 14.5c1.5 1.5 4.5 1.5 6 0`],present:[`M3 4h18`,`M5 4v11h14V4`,`M12 15v3`,`M8 21l4-3 4 3`],"zoom-in":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`,`M11 8v6`],"zoom-out":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`],fit:[`M4 9V4h5`,`M15 4h5v5`,`M20 15v5h-5`,`M9 20H4v-5`],"send-back":[`M4 12h9v8H4z`,`M11 4h9v8h-9z`],group:[`M4 4h3`,`M10 4h4`,`M17 4h3v3`,`M20 10v4`,`M20 17v3h-3`,`M14 20h-4`,`M7 20H4v-3`,`M4 14v-4`,`M8 8h8v8H8z`],sparkles:[`M10 4l1.6 4.4L16 10l-4.4 1.6L10 16l-1.6-4.4L4 10l4.4-1.6z`,`M17 14l.8 2.2L20 17l-2.2.8L17 20l-.8-2.2L14 17l2.2-.8z`,`M17 3v4`,`M15 5h4`],send:[`M4 12l16-8-6 16-2-6z`,`M12 14l8-10`],eye:[`M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z`,`M12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6z`],"user-plus":[`M15 20v-1a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v1`,`M8.5 4a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7z`,`M19 8v6`,`M16 11h6`]},Vj=`http://www.w3.org/2000/svg`;function Hj(e,t=18){let n=document.createElementNS(Vj,`svg`);for(let[e,r]of Object.entries({width:String(t),height:String(t),viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`1.75`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`}))n.setAttribute(e,r);for(let t of Bj[e]){let e=document.createElementNS(Vj,`path`);e.setAttribute(`d`,t),n.append(e)}return n}function Uj(e){return()=>{let t=null,n=null,r=null,i=0,a=null,o=()=>a?.items??r?.items??[],s=t=>{let n=o()[t];if(!r||n===void 0)return;let s=e.children?.(n);s?.length?(a={parent:n,items:s},i=0,c()):e.pick(r,n)},c=()=>{if(!t||!r)return;let n=r;if(t.replaceChildren(),e.showQuery){let e=document.createElement(`div`);e.className=`dw-suggest__query`,e.textContent=`/${n.query}`,t.append(e)}if(a){let n=document.createElement(`div`);n.className=`dw-suggest__query`,n.textContent=`‹ ${e.toItem(a.parent).label}`,t.append(n)}let c=o();if(c.length)c.forEach((n,r)=>{let a=e.toItem(n),o=document.createElement(`div`);o.className=r===i?`dw-suggest__item is-active`:`dw-suggest__item`,o.setAttribute(`role`,`option`),o.setAttribute(`aria-selected`,String(r===i)),o.addEventListener(`mousedown`,e=>{e.preventDefault(),s(r)});let c=document.createElement(`span`);c.className=`dw-suggest__icon`,c.append(Hj(a.icon??`text`));let l=document.createElement(`span`);l.className=`dw-suggest__text`;let u=document.createElement(`span`);if(u.className=`dw-suggest__label`,u.textContent=a.label,l.append(u),a.description){let e=document.createElement(`span`);e.className=`dw-suggest__desc`,e.textContent=a.description,l.append(e)}if(o.append(c,l),e.children?.(n)?.length){o.setAttribute(`aria-haspopup`,`listbox`);let e=Hj(`chevron-right`,14);e.classList.add(`dw-suggest__more`),o.append(e)}t.append(o)}),t.querySelector(`.is-active`)?.scrollIntoView({block:`nearest`});else{let n=document.createElement(`div`);n.className=`dw-suggest__empty`,n.setAttribute(`role`,`status`),n.textContent=e.empty,t.append(n)}},l=()=>{let e=r?.clientRect?.();if(!t||!e)return;let i={getBoundingClientRect:()=>r?.clientRect?.()??e};n?.(),n=jj(i,t,()=>{t&&Fj(i,t,{placement:`bottom-start`,strategy:`fixed`,middleware:[Mj(6),Pj(),Nj({padding:8})]}).then(({x:e,y:n})=>{t&&Object.assign(t.style,{left:`${e}px`,top:`${n}px`})})})},u=()=>{n?.(),n=null,t?.remove(),t=null};return{onStart(n){r=n,i=0,a=null,t=document.createElement(`div`),t.className=`dw-suggest`,t.setAttribute(`role`,`listbox`),t.setAttribute(`aria-label`,e.label),document.body.append(t),c(),l()},onUpdate(e){e.items!==r?.items&&(i=0,a=null),r=e,c(),l()},onKeyDown({event:t}){let n=o().length;if(a&&(t.key===`Escape`||t.key===`ArrowLeft`))return a=null,i=0,c(),!0;let r=o()[i];return t.key===`ArrowRight`&&r!==void 0&&e.children?.(r)?.length?(s(i),!0):t.key===`Escape`?(u(),!0):n?t.key===`ArrowDown`||t.key===`ArrowUp`?(i=(i+(t.key===`ArrowDown`?1:-1)+n)%n,c(),!0):t.key===`Enter`||t.key===`Tab`?(s(i),!0):!1:!1},onExit(){r=null,u()}}}}function Wj(e){let t={...e};return t.attrs&&`blockId`in t.attrs&&(t.attrs={...t.attrs,blockId:null}),t.content&&=t.content.map(Wj),t}function Gj(e,t,n,r){let i=e.state.doc.nodeAt(t);if(!i)return[];let a=n.blockMenu,o=t+i.nodeSize,s=e.state.doc.resolve(t).index(0),c=[];if([`bulletList`,`orderedList`,`taskList`].includes(i.type.name)&&c.push({id:`groupAsDatabase`,label:n.database.groupAsDatabase,icon:`database`,run:()=>{e.chain().focus().setTextSelection(t+2).groupAsDatabase().run()}}),i.type.name===`codeBlock`){let n=!!e.extensionManager.extensions.find(e=>e.name===`codeBlock`)?.options.lineNumbers,r=Ij(i.attrs.lineNumbers,n);c.push({id:`lineNumbers`,label:r?a.hideLineNumbers:a.showLineNumbers,icon:`list-ordered`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`lineNumbers`,!r))})}if(i.type.name===`fileAttachment`&&Rj(i.attrs.mime,i.attrs.name)){let n=i.attrs.view===`preview`;c.push({id:`pdfView`,label:n?a.showAsFile:a.showPages,icon:n?`paperclip`:`file`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`view`,n?`card`:`preview`))})}return s>0&&c.push({id:`moveUp`,label:a.moveUp,icon:`arrow-up`,run:()=>{let n=e.state.doc.child(s-1),r=e.state.tr.delete(t,o).insert(t-n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),s{let n=e.state.doc.child(s+1),r=e.state.tr.delete(t,o).insert(t+n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),c.push({id:`duplicate`,label:a.duplicate,icon:`plus`,run:()=>{let t=e.schema.nodeFromJSON(Wj(i.toJSON()));e.view.dispatch(e.state.tr.insert(o,t).scrollIntoView())}},{id:`copy`,label:a.copy,icon:`copy`,run:()=>{e.chain().focus().setNodeSelection(t).run(),document.execCommand(`copy`)}}),r&&c.push({id:`copyLink`,label:n.blocks.copyBlockLink,icon:`link`,run:r}),c.push({id:`delete`,label:a.delete,icon:`trash`,danger:!0,run:()=>{e.view.dispatch(e.state.tr.delete(t,o)),e.commands.focus()}}),c}function Kj(e,t,n,r){let i=document.createElement(`div`);i.className=`dw-suggest dw-block-menu`,i.setAttribute(`role`,`menu`),i.setAttribute(`aria-label`,n);let a=t,o=0,s=[],c=()=>{i.replaceChildren(),a.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`dw-suggest__item${t===o?` is-active`:``}${e.danger?` is-danger`:``}`,n.setAttribute(`role`,`menuitem`),n.tabIndex=-1,e.children&&n.setAttribute(`aria-haspopup`,`menu`);let r=document.createElement(`span`);r.className=`dw-suggest__icon`,r.append(Hj(e.icon));let a=document.createElement(`span`);if(a.className=`dw-suggest__label`,a.textContent=e.label,n.append(r,a),e.children){let e=Hj(`chevron-right`,14);e.classList.add(`dw-block-menu__more`),n.append(e)}n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>l(t)),n.addEventListener(`mouseenter`,()=>{o=t;for(let[e,n]of[...i.children].entries())n.classList.toggle(`is-active`,e===t)}),i.append(n)}),i.children[o]?.focus()},l=e=>{let t=a[e];t&&(t.children?(s.push(a),a=t.children,o=0,c()):(m(),t.run?.()))},u=e=>{e.key===`Escape`||e.key===`ArrowLeft`&&s.length?(e.preventDefault(),e.stopPropagation(),s.length?(a=s.pop(),o=0,c()):m()):e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),o=(o+(e.key===`ArrowDown`?1:-1)+a.length)%a.length,c()):(e.key===`Enter`||e.key===` `||e.key===`ArrowRight`)&&(e.preventDefault(),(e.key!==`ArrowRight`||a[o]?.children)&&l(o))},d=t=>{!i.contains(t.target)&&!e.contains(t.target)&&m()};document.body.append(i);let f=jj(e,i,()=>{Fj(e,i,{placement:`bottom-start`,strategy:`fixed`,middleware:[Mj(4),Pj(),Nj({padding:8})]}).then(({x:e,y:t})=>Object.assign(i.style,{left:`${e}px`,top:`${t}px`}))});i.addEventListener(`keydown`,u),document.addEventListener(`mousedown`,d,!0);let p=!1;function m(){p||(p=!0,f(),i.remove(),document.removeEventListener(`mousedown`,d,!0),s=[],r?.())}return c(),m}var qj=[`paragraph`,`heading`,`blockquote`,`codeBlock`,`bulletList`,`orderedList`,`taskList`,`callout`,`table`,`details`,`image`,`embed`,`linkCard`,`mermaid`,`blockMath`,`drawio`,`excalidraw`,`fileAttachment`],Jj=/^[a-z0-9]{6,16}$/;function Yj(e){return/^#?b-([a-z0-9]{6,16})$/.exec(e)?.[1]??``}var Xj=e=>`#b-${e}`;function Zj(){return[...crypto.getRandomValues(new Uint8Array(8))].map(e=>(e%36).toString(36)).join(``)}function Qj(e,t){let n=e.state.doc.nodeAt(t);if(!n)return null;let r=n.attrs.blockId;if(r)return r;if(!e.editable||!qj.includes(n.type.name))return null;let i=Zj();return e.dispatch(e.state.tr.setNodeAttribute(t,`blockId`,i)),i}async function $j(e,t,n,r){let i=Qj(e,t);if(!i)return!1;let a=n(Xj(i));try{await navigator.clipboard.writeText(a),r?.(a)}catch{window.prompt(``,a)}return!0}function eM(e,t){let n=-1;return e.descendants((e,r)=>n>=0?!1:(e.attrs.blockId===t&&(n=r),!0)),n}function tM(e,t){let n=eM(e.state.doc,t);if(n<0)return!1;let r=e.view.nodeDOM(n);if(!(r instanceof HTMLElement))return!1;r.scrollIntoView({block:`center`});let i=getComputedStyle(r).getPropertyValue(`--color-selection`).trim()||`rgba(47,125,109,.25)`;return r.animate?.([{backgroundColor:i},{backgroundColor:`transparent`}],{duration:2e3,easing:`ease-out`}),!0}var nM=Tp.create({name:`blockLinks`,addOptions(){return{labels:null,link:void 0,onCopied:void 0}},addGlobalAttributes(){return[{types:qj,attributes:{blockId:{default:null,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-block-id`);return t&&Jj.test(t)?t:null},renderHTML:e=>e.blockId?{"data-block-id":e.blockId}:{}}}}]},addKeyboardShortcuts(){let{link:e,onCopied:t}=this.options;return{"Mod-Shift-c":({editor:n})=>{if(!e)return!1;let r=n.state.selection.$from;if(r.depth<1)return!1;let i=r.before(1),a=n.state.doc.nodeAt(i);return!a||!qj.includes(a.type.name)||!a.attrs.blockId&&!n.isEditable?!1:($j(n.view,i,e,t),!0)}}},addProseMirrorPlugins(){let{link:e,onCopied:t}=this.options,n=this.options.labels,r=this.editor;return[new D({key:new Un(`blockLinks`),view:i=>new oM(i,r,n,e,t),props:{decorations:e=>{let t=aM(e);if(t<0)return null;let n=e.doc.nodeAt(t);return xs.create(e.doc,[vs.node(t,t+n.nodeSize,{class:`dw-block-current`})])}}})]}}),rM=``,iM=``;function aM(e){let{$from:t,$to:n}=e.selection;if(e.selection instanceof E&&t.depth===0)return t.pos;if(t.depth<1||n.depth<1)return-1;let r=t.before(1);return r===n.before(1)?r:-1}var oM=class{view;editor;labels;link;onCopied;gutter=document.createElement(`div`);linkButton=document.createElement(`button`);grip=document.createElement(`button`);pos=-1;closeMenu=null;constructor(e,t,n,r,i){this.view=e,this.editor=t,this.labels=n,this.link=r,this.onCopied=i;let a=this.gutter;a.className=`dw-block-gutter`,a.contentEditable=`false`,a.hidden=!0,a.addEventListener(`mouseleave`,this.leave);let o=this.linkButton;o.type=`button`,o.className=`dw-block-handle`,o.setAttribute(`aria-label`,n.blocks.copyBlockLink),o.title=n.blocks.copyBlockLink,o.innerHTML=rM,o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>void this.copy());let s=this.grip;s.type=`button`,s.className=`dw-block-handle dw-block-grip`,s.setAttribute(`aria-label`,n.blockMenu.open),s.setAttribute(`aria-haspopup`,`menu`),s.setAttribute(`aria-expanded`,`false`),s.title=n.blockMenu.open,s.innerHTML=iM,s.draggable=!0,s.addEventListener(`click`,this.openMenu),s.addEventListener(`dragstart`,this.dragStart),s.addEventListener(`dragend`,()=>this.rest()),r&&a.append(o),a.append(s),e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave),e.dom.addEventListener(`focus`,this.rest),e.dom.addEventListener(`blur`,this.blur)}get host(){let e=this.view.dom.parentElement;return e&&this.gutter.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.gutter)),e}hovering=!1;hide=()=>{this.closeMenu||(this.gutter.hidden=!0,this.pos=-1)};rest=()=>{if(this.closeMenu||this.hovering)return;let e=this.view.hasFocus()?aM(this.view.state):-1;(e<0||!this.place(e))&&this.hide()};blur=e=>{e.relatedTarget instanceof Node&&this.gutter.contains(e.relatedTarget)||this.rest()};leave=e=>{let t=e.relatedTarget;t&&(this.gutter.contains(t)||this.view.dom.contains(t))||(this.hovering=!1,this.rest())};move=e=>{if(this.closeMenu)return;this.hovering=!0;let t=e.target;for(;t&&t.parentElement!==this.view.dom;)t=t.parentElement;if(!t)return;let n;try{n=this.view.posAtDOM(t,0)}catch{return}let r=this.view.state.doc.resolve(Math.min(n,this.view.state.doc.content.size)),i=r.depth>=1?r.before(1):n;this.place(i)||this.hide()};place(e){let t=this.host,n=this.view.state.doc.nodeAt(e),r=n&&this.view.nodeDOM(e);if(!t||!n||!(r instanceof HTMLElement))return!1;let i=!!this.link&&qj.includes(n.type.name)&&(!!n.attrs.blockId||this.view.editable),a=this.view.editable;if(!i&&!a)return!1;this.linkButton.hidden=!i,this.grip.hidden=!a,this.pos=e;let o=r.getBoundingClientRect(),s=t.getBoundingClientRect();return this.gutter.style.top=`${o.top-s.top+o.height/2-11}px`,this.gutter.hidden=!1,!0}openMenu=()=>{if(this.closeMenu){this.closeMenu();return}let e=this.pos;if(e<0||!this.view.editable)return;let t=this.view.state.doc.nodeAt(e),n=!!this.link&&!!t&&qj.includes(t.type.name),r=Gj(this.editor,e,this.labels,n?()=>void this.copy(e):void 0);this.grip.setAttribute(`aria-expanded`,`true`),this.closeMenu=Kj(this.grip,r,this.labels.blockMenu.open,()=>{this.closeMenu=null,this.grip.setAttribute(`aria-expanded`,`false`),this.rest()})};dragStart=e=>{let t=this.pos;if(t<0||!e.dataTransfer)return;this.closeMenu?.();let n=E.create(this.view.state.doc,t);this.view.dispatch(this.view.state.tr.setSelection(n)),e.dataTransfer.effectAllowed=`copyMove`,e.dataTransfer.setData(`text/plain`,n.node.textContent);let r=this.view.nodeDOM(t);r instanceof HTMLElement&&e.dataTransfer.setDragImage(r,0,0),this.view.dragging={slice:n.content(),move:!0}};async copy(e=this.pos){e>=0&&this.link&&await $j(this.view,e,this.link,this.onCopied)}update(){if(!this.closeMenu){if(!this.hovering)return this.rest();(this.pos<0||this.pos>=this.view.state.doc.content.size||!this.place(this.pos))&&this.hide()}}destroy(){this.closeMenu?.(),this.gutter.parentElement?.classList.remove(`dw-block-host`),this.gutter.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave),this.view.dom.removeEventListener(`focus`,this.rest),this.view.dom.removeEventListener(`blur`,this.blur)}},sM,cM;if(typeof WeakMap<`u`){let e=new WeakMap;sM=t=>e.get(t),cM=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;sM=t=>{for(let n=0;n(t==10&&(t=0),e[t++]=n,e[t++]=r)}var lM=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;er&&(a+=i.attrs.colspan)}}for(let e=0;e1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function fM(e,t,n){e.problems||=[];let r={};for(let i=0;i0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function _M(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.node(t)}return null}function vM(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function yM(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=gM(t.$head)||bM(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function bM(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function xM(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function SM(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function CM(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function wM(e,t,n){let r=e.node(-1),i=lM.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function TM(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function EM(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;ee!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new Sn(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(xM(r)&&xM(i)&&CM(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return T.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=lM.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n0||u>0){let e=c.attrs;if(l>0&&(e=TM(e,0,l)),u>0&&(e=TM(e,e.colspan-u,u)),s.leftr.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=lM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom0&&(n=c.resolve(a+i.map[s.left])),o.bottom0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=lM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right{t.push(vs.node(n,n+e.nodeSize,{class:`selectedCell`}))}),xs.create(e.doc,t)}function jM({$from:e,$to:t}){if(e.pos==t.pos||e.pos=0&&!(e.after(i+1)=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function MM({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function NM(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof E&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=OM.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=OM.rowSelection(e,e)}else if(!n){let e=lM.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=OM.create(i,t+1,n)}}else r instanceof T&&jM(r)?a=T.create(i,r.from):r instanceof T&&MM(r)&&(a=T.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var PM=new Un(`fix-tables`);function FM(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o{t.type.spec.tableRole==`table`&&(n=LM(e,t,r,n))};return t?t.doc!=e.doc&&FM(t.doc,e.doc,0,r):e.doc.descendants(r),n}function LM(e,t,n,r){let i=lM.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n0?-1:0;DM(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o0&&i0&&t.map[s-1]==c||i0?-1:0;WM(t,r,i+s)&&(s=i==0||i==t.height?null:0);for(let a=0,c=t.width*i;a0&&i0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i0&&n[a]==n[a-1]||r.right0&&n[i]==n[i-e]||r.bottom0){let e=c+1+l.content.size,t=XM(l)?c+1:e;n.replaceWith(t+r.tableStart,e+r.tableStart,o)}n.setSelection(new OM(n.doc.resolve(c+r.tableStart))),t(n)}return!0}function $M(e,t){let n=mM(e.schema);return eN(({node:e})=>n[e.type.spec.tableRole])(e,t)}function eN(e){return(t,n)=>{let r=t.selection,i,a;if(r instanceof OM){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,a=r.$anchorCell.pos}else{if(i=_M(r.$from),!i)return!1;a=gM(r.$from)?.pos}if(i==null||a==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let o=i.attrs,s=[],c=o.colwidth;o.rowspan>1&&(o={...o,rowspan:1}),o.colspan>1&&(o={...o,colspan:1});let l=RM(t),u=t.tr;for(let e=0;e{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function nN(e){return function(t,n){if(!vM(t))return!1;if(n){let r=mM(t.schema),i=RM(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}iN(`row`,{useDeprecatedLogic:!0}),iN(`column`,{useDeprecatedLogic:!0});var aN=iN(`cell`,{useDeprecatedLogic:!0});function oN(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function lN(e,t){let n=e.selection;if(!(n instanceof OM))return!1;if(t){let r=e.tr,i=mM(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new p(i,0,0))}),r.docChanged&&t(r)}return!0}function uN(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t=t.length&&t.push(s.empty),n[i]r&&(s=s.type.createChecked(TM(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;ni&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(s.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function mN(e,t,n,r,i,a,o){let c=e.doc.type.schema,l=mM(c),u,d;if(i>t.width)for(let a=0,s=0;at.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e=t.width?!1:n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?d||=l.header_cell.createAndFill():u||=l.cell.createAndFill())}let f=l.row.create(null,s.from(c)),p=[];for(let e=t.height;e{if(!i)return!1;let a=n.selection;if(a instanceof OM)return yN(n,r,w.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=TN(i,e,t);if(o==null)return!1;if(e==`horiz`)return yN(n,r,w.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=wM(i,e,t),s;return s=a?w.near(a,1):t<0?w.near(n.doc.resolve(i.before(-1)),-1):w.near(n.doc.resolve(i.after(-1)),1),yN(n,r,s)}}}function xN(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof OM)o=a;else{let r=TN(i,e,t);if(r==null)return!1;o=new OM(n.doc.resolve(r))}let s=wM(o.$headCell,e,t);return s?yN(n,r,new OM(o.$anchorCell,s)):!1}}function SN(e,t){let n=e.state.doc,r=gM(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new OM(r))),!0):!1}function CN(e,t,n){if(!vM(e.state))return!1;let r=uN(n),i=e.state.selection;if(i instanceof OM){r||={width:1,height:1,rows:[s.from(fN(mM(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=lM.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=pN(r,o.right-o.left,o.bottom-o.top),_N(e.state,e.dispatch,a,o,r),!0}if(r){let t=yM(e.state),n=t.start(-1);return _N(e.state,e.dispatch,n,lM.get(t.node(-1)).findCell(t.pos-n),r),!0}return!1}function wN(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=EN(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof OM)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=gM(e.state.selection.$anchor))!=null&&DN(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=DN(e,n),i=hM.getState(e.state)==null;if(!r||!CM(t,r)){if(i)r=t;else return}let a=new OM(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(hM,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),hM.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(hM,-1))}function o(r){let o=r,s=hM.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(EN(e,o.target)!=n&&(c=DN(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function TN(e,t,n){if(!(e.state.selection instanceof T))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function EN(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function DN(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&gM(e.state.doc.resolve(r))||gM(e.state.doc.resolve(i))}var ON=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),kN(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type&&(this.node=e,kN(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function kN(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;enew r(e,n,t)),new MN(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=AN.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{NN(t,n,e,i)},mouseleave:e=>{PN(e)},mousedown:(e,r)=>{FN(e,r,t,n)}},decorations:e=>{let t=AN.getState(e);if(t&&t.activeHandle>-1)return WN(e,t.activeHandle)},nodeViews:{}}});return a}var MN=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(AN);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return xM(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function NN(e,t,n,r){if(!e.editable)return;let i=AN.getState(e.state);if(i&&!i.dragging){let a=LN(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=RN(e,t,`left`,n):i-t.clientX<=n&&(o=RN(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=lM.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}BN(e,o)}}}function PN(e){if(!e.editable)return;let t=AN.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&BN(e,-1)}function FN(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=AN.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=IN(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(AN,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=AN.getState(e.state);r?.dragging&&(VN(e,r.activeHandle,zN(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(AN,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=AN.getState(e.state);if(i&&i.dragging){let a=zN(i.dragging,t,n);HN(e,i.activeHandle,a,r)}}return HN(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function IN(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;eqN(e),renderHTML:e=>{let t=KN(e.align);return Pf(t)?{style:`text-align: ${t}`}:{}}}}function XN(e){let t=e.parentElement,n=e.closest(`table`);if(!t||!n)return null;let r=Array.from(t.children).indexOf(e),i=n.querySelectorAll(`colgroup > col`)[r]?.getAttribute(`width`);return i?[parseInt(i,10)]:null}function ZN(e){let t=e.getAttribute(`colwidth`);return t?t.split(`,`).map(e=>parseInt(e,10)):XN(e)}var QN=/[ \t\r\n\f]+/g;function $N(e){return e.children.length>0?!1:(e.textContent??``).replace(QN,``)===``}function eP(e){let t=e.createAndFill();if(!t)throw Error(`[tiptap error]: "${e.name}" has no default content to backfill.`);return t.content}function tP(e,t,n){if(!(n in t))return;let r=t[n];(r===1||r===`1`||r==null)&&delete e[n]}var nP=Jp.create({name:`tableCell`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:ZN},align:YN()}},tableRole:`cell`,isolating:!0,parseHTML(){return[{tag:`td`,getAttrs:e=>$N(e)?{}:!1,getContent:(e,t)=>eP(t.nodes[this.name])},{tag:`td`}]},renderHTML({HTMLAttributes:e}){let t=A(this.options.HTMLAttributes,e);return tP(t,e,`colspan`),tP(t,e,`rowspan`),[`td`,t,0]}}),rP=Jp.create({name:`tableHeader`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:ZN},align:YN()}},tableRole:`header_cell`,isolating:!0,parseHTML(){return[{tag:`th`,getAttrs:e=>$N(e)?{}:!1,getContent:(e,t)=>eP(t.nodes[this.name])},{tag:`th`}]},renderHTML({HTMLAttributes:e}){let t=A(this.options.HTMLAttributes,e);return tP(t,e,`colspan`),tP(t,e,`rowspan`),[`th`,t,0]}}),iP=Jp.create({name:`tableRow`,addOptions(){return{HTMLAttributes:{}}},content:`(tableCell | tableHeader)*`,tableRole:`row`,parseHTML(){return[{tag:`tr`}]},renderHTML({HTMLAttributes:e}){return[`tr`,A(this.options.HTMLAttributes,e),0]}});function aP(e,t){return t?[`width`,`${Math.max(t,e)}px`]:[`min-width`,`${e}px`]}function oP(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l!==null)for(let e=0,n=0;e{let r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function dP(e,t,n,r,i){let a=uP(e),o=[],s=[];for(let e=0;e{let{selection:t}=e.state;if(!fP(t))return!1;let n=0;return vu(t.ranges[0].$from,e=>e.type.name===`table`)?.node.descendants(e=>{if(e.type.name===`table`)return!1;[`tableCell`,`tableHeader`].includes(e.type.name)&&(n+=1)}),n===t.ranges.length&&(e.commands.deleteTable(),!0)};function mP(e,t){let n=e.mapping.map(t);if(vu(e.selection.$from,e=>e.type.name===`table`)?.pos===n)return;let r=e.doc.nodeAt(n);if(!r)return;let i=n+r.nodeSize-1;e.setSelection(T.near(e.doc.resolve(i),-1))}function hP(e){let t=``,n=0;for(;ne===`|`?`\\|`:e)+e.slice(i,i+r),n=i+r,a=!0;break}i+=o}a||(t+=e.slice(n,n+r),n+=r)}return t}function gP(e){return e.split(` -`).map(e=>!e.includes(`|`)||!e.includes("`")?e:hP(e)).join(` -`)}function _P(e){return(e||``).replaceAll(``,` `).replace(/\s+/g,` `).trim()}function vP(e,t){return t?e.split(t).join(` -`):e}function yP(e){return e.replace(/\\.|\|/g,e=>e===`|`?`\\|`:e)}function bP(e,t,n={}){if(!e||!e.content||e.content.length===0)return``;let r=[];e.content.forEach(e=>{let i=[];e.content&&e.content.forEach(e=>{let r=``;r=e.content&&Array.isArray(e.content)&&e.content.length>1?e.content.map(e=>vP(t.renderChildren(e),n.cellLineSeparator)).join(` -`):vP(e.content?t.renderChildren(e.content):``,n.cellLineSeparator);let a=yP(_P(r.replace(/[ \t]*\r?\n[ \t]*/g,`
`))),o=e.type===`tableHeader`,s=JN(e.attrs);i.push({text:a,isHeader:o,align:s})}),r.push(i)});let i=r.reduce((e,t)=>Math.max(e,t.length),0);if(i===0)return``;let a=Array.from({length:i}).fill(0);r.forEach(e=>{for(let t=0;ta[t]&&(a[t]=n),a[t]<3&&(a[t]=3)}});let o=(e,t)=>e+` `.repeat(Math.max(0,t-e.length)),s=r[0],c=s.some(e=>e.isHeader),l=Array.from({length:i}).fill(null);r.forEach(e=>{for(let t=0;tc&&s[t]&&s[t].text||``);return u+=`| ${d.map((e,t)=>o(e,a[t])).join(` | `)} |\n`,u+=`| ${a.map((e,t)=>{let n=Math.max(3,e),r=l[t];return r===`left`?`:${`-`.repeat(n)}`:r===`right`?`${`-`.repeat(n)}:`:r===`center`?`:${`-`.repeat(n)}:`:`-`.repeat(n)}).join(` | `)} |\n`,(c?r.slice(1):r).forEach(e=>{u+=`| ${Array.from({length:i}).fill(0).map((t,n)=>o(e[n]&&e[n].text||``,a[n])).join(` | `)} |\n`}),u}var xP=new Un(`preserveCellSelectionOnContextMenu`);function SP(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(n)return n.pos;if(!(t.target instanceof Node))return null;try{return e.posAtDOM(t.target,0)}catch{return null}}function CP(e,t){let n=!1;return e.forEachCell((e,r)=>{t>=r&&t{let n=[],r=Array.isArray(e.align)?e.align:[];if(e.header){let i=[];e.header.forEach((e,n)=>{let a=KN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableHeader`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}return e.rows&&e.rows.forEach(e=>{let i=[];e.forEach((e,n)=>{let a=KN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableCell`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}),t.createNode(`table`,void 0,n)},renderMarkdown:(e,t)=>bP(e,t),markdownTokenizer:{name:`table`,level:`block`,start:e=>{let t=e.split(` +`))};return s(n),{dom:r,contentDOM:a,update:e=>e.type===n.type&&(s(e),!0),ignoreMutation:e=>i.contains(e.target)}}}}),Lj=(e,t)=>e===`application/pdf`||typeof t==`string`&&/\.pdf$/i.test(t);function Rj(e,t,n,r){let i=!1,a=null,o=null,s=document.createElement(`div`);return s.className=`dw-pdf__status`,s.textContent=r.blocks.pdfLoading,e.replaceChildren(s),(async()=>{try{let c=await n();if(i)return;o=c.getDocument({url:t});let l=await o.promise;if(i)return;s.remove();let u=Math.max(e.clientWidth-2,200),d=window.devicePixelRatio||1;a=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=t.target;a?.unobserve(e),p(e,Number(e.dataset.page))}},{root:e,rootMargin:`400px 0px`});let f=(await l.getPage(1)).getViewport({scale:1});for(let t=1;t<=l.numPages;t++){let n=document.createElement(`div`);n.className=`dw-pdf__page`,n.dataset.page=String(t),n.style.aspectRatio=`${f.width} / ${f.height}`,n.setAttribute(`aria-label`,r.blocks.pdfPage.replace(`{n}`,String(t))),e.append(n),a.observe(n)}async function p(e,t){let n=await l.getPage(t);if(i)return;let r=u/n.getViewport({scale:1}).width,a=n.getViewport({scale:r*d}),o=document.createElement(`canvas`);o.width=Math.floor(a.width),o.height=Math.floor(a.height),e.style.aspectRatio=`${a.width} / ${a.height}`,e.append(o),await n.render({canvas:o,viewport:a}).promise}}catch{i||(s.textContent=r.blocks.loadFailed)}})(),()=>{i=!0,a?.disconnect(),o?.destroy()}}var zj={page:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M9 12h6`,`M9 16h6`],"chevron-right":[`M10 6l6 6-6 6`],"chevron-left":[`M14 6l-6 6 6 6`],"chevron-down":[`M6 10l6 6 6-6`],"chevron-up":[`M6 14l6-6 6 6`],plus:[`M12 5v14`,`M5 12h14`],search:[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`],more:[`M6 12h.01`,`M12 12h.01`,`M18 12h.01`],drop:[`M12 4h7v7a7 7 0 1 1-7-7z`],info:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 11v5`,`M12 8h.01`],check:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8 12.5l2.5 2.5L16 9.5`],alert:[`M12 4l9 16H3z`,`M12 10v4`,`M12 17h.01`],error:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M9 9l6 6`,`M15 9l-6 6`],text:[`M5 6h14`,`M12 6v13`],heading:[`M6 5v14`,`M18 5v14`,`M6 12h12`],list:[`M9 6h11`,`M9 12h11`,`M9 18h11`,`M4.5 6h.01`,`M4.5 12h.01`,`M4.5 18h.01`],todo:[`M4 4h7v7H4z`,`M5.5 7.5l1.5 1.5 2.5-2.5`,`M14 7h6`,`M4 14h7v7H4z`,`M14 17h6`],code:[`M9 7l-5 5 5 5`,`M15 7l5 5-5 5`],quote:[`M6 6v12`,`M10 8h9`,`M10 12h9`,`M10 16h6`],image:[`M4 5h16v14H4z`,`M4 16l5-5 4 4 2-2 5 5`,`M15.5 8.5h.01`],table:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 5v14`],lock:[`M6 11h12v9H6z`,`M8.5 11V8a3.5 3.5 0 0 1 7 0v3`],trash:[`M4 7h16`,`M10 4h4`,`M6 7l1 13h10l1-13`,`M10 11v6`,`M14 11v6`],settings:[`M4 7h9`,`M17 7h3`,`M15 5v4`,`M4 17h3`,`M11 17h9`,`M9 15v4`],menu:[`M4 7h16`,`M4 12h16`,`M4 17h16`],close:[`M6 6l12 12`,`M18 6L6 18`],open:[`M8 16L16 8`,`M9 8h7v7`],restore:[`M4.5 13a7.5 7.5 0 1 0 2.2-6.3`,`M5 4v4h4`],"sign-out":[`M14 4h5v16h-5`,`M10 8l-4 4 4 4`,`M6 12h9`],sidebar:[`M4 5h16v14H4z`,`M9.5 5v14`],home:[`M4 11l8-7 8 7`,`M6 9.5V20h12V9.5`,`M10 20v-5h4v5`],sun:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M12 3v1.5`,`M12 19.5V21`,`M3 12h1.5`,`M19.5 12H21`,`M5.6 5.6l1.1 1.1`,`M17.3 17.3l1.1 1.1`,`M5.6 18.4l1.1-1.1`,`M17.3 6.7l1.1-1.1`],moon:[`M19.5 14.5A8 8 0 0 1 9.5 4.5a8 8 0 1 0 10 10z`],monitor:[`M4 5h16v11H4z`,`M9 20h6`,`M12 16v4`],selector:[`M8 9l4-4 4 4`,`M8 15l4 4 4-4`],star:[`M12 4l2.5 5.2 5.5.8-4 3.9.9 5.6L12 16.9l-4.9 2.6.9-5.6-4-3.9 5.5-.8z`],clock:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M12 7v5l3 2`],calendar:[`M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z`,`M4 10h16`,`M8 3v4`,`M16 3v4`],share:[`M12 4v11`,`M8 8l4-4 4 4`,`M6 13v7h12v-7`],link:[`M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1`,`M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1`],upload:[`M12 16V4`,`M7 9l5-5 5 5`,`M4 20h16`],download:[`M12 4v12`,`M7 11l5 5 5-5`,`M4 20h16`],file:[`M6 3h8l4 4v14H6z`,`M14 3v4h4`],paperclip:[`M18 11.5l-6.4 6.4a4.2 4.2 0 0 1-6-6l7-7a2.8 2.8 0 0 1 4 4l-7 7a1.4 1.4 0 0 1-2-2l6.4-6.4`],comment:[`M5 5h14v10H9l-4 4z`],at:[`M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z`,`M16 12v1.5a2.5 2.5 0 0 0 5 0V12a9 9 0 1 0-3.5 7.1`],bold:[`M7 5h6a3.5 3.5 0 0 1 0 7H7z`,`M7 12h7a3.5 3.5 0 0 1 0 7H7z`],italic:[`M10 5h8`,`M6 19h8`,`M14 5l-4 14`],strike:[`M5 12h14`,`M16 7.5A3.5 3 0 0 0 12.5 5h-1A3.5 3 0 0 0 8 8c0 4 8 3 8 7.5a3.5 3.5 0 0 1-3.5 3.5h-1A3.5 3 0 0 1 8 16.5`],underline:[`M7 4v7a5 5 0 0 0 10 0V4`,`M5 20h14`],"list-ordered":[`M10 6h10`,`M10 12h10`,`M10 18h10`,`M4 5l1.5-1v5`,`M4 15.5a1.5 1.5 0 0 1 3 .5L4 19h3`],divider:[`M4 12h16`],globe:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M3 12h18`,`M12 3c2.5 2.5 3.5 5.5 3.5 9s-1 6.5-3.5 9`,`M12 3C9.5 5.5 8.5 8.5 8.5 12s1 6.5 3.5 9`],bell:[`M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z`,`M10 20a2 2 0 0 0 4 0`],"bell-off":[`M6 16V11a6 6 0 0 1 9.5-4.9`,`M18 11v5l1.5 2H8`,`M10 20a2 2 0 0 0 4 0`,`M4 4l16 16`],smile:[`M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18z`,`M8.5 14a4 4 0 0 0 7 0`,`M9 9.5h.01`,`M15 9.5h.01`],reply:[`M9 7L4 12l5 5`,`M4 12h10a6 6 0 0 1 6 6v1`],pencil:[`M15 5l4 4L8 20H4v-4z`],sigma:[`M18 6V4H6l6 8l-6 8h12v-2`],diagram:[`M4 4h6v5H4z`,`M14 15h6v5h-6z`,`M7 9v4a2 2 0 0 0 2 2h5`],video:[`M4 6h11v12H4z`,`M15 10l5-3v10l-5-3`],archive:[`M4 5h16v4H4z`,`M5 9v10h14V9`,`M10 13h4`],pin:[`M9 4h6`,`M10 4v6l-3 4h10l-3-4V4`,`M12 14v6`],width:[`M3 12h18`,`M7 8l-4 4 4 4`,`M17 8l4 4-4 4`],type:[`M5 7V5h14v2`,`M12 5v14`,`M9 19h6`],server:[`M4 4h16v6H4z`,`M4 14h16v6H4z`,`M8 7h.01`,`M8 17h.01`],users:[`M9 11a3.5 3.5 0 1 0 0-7a3.5 3.5 0 1 0 0 7z`,`M3 20a6 6 0 0 1 12 0`,`M16 4.5a3.5 3.5 0 0 1 0 6.5`,`M18 14a6 6 0 0 1 3 6`],"align-left":[`M4 6h16`,`M4 10h10`,`M4 14h16`,`M4 18h10`],"align-center":[`M4 6h16`,`M7 10h10`,`M4 14h16`,`M7 18h10`],"align-right":[`M4 6h16`,`M10 10h10`,`M4 14h16`,`M10 18h10`],grip:[`M9 6h.01`,`M15 6h.01`,`M9 12h.01`,`M15 12h.01`,`M9 18h.01`,`M15 18h.01`],copy:[`M9 9h11v11H9z`,`M5 15H4V4h11v1`],"arrow-up":[`M12 19V5`,`M6 11l6-6 6 6`],"arrow-down":[`M12 5v14`,`M6 13l6 6 6-6`],callout:[`M4 5h16v14H4z`,`M8 10h.01`,`M11 10h5`,`M8 14h8`],columns:[`M4 5h6v14H4z`,`M14 5h6v14h-6z`],palette:[`M12 3a9 9 0 1 0 0 18c1 0 1.5-.7 1.5-1.5 0-1.2-1-1.5-1-2.5s.8-1.5 2-1.5H17a4 4 0 0 0 4-4c0-4.7-4-8.5-9-8.5z`,`M7.5 11h.01`,`M10 7.5h.01`,`M14.5 7.5h.01`],"page-plus":[`M6 3h8l4 4v14H6z`,`M14 3v4h4`,`M12 11v6`,`M9 14h6`],tag:[`M4 4h7l9 9-7 7-9-9z`,`M8 8h.01`],grid:[`M4 4h7v7H4z`,`M13 4h7v7h-7z`,`M4 13h7v7H4z`,`M13 13h7v7h-7z`],cards:[`M4 5h16v6H4z`,`M4 15h16v4H4z`],timeline:[`M4 4v16`,`M7 7h8`,`M10 12h10`,`M7 17h6`],chart:[`M4 20h16`,`M7 16v-5`,`M12 16V6`,`M17 16v-8`],filter:[`M4 5h16l-6 8v6l-4-2v-4z`],layers:[`M12 4l8 4-8 4-8-4z`,`M4 12l8 4 8-4`,`M4 16l8 4 8-4`],journal:[`M6 3h11a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6z`,`M9 3v18`,`M12 8h3`,`M12 12h3`],sliders:[`M5 6h14`,`M5 12h14`,`M5 18h14`,`M9 4v4`,`M15 10v4`,`M11 16v4`],sort:[`M7 4v16`,`M4 7l3-3 3 3`,`M17 20V4`,`M14 17l3 3 3-3`],database:[`M4 5h16v14H4z`,`M4 10h16`,`M4 15h16`,`M10 10v9`],relation:[`M3 6h7v5H3z`,`M14 13h7v5h-7z`,`M10 8.5h2.5a2 2 0 0 1 2 2V13`],rollup:[`M4 5h16`,`M4 9h16`,`M4 13h16`,`M12 16v5`,`M9 18l3 3 3-3`],edgeless:[`M4 5h16v14H4z`,`M7 15l3-4 3 3 4-5`,`M7 8.5h.01`],cursor:[`M6 4l12 7-5.5 1.5L10 18z`],hand:[`M8 13V6.5a1.5 1.5 0 0 1 3 0V12`,`M11 11V5a1.5 1.5 0 0 1 3 0v6`,`M14 11V6.5a1.5 1.5 0 0 1 3 0V14a6 6 0 0 1-6 6h-1a5 5 0 0 1-4.2-2.3L4.5 14a1.5 1.5 0 0 1 2.5-1.6L8 14`],note:[`M5 4h14v10l-6 6H5z`,`M13 20v-6h6`],shapes:[`M4 13h7v7H4z`,`M16.5 4a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7z`,`M7.5 4l3.5 6H4z`],connector:[`M5 19a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M19 9a2 2 0 1 0 0-4a2 2 0 1 0 0 4z`,`M6.5 15.5C9 10 13 13 17.5 8.5`],pen:[`M4 20l1-4L16 5l3 3L8 19z`,`M14 7l3 3`],eraser:[`M8 20h12`,`M4.5 15.5l9-9 6 6-7.5 7.5H9z`,`M9 11l5 5`],frame:[`M7 3v18`,`M17 3v18`,`M3 7h18`,`M3 17h18`],mindmap:[`M10 10h4v4h-4z`,`M3 4h4v3H3z`,`M17 4h4v3h-4z`,`M3 17h4v3H3z`,`M17 17h4v3h-4z`,`M7 6l3 4`,`M17 6l-3 4`,`M7 18l3-4`,`M17 18l-3-4`],sticker:[`M12 3a9 9 0 1 0 9 9h-5a4 4 0 0 1-4-4z`,`M12 3a9 9 0 0 1 9 9`,`M9 14.5c1.5 1.5 4.5 1.5 6 0`],present:[`M3 4h18`,`M5 4v11h14V4`,`M12 15v3`,`M8 21l4-3 4 3`],"zoom-in":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`,`M11 8v6`],"zoom-out":[`M11 4a7 7 0 1 0 0 14a7 7 0 1 0 0-14z`,`M16.5 16.5L20 20`,`M8 11h6`],fit:[`M4 9V4h5`,`M15 4h5v5`,`M20 15v5h-5`,`M9 20H4v-5`],"send-back":[`M4 12h9v8H4z`,`M11 4h9v8h-9z`],group:[`M4 4h3`,`M10 4h4`,`M17 4h3v3`,`M20 10v4`,`M20 17v3h-3`,`M14 20h-4`,`M7 20H4v-3`,`M4 14v-4`,`M8 8h8v8H8z`],sparkles:[`M10 4l1.6 4.4L16 10l-4.4 1.6L10 16l-1.6-4.4L4 10l4.4-1.6z`,`M17 14l.8 2.2L20 17l-2.2.8L17 20l-.8-2.2L14 17l2.2-.8z`,`M17 3v4`,`M15 5h4`],send:[`M4 12l16-8-6 16-2-6z`,`M12 14l8-10`],eye:[`M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z`,`M12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6z`],"user-plus":[`M15 20v-1a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v1`,`M8.5 4a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7z`,`M19 8v6`,`M16 11h6`],music:[`M9 18V5l11-2v13`,`M6 15a3 3 0 1 0 0 6a3 3 0 1 0 0-6z`,`M17 13a3 3 0 1 0 0 6a3 3 0 1 0 0-6z`],tabs:[`M3 9h18v11H3z`,`M3 9V5h6v4`,`M9 5h6v4`],"page-break":[`M6 3v5h12V3`,`M6 21v-5h12v5`,`M3 12h2`,`M8 12h2`,`M14 12h2`,`M19 12h2`],footnote:[`M4 7h10`,`M9 7v12`,`M17 4h2v5`,`M16 9h4`],status:[`M7 8h10a4 4 0 0 1 0 8H7a4 4 0 0 1 0-8z`,`M8 12h.01`]},Bj=`http://www.w3.org/2000/svg`;function Vj(e,t=18){let n=document.createElementNS(Bj,`svg`);for(let[e,r]of Object.entries({width:String(t),height:String(t),viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`1.75`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`}))n.setAttribute(e,r);for(let t of zj[e]){let e=document.createElementNS(Bj,`path`);e.setAttribute(`d`,t),n.append(e)}return n}function Hj(e){return()=>{let t=null,n=null,r=null,i=0,a=null,o=()=>a?.items??r?.items??[],s=t=>{let n=o()[t];if(!r||n===void 0)return;let s=e.children?.(n);s?.length?(a={parent:n,items:s},i=0,c()):e.pick(r,n)},c=()=>{if(!t||!r)return;let n=r;if(t.replaceChildren(),e.showQuery){let e=document.createElement(`div`);e.className=`dw-suggest__query`,e.textContent=`/${n.query}`,t.append(e)}if(a){let n=document.createElement(`div`);n.className=`dw-suggest__query`,n.textContent=`‹ ${e.toItem(a.parent).label}`,t.append(n)}let c=o();if(c.length)c.forEach((n,r)=>{let a=e.toItem(n),o=document.createElement(`div`);o.className=r===i?`dw-suggest__item is-active`:`dw-suggest__item`,o.setAttribute(`role`,`option`),o.setAttribute(`aria-selected`,String(r===i)),o.addEventListener(`mousedown`,e=>{e.preventDefault(),s(r)});let c=document.createElement(`span`);c.className=`dw-suggest__icon`,a.glyph?(c.classList.add(`dw-suggest__icon--glyph`),c.textContent=a.glyph):c.append(Vj(a.icon??`text`));let l=document.createElement(`span`);l.className=`dw-suggest__text`;let u=document.createElement(`span`);if(u.className=`dw-suggest__label`,u.textContent=a.label,l.append(u),a.description){let e=document.createElement(`span`);e.className=`dw-suggest__desc`,e.textContent=a.description,l.append(e)}if(o.append(c,l),e.children?.(n)?.length){o.setAttribute(`aria-haspopup`,`listbox`);let e=Vj(`chevron-right`,14);e.classList.add(`dw-suggest__more`),o.append(e)}t.append(o)}),t.querySelector(`.is-active`)?.scrollIntoView({block:`nearest`});else{let n=document.createElement(`div`);n.className=`dw-suggest__empty`,n.setAttribute(`role`,`status`),n.textContent=e.empty,t.append(n)}},l=()=>{let e=r?.clientRect?.();if(!t||!e)return;let i={getBoundingClientRect:()=>r?.clientRect?.()??e};n?.(),n=Aj(i,t,()=>{t&&Pj(i,t,{placement:`bottom-start`,strategy:`fixed`,middleware:[jj(6),Nj(),Mj({padding:8})]}).then(({x:e,y:n})=>{t&&Object.assign(t.style,{left:`${e}px`,top:`${n}px`})})})},u=()=>{n?.(),n=null,t?.remove(),t=null};return{onStart(n){r=n,i=0,a=null,t=document.createElement(`div`),t.className=`dw-suggest`,t.setAttribute(`role`,`listbox`),t.setAttribute(`aria-label`,e.label),document.body.append(t),c(),l()},onUpdate(e){e.items!==r?.items&&(i=0,a=null),r=e,c(),l()},onKeyDown({event:t}){let n=o().length;if(a&&(t.key===`Escape`||t.key===`ArrowLeft`))return a=null,i=0,c(),!0;let r=o()[i];return t.key===`ArrowRight`&&r!==void 0&&e.children?.(r)?.length?(s(i),!0):t.key===`Escape`?(u(),!0):n?t.key===`ArrowDown`||t.key===`ArrowUp`?(i=(i+(t.key===`ArrowDown`?1:-1)+n)%n,c(),!0):t.key===`Enter`||t.key===`Tab`?(s(i),!0):!1:!1},onExit(){r=null,u()}}}}function Uj(e){let t={...e};return t.attrs&&`blockId`in t.attrs&&(t.attrs={...t.attrs,blockId:null}),t.content&&=t.content.map(Uj),t}function Wj(e,t,n,r){let i=e.state.doc.nodeAt(t);if(!i)return[];let a=n.blockMenu,o=t+i.nodeSize,s=e.state.doc.resolve(t).index(0),c=[];if([`bulletList`,`orderedList`,`taskList`].includes(i.type.name)&&c.push({id:`groupAsDatabase`,label:n.database.groupAsDatabase,icon:`database`,run:()=>{e.chain().focus().setTextSelection(t+2).groupAsDatabase().run()}}),i.type.name===`codeBlock`){let n=!!e.extensionManager.extensions.find(e=>e.name===`codeBlock`)?.options.lineNumbers,r=Fj(i.attrs.lineNumbers,n);c.push({id:`lineNumbers`,label:r?a.hideLineNumbers:a.showLineNumbers,icon:`list-ordered`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`lineNumbers`,!r))})}if(i.type.name===`fileAttachment`&&Lj(i.attrs.mime,i.attrs.name)){let n=i.attrs.view===`preview`;c.push({id:`pdfView`,label:n?a.showAsFile:a.showPages,icon:n?`paperclip`:`file`,run:()=>e.view.dispatch(e.state.tr.setNodeAttribute(t,`view`,n?`card`:`preview`))})}return s>0&&c.push({id:`moveUp`,label:a.moveUp,icon:`arrow-up`,run:()=>{let n=e.state.doc.child(s-1),r=e.state.tr.delete(t,o).insert(t-n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),s{let n=e.state.doc.child(s+1),r=e.state.tr.delete(t,o).insert(t+n.nodeSize,i);e.view.dispatch(r.scrollIntoView())}}),c.push({id:`duplicate`,label:a.duplicate,icon:`plus`,run:()=>{let t=e.schema.nodeFromJSON(Uj(i.toJSON()));e.view.dispatch(e.state.tr.insert(o,t).scrollIntoView())}},{id:`copy`,label:a.copy,icon:`copy`,run:()=>{e.chain().focus().setNodeSelection(t).run(),document.execCommand(`copy`)}}),r&&c.push({id:`copyLink`,label:n.blocks.copyBlockLink,icon:`link`,run:r}),c.push({id:`delete`,label:a.delete,icon:`trash`,danger:!0,run:()=>{e.view.dispatch(e.state.tr.delete(t,o)),e.commands.focus()}}),c}function Gj(e,t,n,r){let i=document.createElement(`div`);i.className=`dw-suggest dw-block-menu`,i.setAttribute(`role`,`menu`),i.setAttribute(`aria-label`,n);let a=t,o=0,s=[],c=()=>{i.replaceChildren(),a.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`dw-suggest__item${t===o?` is-active`:``}${e.danger?` is-danger`:``}`,n.setAttribute(`role`,`menuitem`),n.tabIndex=-1,e.children&&n.setAttribute(`aria-haspopup`,`menu`);let r=document.createElement(`span`);r.className=`dw-suggest__icon`,r.append(Vj(e.icon));let a=document.createElement(`span`);if(a.className=`dw-suggest__label`,a.textContent=e.label,n.append(r,a),e.children){let e=Vj(`chevron-right`,14);e.classList.add(`dw-block-menu__more`),n.append(e)}n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>l(t)),n.addEventListener(`mouseenter`,()=>{o=t;for(let[e,n]of[...i.children].entries())n.classList.toggle(`is-active`,e===t)}),i.append(n)}),i.children[o]?.focus()},l=e=>{let t=a[e];t&&(t.children?(s.push(a),a=t.children,o=0,c()):(m(),t.run?.()))},u=e=>{e.key===`Escape`||e.key===`ArrowLeft`&&s.length?(e.preventDefault(),e.stopPropagation(),s.length?(a=s.pop(),o=0,c()):m()):e.key===`ArrowDown`||e.key===`ArrowUp`?(e.preventDefault(),o=(o+(e.key===`ArrowDown`?1:-1)+a.length)%a.length,c()):(e.key===`Enter`||e.key===` `||e.key===`ArrowRight`)&&(e.preventDefault(),(e.key!==`ArrowRight`||a[o]?.children)&&l(o))},d=t=>{!i.contains(t.target)&&!e.contains(t.target)&&m()};document.body.append(i);let f=Aj(e,i,()=>{Pj(e,i,{placement:`bottom-start`,strategy:`fixed`,middleware:[jj(4),Nj(),Mj({padding:8})]}).then(({x:e,y:t})=>Object.assign(i.style,{left:`${e}px`,top:`${t}px`}))});i.addEventListener(`keydown`,u),document.addEventListener(`mousedown`,d,!0);let p=!1;function m(){p||(p=!0,f(),i.remove(),document.removeEventListener(`mousedown`,d,!0),s=[],r?.())}return c(),m}var Kj=[`paragraph`,`heading`,`blockquote`,`codeBlock`,`bulletList`,`orderedList`,`taskList`,`callout`,`table`,`details`,`image`,`embed`,`linkCard`,`mermaid`,`blockMath`,`drawio`,`excalidraw`,`fileAttachment`],qj=/^[a-z0-9]{6,16}$/;function Jj(e){return/^#?b-([a-z0-9]{6,16})$/.exec(e)?.[1]??``}var Yj=e=>`#b-${e}`;function Xj(){return[...crypto.getRandomValues(new Uint8Array(8))].map(e=>(e%36).toString(36)).join(``)}function Zj(e,t){let n=e.state.doc.nodeAt(t);if(!n)return null;let r=n.attrs.blockId;if(r)return r;if(!e.editable||!Kj.includes(n.type.name))return null;let i=Xj();return e.dispatch(e.state.tr.setNodeAttribute(t,`blockId`,i)),i}async function Qj(e,t,n,r){let i=Zj(e,t);if(!i)return!1;let a=n(Yj(i));try{await navigator.clipboard.writeText(a),r?.(a)}catch{window.prompt(``,a)}return!0}function $j(e,t){let n=-1;return e.descendants((e,r)=>n>=0?!1:(e.attrs.blockId===t&&(n=r),!0)),n}function eM(e,t){let n=$j(e.state.doc,t);if(n<0)return!1;let r=e.view.nodeDOM(n);if(!(r instanceof HTMLElement))return!1;r.scrollIntoView({block:`center`});let i=getComputedStyle(r).getPropertyValue(`--color-selection`).trim()||`rgba(47,125,109,.25)`;return r.animate?.([{backgroundColor:i},{backgroundColor:`transparent`}],{duration:2e3,easing:`ease-out`}),!0}var tM=wp.create({name:`blockLinks`,addOptions(){return{labels:null,link:void 0,onCopied:void 0}},addGlobalAttributes(){return[{types:Kj,attributes:{blockId:{default:null,keepOnSplit:!1,parseHTML:e=>{let t=e.getAttribute(`data-block-id`);return t&&qj.test(t)?t:null},renderHTML:e=>e.blockId?{"data-block-id":e.blockId}:{}}}}]},addKeyboardShortcuts(){let{link:e,onCopied:t}=this.options;return{"Mod-Shift-c":({editor:n})=>{if(!e)return!1;let r=n.state.selection.$from;if(r.depth<1)return!1;let i=r.before(1),a=n.state.doc.nodeAt(i);return!a||!Kj.includes(a.type.name)||!a.attrs.blockId&&!n.isEditable?!1:(Qj(n.view,i,e,t),!0)}}},addProseMirrorPlugins(){let{link:e,onCopied:t}=this.options,n=this.options.labels,r=this.editor;return[new D({key:new O(`blockLinks`),view:i=>new aM(i,r,n,e,t),props:{decorations:e=>{let t=iM(e);if(t<0)return null;let n=e.doc.nodeAt(t);return bs.create(e.doc,[_s.node(t,t+n.nodeSize,{class:`dw-block-current`})])}}})]}}),nM=``,rM=``;function iM(e){let{$from:t,$to:n}=e.selection;if(e.selection instanceof E&&t.depth===0)return t.pos;if(t.depth<1||n.depth<1)return-1;let r=t.before(1);return r===n.before(1)?r:-1}var aM=class{view;editor;labels;link;onCopied;gutter=document.createElement(`div`);linkButton=document.createElement(`button`);grip=document.createElement(`button`);pos=-1;closeMenu=null;constructor(e,t,n,r,i){this.view=e,this.editor=t,this.labels=n,this.link=r,this.onCopied=i;let a=this.gutter;a.className=`dw-block-gutter`,a.contentEditable=`false`,a.hidden=!0,a.addEventListener(`mouseleave`,this.leave);let o=this.linkButton;o.type=`button`,o.className=`dw-block-handle`,o.setAttribute(`aria-label`,n.blocks.copyBlockLink),o.title=n.blocks.copyBlockLink,o.innerHTML=nM,o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>void this.copy());let s=this.grip;s.type=`button`,s.className=`dw-block-handle dw-block-grip`,s.setAttribute(`aria-label`,n.blockMenu.open),s.setAttribute(`aria-haspopup`,`menu`),s.setAttribute(`aria-expanded`,`false`),s.title=n.blockMenu.open,s.innerHTML=rM,s.draggable=!0,s.addEventListener(`click`,this.openMenu),s.addEventListener(`dragstart`,this.dragStart),s.addEventListener(`dragend`,()=>this.rest()),r&&a.append(o),a.append(s),e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave),e.dom.addEventListener(`focus`,this.rest),e.dom.addEventListener(`blur`,this.blur)}get host(){let e=this.view.dom.parentElement;return e&&this.gutter.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.gutter)),e}hovering=!1;hide=()=>{this.closeMenu||(this.gutter.hidden=!0,this.pos=-1)};rest=()=>{if(this.closeMenu||this.hovering)return;let e=this.view.hasFocus()?iM(this.view.state):-1;(e<0||!this.place(e))&&this.hide()};blur=e=>{e.relatedTarget instanceof Node&&this.gutter.contains(e.relatedTarget)||this.rest()};leave=e=>{let t=e.relatedTarget;t&&(this.gutter.contains(t)||this.view.dom.contains(t))||(this.hovering=!1,this.rest())};move=e=>{if(this.closeMenu)return;this.hovering=!0;let t=e.target;for(;t&&t.parentElement!==this.view.dom;)t=t.parentElement;if(!t)return;let n;try{n=this.view.posAtDOM(t,0)}catch{return}let r=this.view.state.doc.resolve(Math.min(n,this.view.state.doc.content.size)),i=r.depth>=1?r.before(1):n;this.place(i)||this.hide()};place(e){let t=this.host,n=this.view.state.doc.nodeAt(e),r=n&&this.view.nodeDOM(e);if(!t||!n||!(r instanceof HTMLElement))return!1;let i=!!this.link&&Kj.includes(n.type.name)&&(!!n.attrs.blockId||this.view.editable),a=this.view.editable;if(!i&&!a)return!1;this.linkButton.hidden=!i,this.grip.hidden=!a,this.pos=e;let o=r.getBoundingClientRect(),s=t.getBoundingClientRect();return this.gutter.style.top=`${o.top-s.top+o.height/2-11}px`,this.gutter.hidden=!1,!0}openMenu=()=>{if(this.closeMenu){this.closeMenu();return}let e=this.pos;if(e<0||!this.view.editable)return;let t=this.view.state.doc.nodeAt(e),n=!!this.link&&!!t&&Kj.includes(t.type.name),r=Wj(this.editor,e,this.labels,n?()=>void this.copy(e):void 0);this.grip.setAttribute(`aria-expanded`,`true`),this.closeMenu=Gj(this.grip,r,this.labels.blockMenu.open,()=>{this.closeMenu=null,this.grip.setAttribute(`aria-expanded`,`false`),this.rest()})};dragStart=e=>{let t=this.pos;if(t<0||!e.dataTransfer)return;this.closeMenu?.();let n=E.create(this.view.state.doc,t);this.view.dispatch(this.view.state.tr.setSelection(n)),e.dataTransfer.effectAllowed=`copyMove`,e.dataTransfer.setData(`text/plain`,n.node.textContent);let r=this.view.nodeDOM(t);r instanceof HTMLElement&&e.dataTransfer.setDragImage(r,0,0),this.view.dragging={slice:n.content(),move:!0}};async copy(e=this.pos){e>=0&&this.link&&await Qj(this.view,e,this.link,this.onCopied)}update(){if(!this.closeMenu){if(!this.hovering)return this.rest();(this.pos<0||this.pos>=this.view.state.doc.content.size||!this.place(this.pos))&&this.hide()}}destroy(){this.closeMenu?.(),this.gutter.parentElement?.classList.remove(`dw-block-host`),this.gutter.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave),this.view.dom.removeEventListener(`focus`,this.rest),this.view.dom.removeEventListener(`blur`,this.blur)}},oM,sM;if(typeof WeakMap<`u`){let e=new WeakMap;oM=t=>e.get(t),sM=(t,n)=>(e.set(t,n),n)}else{let e=[],t=0;oM=t=>{for(let n=0;n(t==10&&(t=0),e[t++]=n,e[t++]=r)}var cM=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t=n){(a||=[]).push({type:`overlong_rowspan`,pos:c,n:f-e});break}let l=i+e*t;for(let e=0;er&&(a+=i.attrs.colspan)}}for(let e=0;e1&&(n=!0)}t==-1?t=a:t!=a&&(t=Math.max(t,a))}return t}function dM(e,t,n){e.problems||=[];let r={};for(let i=0;i0;t--)if(e.node(t).type.spec.tableRole==`row`)return e.node(0).resolve(e.before(t+1));return null}function gM(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if(n===`cell`||n===`header_cell`)return e.node(t)}return null}function _M(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type.spec.tableRole==`row`)return!0;return!1}function vM(e){let t=e.selection;if(`$anchorCell`in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if(`node`in t&&t.node&&t.node.type.spec.tableRole==`cell`)return t.$anchor;let n=hM(t.$head)||yM(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function yM(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if(r==`cell`||r==`header_cell`)return e.doc.resolve(n-t.nodeSize)}}function bM(e){return e.parent.type.spec.tableRole==`row`&&!!e.nodeAfter}function xM(e){return e.node(0).resolve(e.pos+e.nodeAfter.nodeSize)}function SM(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function CM(e,t,n){let r=e.node(-1),i=cM.get(r),a=e.start(-1),o=i.nextCell(e.pos-a,t,n);return o==null?null:e.node(0).resolve(a+o)}function wM(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function TM(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;ee!=t.pos-i);s.unshift(t.pos-i);let c=s.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new Sn(o.resolve(r),o.resolve(r+t.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(bM(r)&&bM(i)&&SM(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return T.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=cM.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},a=[];for(let n=r.top;n0||u>0){let e=c.attrs;if(l>0&&(e=wM(e,0,l)),u>0&&(e=wM(e,e.colspan-u,u)),s.leftr.bottom){let e={...c.attrs,rowspan:Math.min(s.bottom,r.bottom)-Math.max(s.top,r.top)};c=s.top0)return!1;let n=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(n,r)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=cM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.top<=s.top?(o.top>0&&(t=c.resolve(a+i.map[o.left])),s.bottom0&&(n=c.resolve(a+i.map[s.left])),o.bottom0)return!1;let a=r+this.$anchorCell.nodeAfter.attrs.colspan,o=i+this.$headCell.nodeAfter.attrs.colspan;return Math.max(a,o)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=cM.get(r),a=t.start(-1),o=i.findCell(t.pos-a),s=i.findCell(n.pos-a),c=t.node(0);return o.left<=s.left?(o.left>0&&(t=c.resolve(a+i.map[o.top*i.width])),s.right0&&(n=c.resolve(a+i.map[s.top*i.width])),o.right{t.push(_s.node(n,n+e.nodeSize,{class:`selectedCell`}))}),bs.create(e.doc,t)}function AM({$from:e,$to:t}){if(e.pos==t.pos||e.pos=0&&!(e.after(i+1)=0&&!(t.before(e+1)>t.start(e));e--,r--);return n==r&&/row|table/.test(e.node(i).type.spec.tableRole)}function jM({$from:e,$to:t}){let n,r;for(let t=e.depth;t>0;t--){let r=e.node(t);if(r.type.spec.tableRole===`cell`||r.type.spec.tableRole===`header_cell`){n=r;break}}for(let e=t.depth;e>0;e--){let n=t.node(e);if(n.type.spec.tableRole===`cell`||n.type.spec.tableRole===`header_cell`){r=n;break}}return n!==r&&t.parentOffset===0}function MM(e,t,n){let r=(t||e).selection,i=(t||e).doc,a,o;if(r instanceof E&&(o=r.node.type.spec.tableRole)){if(o==`cell`||o==`header_cell`)a=DM.create(i,r.from);else if(o==`row`){let e=i.resolve(r.from+1);a=DM.rowSelection(e,e)}else if(!n){let e=cM.get(r.node),t=r.from+1,n=t+e.map[e.width*e.height-1];a=DM.create(i,t+1,n)}}else r instanceof T&&AM(r)?a=T.create(i,r.from):r instanceof T&&jM(r)&&(a=T.create(i,r.$from.start(),r.$from.end()));return a&&(t||=e.tr).setSelection(a),t}var NM=new O(`fix-tables`);function PM(e,t,n,r){let i=e.childCount,a=t.childCount;outer:for(let o=0,s=0;o{t.type.spec.tableRole==`table`&&(n=IM(e,t,r,n))};return t?t.doc!=e.doc&&PM(t.doc,e.doc,0,r):e.doc.descendants(r),n}function IM(e,t,n,r){let i=cM.get(t);if(!i.problems)return r;r||=e.tr;let a=[];for(let e=0;e0){let t=`cell`;n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n0?-1:0;EM(t,r,i+a)&&(a=i==0||i==t.width?null:0);for(let o=0;o0&&i0&&t.map[s-1]==c||i0?-1:0;UM(t,r,i+s)&&(s=i==0||i==t.height?null:0);for(let a=0,c=t.width*i;a0&&i0&&l==t.map[o-t.width]){let t=n.nodeAt(l).attrs;e.setNodeMarkup(e.mapping.slice(s).map(l+r),null,{...t,rowspan:t.rowspan-1}),a+=t.colspan-1}else if(i0&&n[a]==n[a-1]||r.right0&&n[i]==n[i-e]||r.bottom0){let e=c+1+l.content.size,t=YM(l)?c+1:e;n.replaceWith(t+r.tableStart,e+r.tableStart,o)}n.setSelection(new DM(n.doc.resolve(c+r.tableStart))),t(n)}return!0}function QM(e,t){let n=pM(e.schema);return $M(({node:e})=>n[e.type.spec.tableRole])(e,t)}function $M(e){return(t,n)=>{let r=t.selection,i,a;if(r instanceof DM){if(r.$anchorCell.pos!=r.$headCell.pos)return!1;i=r.$anchorCell.nodeAfter,a=r.$anchorCell.pos}else{if(i=gM(r.$from),!i)return!1;a=hM(r.$from)?.pos}if(i==null||a==null||i.attrs.colspan==1&&i.attrs.rowspan==1)return!1;if(n){let o=i.attrs,s=[],c=o.colwidth;o.rowspan>1&&(o={...o,rowspan:1}),o.colspan>1&&(o={...o,colspan:1});let l=LM(t),u=t.tr;for(let e=0;e{n.attrs[e]!==t&&a.setNodeMarkup(r,null,{...n.attrs,[e]:t})}):a.setNodeMarkup(i.pos,null,{...i.nodeAfter.attrs,[e]:t}),r(a)}return!0}}function tN(e){return function(t,n){if(!_M(t))return!1;if(n){let r=pM(t.schema),i=LM(t),a=t.tr,o=i.map.cellsInRect(e==`column`?{left:i.left,top:0,right:i.right,bottom:i.map.height}:e==`row`?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),s=o.map(e=>i.table.nodeAt(e));for(let e=0;e{let t=e+i.tableStart,n=a.doc.nodeAt(t);n&&a.setNodeMarkup(t,u,n.attrs)}),n(a)}return!0}}rN(`row`,{useDeprecatedLogic:!0}),rN(`column`,{useDeprecatedLogic:!0});var iN=rN(`cell`,{useDeprecatedLogic:!0});function aN(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()0;r--)if(n.node(r).type.spec.tableRole==`table`)return t&&t(e.tr.delete(n.before(r),n.after(r)).scrollIntoView()),!0;return!1}function cN(e,t){let n=e.selection;if(!(n instanceof DM))return!1;if(t){let r=e.tr,i=pM(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new p(i,0,0))}),r.docChanged&&t(r)}return!0}function lN(e){if(e.size===0)return null;let{content:t,openStart:n,openEnd:r}=e;for(;t.childCount==1&&(n>0&&r>0||t.child(0).type.spec.tableRole==`table`);)n--,r--,t=t.child(0).content;let i=t.child(0),a=i.type.spec.tableRole,o=i.type.schema,s=[];if(a==`row`)for(let e=0;e=0;t--){let{rowspan:i,colspan:a}=r.child(t).attrs;for(let t=e;t=t.length&&t.push(s.empty),n[i]r&&(s=s.type.createChecked(wM(s.attrs,s.attrs.colspan,n+s.attrs.colspan-r),s.content)),o.push(s),n+=s.attrs.colspan;for(let n=1;ni&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(s.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}function pN(e,t,n,r,i,a,o){let c=e.doc.type.schema,l=pM(c),u,d;if(i>t.width)for(let a=0,s=0;at.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e=t.width?!1:n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?d||=l.header_cell.createAndFill():u||=l.cell.createAndFill())}let f=l.row.create(null,s.from(c)),p=[];for(let e=t.height;e{if(!i)return!1;let a=n.selection;if(a instanceof DM)return vN(n,r,w.near(a.$headCell,t));if(e!=`horiz`&&!a.empty)return!1;let o=wN(i,e,t);if(o==null)return!1;if(e==`horiz`)return vN(n,r,w.near(n.doc.resolve(a.head+t),t));{let i=n.doc.resolve(o),a=CM(i,e,t),s;return s=a?w.near(a,1):t<0?w.near(n.doc.resolve(i.before(-1)),-1):w.near(n.doc.resolve(i.after(-1)),1),vN(n,r,s)}}}function bN(e,t){return(n,r,i)=>{if(!i)return!1;let a=n.selection,o;if(a instanceof DM)o=a;else{let r=wN(i,e,t);if(r==null)return!1;o=new DM(n.doc.resolve(r))}let s=CM(o.$headCell,e,t);return s?vN(n,r,new DM(o.$anchorCell,s)):!1}}function xN(e,t){let n=e.state.doc,r=hM(n.resolve(t));return r?(e.dispatch(e.state.tr.setSelection(new DM(r))),!0):!1}function SN(e,t,n){if(!_M(e.state))return!1;let r=lN(n),i=e.state.selection;if(i instanceof DM){r||={width:1,height:1,rows:[s.from(dN(pM(e.state.schema).cell,n))]};let t=i.$anchorCell.node(-1),a=i.$anchorCell.start(-1),o=cM.get(t).rectBetween(i.$anchorCell.pos-a,i.$headCell.pos-a);return r=fN(r,o.right-o.left,o.bottom-o.top),gN(e.state,e.dispatch,a,o,r),!0}if(r){let t=vM(e.state),n=t.start(-1);return gN(e.state,e.dispatch,n,cM.get(t.node(-1)).findCell(t.pos-n),r),!0}return!1}function CN(e,t){if(t.button!=0||t.ctrlKey||t.metaKey)return;let n=TN(e,t.target),r;if(t.shiftKey&&e.state.selection instanceof DM)i(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&n&&(r=hM(e.state.selection.$anchor))!=null&&EN(e,t)?.pos!=r.pos)i(r,t),t.preventDefault();else if(!n)return;function i(t,n){let r=EN(e,n),i=mM.getState(e.state)==null;if(!r||!SM(t,r)){if(i)r=t;else return}let a=new DM(t,r);if(i||!e.state.selection.eq(a)){let n=e.state.tr.setSelection(a);i&&n.setMeta(mM,t.pos),e.dispatch(n)}}function a(){e.root.removeEventListener(`mouseup`,a),e.root.removeEventListener(`dragstart`,a),e.root.removeEventListener(`mousemove`,o),mM.getState(e.state)!=null&&e.dispatch(e.state.tr.setMeta(mM,-1))}function o(r){let o=r,s=mM.getState(e.state),c;if(s!=null)c=e.state.doc.resolve(s);else if(TN(e,o.target)!=n&&(c=EN(e,t),!c))return a();c&&i(c,o)}e.root.addEventListener(`mouseup`,a),e.root.addEventListener(`dragstart`,a),e.root.addEventListener(`mousemove`,o)}function wN(e,t,n){if(!(e.state.selection instanceof T))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let a=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:a.childCount))return null;if(a.type.spec.tableRole==`cell`||a.type.spec.tableRole==`header_cell`){let a=r.before(i),o=t==`vert`?n>0?`down`:`up`:n>0?`right`:`left`;return e.endOfTextblock(o)?a:null}}return null}function TN(e,t){for(;t&&t!=e.dom;t=t.parentNode)if(t.nodeName==`TD`||t.nodeName==`TH`)return t;return null}function EN(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&hM(e.state.doc.resolve(r))||hM(e.state.doc.resolve(i))}var DN=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement(`div`),this.dom.className=`tableWrapper`,this.table=this.dom.appendChild(document.createElement(`table`)),this.table.style.setProperty(`--default-cell-min-width`,`${t}px`),this.colgroup=this.table.appendChild(document.createElement(`colgroup`)),ON(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement(`tbody`))}update(e){return e.type==this.node.type&&(this.node=e,ON(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type==`attributes`&&(e.target==this.table||this.colgroup.contains(e.target))}};function ON(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l){for(let e=0,n=0;enew r(e,n,t)),new jN(-1,!1)},apply(e,t){return t.apply(e)}},props:{attributes:e=>{let t=kN.getState(e);return t&&t.activeHandle>-1?{class:`resize-cursor`}:{}},handleDOMEvents:{mousemove:(t,n)=>{MN(t,n,e,i)},mouseleave:e=>{NN(e)},mousedown:(e,r)=>{PN(e,r,t,n)}},decorations:e=>{let t=kN.getState(e);if(t&&t.activeHandle>-1)return UN(e,t.activeHandle)},nodeViews:{}}});return a}var jN=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=this,r=t.getMeta(kN);if(r&&r.setHandle!=null)return new e(r.setHandle,!1);if(r&&r.setDragging!==void 0)return new e(n.activeHandle,r.setDragging);if(n.activeHandle>-1&&t.docChanged){let r=t.mapping.map(n.activeHandle,-1);return bM(t.doc.resolve(r))||(r=-1),new e(r,n.dragging)}return n}};function MN(e,t,n,r){if(!e.editable)return;let i=kN.getState(e.state);if(i&&!i.dragging){let a=IN(t.target),o=-1;if(a){let{left:r,right:i}=a.getBoundingClientRect();t.clientX-r<=n?o=LN(e,t,`left`,n):i-t.clientX<=n&&(o=LN(e,t,`right`,n))}if(o!=i.activeHandle){if(!r&&o!==-1){let t=e.state.doc.resolve(o),n=t.node(-1),r=cM.get(n),i=t.start(-1);if(r.colCount(t.pos-i)+t.nodeAfter.attrs.colspan-1==r.width-1)return}zN(e,o)}}}function NN(e){if(!e.editable)return;let t=kN.getState(e.state);t&&t.activeHandle>-1&&!t.dragging&&zN(e,-1)}function PN(e,t,n,r){if(!e.editable)return!1;let i=e.dom.ownerDocument.defaultView??window,a=kN.getState(e.state);if(!a||a.activeHandle==-1||a.dragging)return!1;let o=e.state.doc.nodeAt(a.activeHandle),s=FN(e,a.activeHandle,o.attrs);e.dispatch(e.state.tr.setMeta(kN,{setDragging:{startX:t.clientX,startWidth:s}}));function c(t){i.removeEventListener(`mouseup`,c),i.removeEventListener(`mousemove`,l);let r=kN.getState(e.state);r?.dragging&&(BN(e,r.activeHandle,RN(r.dragging,t,n)),e.dispatch(e.state.tr.setMeta(kN,{setDragging:null})))}function l(t){if(!t.which)return c(t);let i=kN.getState(e.state);if(i&&i.dragging){let a=RN(i.dragging,t,n);VN(e,i.activeHandle,a,r)}}return VN(e,a.activeHandle,s,r),i.addEventListener(`mouseup`,c),i.addEventListener(`mousemove`,l),t.preventDefault(),!0}function FN(e,t,{colspan:n,colwidth:r}){let i=r&&r[r.length-1];if(i)return i;let a=e.domAtPos(t),o=a.node.childNodes[a.offset].offsetWidth,s=n;if(r)for(let e=0;eKN(e),renderHTML:e=>{let t=GN(e.align);return Nf(t)?{style:`text-align: ${t}`}:{}}}}function YN(e){let t=e.parentElement,n=e.closest(`table`);if(!t||!n)return null;let r=Array.from(t.children).indexOf(e),i=n.querySelectorAll(`colgroup > col`)[r]?.getAttribute(`width`);return i?[parseInt(i,10)]:null}function XN(e){let t=e.getAttribute(`colwidth`);return t?t.split(`,`).map(e=>parseInt(e,10)):YN(e)}var ZN=/[ \t\r\n\f]+/g;function QN(e){return e.children.length>0?!1:(e.textContent??``).replace(ZN,``)===``}function $N(e){let t=e.createAndFill();if(!t)throw Error(`[tiptap error]: "${e.name}" has no default content to backfill.`);return t.content}function eP(e,t,n){if(!(n in t))return;let r=t[n];(r===1||r===`1`||r==null)&&delete e[n]}var tP=qp.create({name:`tableCell`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:XN},align:JN()}},tableRole:`cell`,isolating:!0,parseHTML(){return[{tag:`td`,getAttrs:e=>QN(e)?{}:!1,getContent:(e,t)=>$N(t.nodes[this.name])},{tag:`td`}]},renderHTML({HTMLAttributes:e}){let t=j(this.options.HTMLAttributes,e);return eP(t,e,`colspan`),eP(t,e,`rowspan`),[`td`,t,0]}}),nP=qp.create({name:`tableHeader`,addOptions(){return{HTMLAttributes:{}}},content:`block+`,addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:XN},align:JN()}},tableRole:`header_cell`,isolating:!0,parseHTML(){return[{tag:`th`,getAttrs:e=>QN(e)?{}:!1,getContent:(e,t)=>$N(t.nodes[this.name])},{tag:`th`}]},renderHTML({HTMLAttributes:e}){let t=j(this.options.HTMLAttributes,e);return eP(t,e,`colspan`),eP(t,e,`rowspan`),[`th`,t,0]}}),rP=qp.create({name:`tableRow`,addOptions(){return{HTMLAttributes:{}}},content:`(tableCell | tableHeader)*`,tableRole:`row`,parseHTML(){return[{tag:`tr`}]},renderHTML({HTMLAttributes:e}){return[`tr`,j(this.options.HTMLAttributes,e),0]}});function iP(e,t){return t?[`width`,`${Math.max(t,e)}px`]:[`min-width`,`${e}px`]}function aP(e,t,n,r,i,a){let o=0,s=!0,c=t.firstChild,l=e.firstChild;if(l!==null)for(let e=0,n=0;e{let r=e.nodes[n];r.spec.tableRole&&(t[r.spec.tableRole]=r)}),e.cached.tableNodeTypes=t,t}function uP(e,t,n,r,i){let a=lP(e),o=[],s=[];for(let e=0;e{let{selection:t}=e.state;if(!dP(t))return!1;let n=0;return _u(t.ranges[0].$from,e=>e.type.name===`table`)?.node.descendants(e=>{if(e.type.name===`table`)return!1;[`tableCell`,`tableHeader`].includes(e.type.name)&&(n+=1)}),n===t.ranges.length&&(e.commands.deleteTable(),!0)};function pP(e,t){let n=e.mapping.map(t);if(_u(e.selection.$from,e=>e.type.name===`table`)?.pos===n)return;let r=e.doc.nodeAt(n);if(!r)return;let i=n+r.nodeSize-1;e.setSelection(T.near(e.doc.resolve(i),-1))}function mP(e){let t=``,n=0;for(;ne===`|`?`\\|`:e)+e.slice(i,i+r),n=i+r,a=!0;break}i+=o}a||(t+=e.slice(n,n+r),n+=r)}return t}function hP(e){return e.split(` +`).map(e=>!e.includes(`|`)||!e.includes("`")?e:mP(e)).join(` +`)}function gP(e){return(e||``).replaceAll(``,` `).replace(/\s+/g,` `).trim()}function _P(e,t){return t?e.split(t).join(` +`):e}function vP(e){return e.replace(/\\.|\|/g,e=>e===`|`?`\\|`:e)}function yP(e,t,n={}){if(!e||!e.content||e.content.length===0)return``;let r=[];e.content.forEach(e=>{let i=[];e.content&&e.content.forEach(e=>{let r=``;r=e.content&&Array.isArray(e.content)&&e.content.length>1?e.content.map(e=>_P(t.renderChildren(e),n.cellLineSeparator)).join(` +`):_P(e.content?t.renderChildren(e.content):``,n.cellLineSeparator);let a=vP(gP(r.replace(/[ \t]*\r?\n[ \t]*/g,`
`))),o=e.type===`tableHeader`,s=qN(e.attrs);i.push({text:a,isHeader:o,align:s})}),r.push(i)});let i=r.reduce((e,t)=>Math.max(e,t.length),0);if(i===0)return``;let a=Array.from({length:i}).fill(0);r.forEach(e=>{for(let t=0;ta[t]&&(a[t]=n),a[t]<3&&(a[t]=3)}});let o=(e,t)=>e+` `.repeat(Math.max(0,t-e.length)),s=r[0],c=s.some(e=>e.isHeader),l=Array.from({length:i}).fill(null);r.forEach(e=>{for(let t=0;tc&&s[t]&&s[t].text||``);return u+=`| ${d.map((e,t)=>o(e,a[t])).join(` | `)} |\n`,u+=`| ${a.map((e,t)=>{let n=Math.max(3,e),r=l[t];return r===`left`?`:${`-`.repeat(n)}`:r===`right`?`${`-`.repeat(n)}:`:r===`center`?`:${`-`.repeat(n)}:`:`-`.repeat(n)}).join(` | `)} |\n`,(c?r.slice(1):r).forEach(e=>{u+=`| ${Array.from({length:i}).fill(0).map((t,n)=>o(e[n]&&e[n].text||``,a[n])).join(` | `)} |\n`}),u}var bP=new O(`preserveCellSelectionOnContextMenu`);function xP(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(n)return n.pos;if(!(t.target instanceof Node))return null;try{return e.posAtDOM(t.target,0)}catch{return null}}function SP(e,t){let n=!1;return e.forEachCell((e,r)=>{t>=r&&t{let n=[],r=Array.isArray(e.align)?e.align:[];if(e.header){let i=[];e.header.forEach((e,n)=>{let a=GN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableHeader`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}return e.rows&&e.rows.forEach(e=>{let i=[];e.forEach((e,n)=>{let a=GN(r[n]??e.align),o=a?{align:a}:{};i.push(t.createNode(`tableCell`,o,[{type:`paragraph`,content:t.parseInline(e.tokens)}]))}),n.push(t.createNode(`tableRow`,{},i))}),t.createNode(`table`,void 0,n)},renderMarkdown:(e,t)=>yP(e,t),markdownTokenizer:{name:`table`,level:`block`,start:e=>{let t=e.split(` `);if(t.length<2)return-1;let n=t[1];return!/^[ \t|:]*-[ \t|:-]*$/.test(n)||!n.includes(`|`)?-1:t[0].includes(`|`)?0:-1},tokenize(e,t,n){let r=e.indexOf(` `),i=r>=0?e.slice(0,r):e,a=i.split(` -`);if(a.length<2)return;let o=a[1];if(!/^[ \t|:]*-[ \t|:-]*$/.test(o)||!o.includes(`|`))return;let s=gP(i);if(s===i)return;let c=n.blockTokens(s)[0];if(c?.type!==`table`||!c.raw)return;let l=c.raw.split(` +`);if(a.length<2)return;let o=a[1];if(!/^[ \t|:]*-[ \t|:-]*$/.test(o)||!o.includes(`|`))return;let s=hP(i);if(s===i)return;let c=n.blockTokens(s)[0];if(c?.type!==`table`||!c.raw)return;let l=c.raw.split(` `).length,u=e.split(` `).slice(0,l).join(` -`);return{...c,raw:u}}},addCommands(){return{insertTable:({rows:e=3,cols:t=3,withHeaderRow:n=!0}={})=>({tr:r,dispatch:i,editor:a})=>{let o=dP(a.schema,e,t,n);if(i){let e=r.selection.from+1;r.replaceSelectionWith(o).scrollIntoView().setSelection(T.near(r.doc.resolve(e)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>BM(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>VM(e,t),deleteColumn:()=>({state:e,dispatch:t})=>{let n=vu(e.selection.$from,e=>e.type.name===`table`);return UM(e,t&&(e=>{n&&mP(e,n.pos),t(e)}))},addRowBefore:()=>({state:e,dispatch:t})=>KM(e,t),addRowAfter:()=>({state:e,dispatch:t})=>qM(e,t),deleteRow:()=>({state:e,dispatch:t})=>{let n=vu(e.selection.$from,e=>e.type.name===`table`);return YM(e,t&&(e=>{n&&mP(e,n.pos),t(e)}))},deleteTable:()=>({state:e,dispatch:t})=>cN(e,t),mergeCells:()=>({state:e,dispatch:t})=>QM(e,t),splitCell:()=>({state:e,dispatch:t})=>$M(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>iN(`column`)(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>iN(`row`)(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>aN(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>QM(e,t)?!0:$M(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>tN(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>sN(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>sN(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&IM(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let n=OM.create(t.doc,e.anchorCell,e.headCell);t.setSelection(n)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:pP,"Mod-Backspace":pP,Delete:pP,"Mod-Delete":pP}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[jN({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:null,lastColumnResizable:this.options.lastColumnResizable})]:[],GN({allowTableNodeSelection:this.options.allowTableNodeSelection}),wP()]},addNodeView(){let e=this.options.View;return e?({node:t,view:n,HTMLAttributes:r})=>{let i=A(this.options.HTMLAttributes,r);return new e(t,this.options.cellMinWidth,n,i)}:null},extendNodeSchema(e){return{tableRole:Nu(k(e,`tableRole`,{name:e.name,options:e.options,storage:e.storage}))}}}),EP=Tp.create({name:`tableKit`,addExtensions(){let e=[];return this.options.table!==!1&&e.push(TP.configure(this.options.table)),this.options.tableCell!==!1&&e.push(nP.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(rP.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(iP.configure(this.options.tableRow)),e}}),DP=Tp.create({name:`textAlign`,addOptions(){return{types:[],alignments:[`left`,`center`,`right`,`justify`],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>!Pf(e.textAlign)||!this.options.alignments.includes(e.textAlign)?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(e=>e):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,`textAlign`)).some(e=>e),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign(`left`),"Mod-Shift-e":()=>this.editor.commands.setTextAlign(`center`),"Mod-Shift-r":()=>this.editor.commands.setTextAlign(`right`),"Mod-Shift-j":()=>this.editor.commands.setTextAlign(`justify`)}}});function OP(){return[Bk.configure({HTMLAttributes:{class:`dw-tasks`}}),zk.configure({nested:!0})]}function kP(){return[EP.configure({table:{resizable:!0,cellMinWidth:60,HTMLAttributes:{class:`dw-table`}}})]}var AP=DP.configure({types:[`heading`,`paragraph`],alignments:[`left`,`center`,`right`]}),jP=Tp.create({name:`headingShortcuts`,addKeyboardShortcuts(){let e={"Mod-Shift-0":()=>this.editor.commands.setParagraph()};for(let t of[1,2,3,4,5,6])e[`Mod-Shift-${t}`]=()=>this.editor.commands.toggleHeading({level:t});return e}}),MP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,NP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,PP=_p.create({name:`highlight`,addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute(`data-color`)||Af(e,`background-color`)||e.style.backgroundColor,renderHTML:e=>Pf(e.color)?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:`mark`}]},renderHTML({HTMLAttributes:e}){return[`mark`,A(this.options.HTMLAttributes,e),0]},renderMarkdown:(e,t)=>`==${t.renderChildren(e)}==`,parseMarkdown:(e,t)=>t.applyMark(`highlight`,t.parseInline(e.tokens||[])),markdownTokenizer:{name:`highlight`,level:`inline`,start:e=>e.indexOf(`==`),tokenize(e,t,n){let r=/^(==)(?!\s)([^=]*[^=\s])(==)/.exec(e);if(r){let e=r[2].trim(),t=n.inlineTokens(e);return{type:`highlight`,raw:r[0],text:e,tokens:t}}}},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[Hp({find:MP,type:this.type})]},addPasteRules(){return[Yp({find:NP,type:this.type})]}}),FP=[`gray`,`red`,`orange`,`yellow`,`green`,`teal`,`blue`,`purple`,`pink`],IP=e=>typeof e==`string`&&FP.includes(e),LP=_p.create({name:`textColor`,addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return IP(t)?t:null},renderHTML:e=>e.color?{"data-color":e.color}:{}}}},parseHTML(){return[{tag:`span[data-color]`,getAttrs:e=>IP(e.getAttribute(`data-color`))?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`span`,A(e,{class:`dw-text-color`}),0]},addCommands(){return{setTextColor:e=>({commands:t})=>t.setMark(this.name,{color:e}),unsetTextColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),RP=PP.extend({addOptions(){return{...this.parent(),multicolor:!0}},addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return IP(t)?t:null},renderHTML:e=>({"data-color":IP(e.color)?e.color:`yellow`})}}},renderHTML({HTMLAttributes:e}){return[`mark`,A(e,{class:`dw-highlight`}),0]}}),zP=`💡`;function BP(e){let t=e.trim();return t&&[...t].length<=4?t:``}var VP=Jp.create({name:`callout`,group:`block`,content:`block+`,defining:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{emoji:{default:zP,parseHTML:e=>BP(e.getAttribute(`data-emoji`)??``)||zP,renderHTML:e=>({"data-emoji":e.emoji})},color:{default:`blue`,parseHTML:e=>{let t=e.getAttribute(`data-color`);return IP(t)?t:`blue`},renderHTML:e=>({"data-color":e.color})}}},parseHTML(){return[{tag:`aside[data-type=callout]`,contentElement:e=>e.querySelector(`:scope > .callout-body`)??e}]},renderHTML({HTMLAttributes:e}){return[`aside`,A(e,{"data-type":`callout`,class:`dw-callout`}),0]},addCommands(){return{setCallout:e=>({commands:t})=>t.wrapIn(this.name,e),unsetCallout:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{Backspace:({editor:e})=>{let{$from:t,empty:n}=e.state.selection;if(!n||t.parentOffset>0)return!1;for(let n=t.depth-1;n>0;n--){if(t.node(n).type.name===this.name)return t.index(n)!==0||t.start(n+1)!==t.start()?!1:e.commands.lift(this.name);if(t.index(n)!==0)return!1}return!1}}},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=document.createElement(`aside`);i.className=`dw-callout`,i.setAttribute(`data-type`,`callout`);let a=document.createElement(`div`);a.className=`dw-callout__side`,a.contentEditable=`false`;let o=document.createElement(`button`);o.type=`button`,o.className=`dw-callout__emoji`;let s=document.createElement(`button`);s.type=`button`,s.className=`dw-callout__color`,a.append(o,s);let c=document.createElement(`div`);c.className=`dw-callout__body`,i.append(a,c);let l=e,u=e=>{let r=t();typeof r==`number`&&n.isEditable&&n.view.dispatch(n.state.tr.setNodeMarkup(r,void 0,{...l.attrs,...e}))};o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>{if(!n.isEditable)return;let e=BP(window.prompt(r?.blocks.calloutEmoji??`Emoji`,l.attrs.emoji)??``);e&&u({emoji:e})}),s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`click`,()=>{let e=FP.indexOf(l.attrs.color);u({color:FP[(e+1)%FP.length]})});let d=()=>{i.setAttribute(`data-color`,String(l.attrs.color)),o.textContent=String(l.attrs.emoji);let e=r?.blocks.calloutEmoji??`Emoji`;o.setAttribute(`aria-label`,e),o.title=e;let t=r?.blocks.calloutColor??`Colour`;s.setAttribute(`aria-label`,t),s.title=t};return d(),{dom:i,contentDOM:c,update:t=>t.type===e.type&&(l=t,d(),!0),stopEvent:e=>a.contains(e.target),ignoreMutation:e=>a.contains(e.target)}}}}),HP=10;function UP(e){let t=typeof e==`string`?parseFloat(e):typeof e==`number`?e:NaN;return Number.isFinite(t)&&t>0&&t<=100?Math.round(t*10)/10:null}function WP(e){let t=[];e.forEach(e=>t.push(UP(e.attrs.width)));let n=t.reduce((e,t)=>e+(t??0),0),r=t.filter(e=>e===null).length,i=r?Math.max(100-n,r*HP)/r:0,a=t.map(e=>e??i),o=a.reduce((e,t)=>e+t,0)||1;return a.map(e=>e*100/o)}function GP(e){let{$from:t}=e.state.selection;for(let e=t.depth;e>0;e--)if(t.node(e).type.name===`columns`)return e;return-1}function KP(e,t=null){let{schema:n}=e.state;return n.nodes.column.create({width:t},n.nodes.paragraph.create())}function qP(e){return e.childCount===1&&e.firstChild.type.name===`paragraph`&&e.firstChild.content.size===0}var JP=Jp.create({name:`columns`,group:`block`,content:`column{2,4}`,defining:!0,isolating:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`div[data-type=columns]`}]},renderHTML({HTMLAttributes:e}){return[`div`,A(e,{"data-type":`columns`,class:`dw-columns`}),0]},addCommands(){return{insertColumns:(e=2)=>({editor:t,tr:n,dispatch:r})=>{let i=Math.min(Math.max(Math.round(e),2),4),a=t.schema.nodes.columns.create(null,Array.from({length:i},()=>KP(t)));if(!r)return!0;let o=n.selection.from;n.replaceSelectionWith(a);let s=-1;return n.doc.nodesBetween(o,Math.min(o+a.nodeSize+2,n.doc.content.size),(e,t)=>(s<0&&e.type.name===`columns`&&(s=t),s<0)),s>=0&&n.setSelection(T.create(n.doc,s+3)),n.scrollIntoView(),!0},addColumn:()=>({editor:e,tr:t,dispatch:n})=>{let r=GP(e);if(r<0)return!1;let{$from:i}=t.selection,a=i.node(r);if(a.childCount>=4)return!1;if(!n)return!0;let o=i.index(r),s=i.before(r),c=WP(a),l=100/(a.childCount+1),u=(100-l)/100,d=s+1;a.forEach((e,n,r)=>{t.setNodeMarkup(t.mapping.map(d),void 0,{...e.attrs,width:c[r]*u}),d+=e.nodeSize});let f=s+1;for(let e=0;e<=o;e++)f+=a.child(e).nodeSize;let p=t.mapping.map(f);return t.insert(p,KP(e,l)),t.setSelection(T.create(t.doc,p+2)),!0},unsetColumns:()=>({editor:e,tr:t,dispatch:n})=>{let r=GP(e);if(r<0)return!1;if(!n)return!0;let{$from:i}=t.selection,a=i.node(r),o=[];a.forEach(e=>{qP(e)||e.forEach(e=>o.push(e))}),o.length||o.push(e.schema.nodes.paragraph.create());let c=i.before(r);return t.replaceWith(c,c+a.nodeSize,s.from(o)),t.setSelection(T.near(t.doc.resolve(c+1))),!0}}},addKeyboardShortcuts(){return{Backspace:({editor:e})=>{let{$from:t,empty:n}=e.state.selection;if(!n||t.parentOffset>0)return!1;let r=GP(e);if(r<0||t.depth!==r+2)return!1;let i=t.node(r),a=t.node(r+1);if(!qP(a))return!1;if(i.childCount<=2)return e.commands.unsetColumns();let o=t.index(r),s=t.before(r+1),c=e.state.tr.delete(s,s+a.nodeSize),l=t.before(r),u=c.doc.nodeAt(l),d=WP(u),f=l+1;u.forEach((e,t,n)=>{c.setNodeMarkup(f,void 0,{...e.attrs,width:d[n]}),f+=e.nodeSize});let p=Math.max(o-1,0),m=l+1;for(let e=0;e<=p;e++)m+=c.doc.nodeAt(l).child(e).nodeSize;return c.setSelection(T.near(c.doc.resolve(m-1),-1)),e.view.dispatch(c.scrollIntoView()),!0},"Mod-Alt-ArrowRight":({editor:e})=>e.commands.addColumn()}}}),YP=Jp.create({name:`column`,content:`block+`,isolating:!0,addOptions(){return{labels:null}},addAttributes(){return{width:{default:null,parseHTML:e=>UP(e.getAttribute(`data-width`)),renderHTML:e=>e.width==null?{}:{"data-width":String(UP(e.width))}}}},parseHTML(){return[{tag:`div[data-type=column]`}]},renderHTML({HTMLAttributes:e}){return[`div`,A(e,{"data-type":`column`,class:`dw-column`}),0]},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=document.createElement(`div`);i.className=`dw-column`,i.setAttribute(`data-type`,`column`);let a=document.createElement(`div`);a.className=`dw-column__body`;let o=document.createElement(`div`);o.className=`dw-column__resize`,o.contentEditable=`false`,o.setAttribute(`role`,`separator`),o.setAttribute(`aria-orientation`,`vertical`);let s=document.createElement(`button`);s.type=`button`,s.className=`dw-column__add`,s.contentEditable=`false`,s.textContent=`+`,i.append(a,o,s);let c=()=>{let e=t();if(typeof e!=`number`)return null;let r=n.state.doc.resolve(e),i=r.parent;return i.type.name===`columns`?{row:i,index:r.index(),rowPos:r.before()}:null},l=()=>{let e=c(),t=e?WP(e.row):[100],n=e?t[e.index]:100;i.style.flexGrow=String(n);let a=!e||e.index===e.row.childCount-1;o.hidden=a,s.hidden=!e||e.row.childCount>=4;let l=r?.blocks.resizeColumn??`Drag to resize`;o.title=l,o.setAttribute(`aria-label`,l);let u=r?.blocks.addColumn??`Add a column`;s.title=u,s.setAttribute(`aria-label`,u)};return l(),s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`click`,()=>{let e=t();typeof e==`number`&&n.isEditable&&n.chain().setTextSelection(e+2).addColumn().focus().run()}),o.addEventListener(`pointerdown`,e=>{let t=c();if(!t||!n.isEditable||t.index>=t.row.childCount-1)return;e.preventDefault();let r=i.parentElement,a=i.nextElementSibling;if(!r||!a)return;let s=r.getBoundingClientRect().width||1,u=WP(t.row),d=u[t.index]+u[t.index+1],f=e.clientX,p=u[t.index],m=p;o.setPointerCapture(e.pointerId),i.classList.add(`is-resizing`);let h=e=>{m=Math.min(Math.max(p+(e.clientX-f)*100/s,HP),d-HP),i.style.flexGrow=String(m),a.style.flexGrow=String(d-m)},g=()=>{o.removeEventListener(`pointermove`,h),o.removeEventListener(`pointerup`,g),o.removeEventListener(`pointercancel`,g),i.classList.remove(`is-resizing`);let e=c();if(!e||Math.abs(m-p)<.5)return l();let t=WP(e.row);t[e.index]=m,t[e.index+1]=d-m;let r=n.state.tr,a=e.rowPos+1;e.row.forEach((e,n,i)=>{r.setNodeMarkup(a,void 0,{...e.attrs,width:Math.round(t[i]*10)/10}),a+=e.nodeSize}),n.view.dispatch(r)};o.addEventListener(`pointermove`,h),o.addEventListener(`pointerup`,g),o.addEventListener(`pointercancel`,g)}),{dom:i,contentDOM:a,update:t=>t.type===e.type&&(l(),!0),stopEvent:e=>o.contains(e.target)||s.contains(e.target),ignoreMutation:e=>o.contains(e.target)||s.contains(e.target)||e.type===`attributes`&&e.target===i}}}}),XP=e=>[e.x+e.w/2,e.y+e.h/2];function ZP(e){if(!e.length)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.w),i=Math.max(i,a.y+a.h);return{x:t,y:n,w:r-t,h:i-n}}var QP=(e,t)=>({x:e.x-t,y:e.y-t,w:e.w+2*t,h:e.h+2*t}),$P=(e,t)=>e.x<=t.x+t.w&&t.x<=e.x+e.w&&e.y<=t.y+t.h&&t.y<=e.y+e.h,eF=(e,t)=>t.x>=e.x&&t.y>=e.y&&t.x+t.w<=e.x+e.w&&t.y+t.h<=e.y+e.h;function tF(e,t){return{x:Math.min(e[0],t[0]),y:Math.min(e[1],t[1]),w:Math.abs(e[0]-t[0]),h:Math.abs(e[1]-t[1])}}function nF([e,t],[n,r],i){if(!i)return[e,t];let a=i*Math.PI/180,o=Math.cos(a),s=Math.sin(a);return[n+(e-n)*o-(t-r)*s,r+(e-n)*s+(t-r)*o]}function rF(e,t){if(!t)return e;let n=XP(e),r=[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>nF(e,n,t));return tF([Math.min(...r.map(e=>e[0])),Math.min(...r.map(e=>e[1]))],[Math.max(...r.map(e=>e[0])),Math.max(...r.map(e=>e[1]))])}function iF([e,t],[n,r],[i,a]){let o=i-n,s=a-r,c=o*o+s*s,l=c?Math.max(0,Math.min(1,((e-n)*o+(t-r)*s)/c)):0;return Math.hypot(e-(n+l*o),t-(r+l*s))}function aF(e,t){if(t.length===1)return Math.hypot(e[0]-t[0][0],e[1]-t[0][1]);let n=1/0;for(let r=1;re[1]-t[1]),r[0][0]}var sF={left:[-1,0],right:[1,0],top:[0,-1],bottom:[0,1]};function cF(e,t,n=!1){let[r,i]=XP(e),a=t[0]-r,o=t[1]-i;if(!a&&!o)return[r,i];let s=Math.max(e.w/2,.5),c=Math.max(e.h/2,.5),l=n?1/Math.sqrt(a*a/(s*s)+o*o/(c*c)):Math.min(Math.abs(s/(a||1e-9)),Math.abs(c/(o||1e-9)));return[r+a*l,i+o*l]}var lF=e=>[[`top`,[e.x+e.w/2,e.y]],[`right`,[e.x+e.w,e.y+e.h/2]],[`bottom`,[e.x+e.w/2,e.y+e.h]],[`left`,[e.x,e.y+e.h/2]]];function uF(e,t){let n=e=>{if(!e.id)return[e.x??0,e.y??0];let n=t(e.id);return n?e.pos?[n.box.x+n.box.w*e.pos[0],n.box.y+n.box.h*e.pos[1]]:null:[e.x??0,e.y??0]},r=e=>{let n=e.id?t(e.id):null;return n?XP(n.box):[e.x??0,e.y??0]},i=(e,i)=>{let a=n(e),o=e.id?t(e.id):null;if(a)return{at:a,side:o?oF(o.box,a):null};let s=cF(o.box,n(i)??r(i),o.ellipse);return{at:s,side:oF(o.box,s)}};return[i(e.source,e.target),i(e.target,e.source)]}var dF=e=>Math.round(e*100)/100,fF=e=>e.map((e,t)=>`${t?`L`:`M`}${dF(e[0])} ${dF(e[1])}`).join(` `),pF=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);function mF(e,t,n){let[r,i]=t.at,[a,o]=n.at,s=Math.hypot(a-r,o-i);if(e===`straight`||s<1)return{points:[t.at,n.at],d:fF([t.at,n.at]),mid:[(r+a)/2,(i+o)/2],startAngle:pF(n.at,t.at),endAngle:pF(t.at,n.at)};if(e===`curve`){let e=Math.min(s/2,160),c=t.side?sF[t.side]:hF(t.at,n.at),l=n.side?sF[n.side]:hF(n.at,t.at),u=[r+c[0]*e,i+c[1]*e],d=[a+l[0]*e,o+l[1]*e],f=[];for(let e=0;e<=24;e++)f.push(gF(t.at,u,d,n.at,e/24));return{points:f,d:`M${dF(r)} ${dF(i)} C${dF(u[0])} ${dF(u[1])} ${dF(d[0])} ${dF(d[1])} ${dF(a)} ${dF(o)}`,mid:gF(t.at,u,d,n.at,.5),startAngle:pF(u,t.at),endAngle:pF(d,n.at)}}let c=t.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`right`:`left`:o>i?`bottom`:`top`),l=n.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`left`:`right`:o>i?`top`:`bottom`),u=[r+sF[c][0]*24,i+sF[c][1]*24],d=[a+sF[l][0]*24,o+sF[l][1]*24],f=c===`left`||c===`right`,p=l===`left`||l===`right`,m;if(f&&p){let e=(u[0]+d[0])/2;m=[[e,u[1]],[e,d[1]]]}else if(!f&&!p){let e=(u[1]+d[1])/2;m=[[u[0],e],[d[0],e]]}else m=f?[[d[0],u[1]]]:[[u[0],d[1]]];let h=_F([t.at,u,...m,d,n.at]);return{points:h,d:fF(h),mid:vF(h),startAngle:pF(h[1]??n.at,t.at),endAngle:pF(h[h.length-2]??t.at,n.at)}}function hF(e,t){let n=Math.hypot(t[0]-e[0],t[1]-e[1])||1;return[(t[0]-e[0])/n,(t[1]-e[1])/n]}function gF(e,t,n,r,i){let a=1-i,o=a*a*a,s=3*a*a*i,c=3*a*i*i,l=i*i*i;return[o*e[0]+s*t[0]+c*n[0]+l*r[0],o*e[1]+s*t[1]+c*n[1]+l*r[1]]}function _F(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&Math.abs(e[0]-n[0])<.01&&Math.abs(e[1]-n[1])<.01)continue;let r=t[t.length-2];if(r&&e){let i=(e[0]-r[0])*(n[1]-r[1])-(e[1]-r[1])*(n[0]-r[0]);Math.abs(i)<.01&&t.pop()}t.push(n)}return t}function vF(e){let t=0;for(let n=1;n=n&&a>0)return[r[0]+(i[0]-r[0])*n/a,r[1]+(i[1]-r[1])*n/a];n-=a}return e[0]??[0,0]}function yF(e,t,n){let r=e=>[e.x,e.x+e.w/2,e.x+e.w],i=e=>[e.y,e.y+e.h/2,e.y+e.h],a={dx:0,ox:null,vx:0},o={dy:0,oy:null,vy:0},s=n+1,c=n+1;for(let n of t){for(let t of r(e))for(let e of r(n)){let r=Math.abs(e-t);rtypeof e==`string`&&CF.includes(e),TF=[`rect`,`roundrect`,`ellipse`,`diamond`,`triangle`],EF=[`straight`,`curve`,`elbow`],DF=[`none`,`arrow`,`triangle`,`circle`,`diamond`],OF=[`right`,`left`,`radial`],kF=`page`,AF=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:t,jF=(e,t=``)=>typeof e==`string`?e:t,MF=e=>e===!0,NF=(e,t)=>wF(e)?e:t,PF=(e,t,n)=>typeof e==`string`&&t.includes(e)?e:n;function FF(e){if(!e||typeof e!=`object`)return{x:0,y:0};let t=e,n={};return typeof t.id==`string`&&t.id&&(n.id=t.id),Array.isArray(t.pos)&&t.pos.length===2&&(n.pos=[AF(t.pos[0],.5),AF(t.pos[1],.5)]),n.id||(n.x=AF(t.x,0),n.y=AF(t.y,0)),n}function IF(e){let t={};if(!e||typeof e!=`object`)return t;for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`)continue;let e=r;t[n]={text:jF(e.text),parent:jF(e.parent),pos:AF(e.pos,0)}}return t}function LF(e){let t={id:jF(e.id),index:AF(e.index,0),x:AF(e.x,0),y:AF(e.y,0),w:Math.max(0,AF(e.w,0)),h:Math.max(0,AF(e.h,0)),rotate:AF(e.rotate,0),group:jF(e.group)};switch(e.type){case`shape`:return{...t,type:`shape`,shape:PF(e.shape,TF,`rect`),stroke:NF(e.stroke,`ink`),fill:NF(e.fill,`none`),strokeWidth:AF(e.strokeWidth,2),strokeStyle:PF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),rough:MF(e.rough),text:jF(e.text),textColor:NF(e.textColor,`ink`),fontSize:AF(e.fontSize,18)};case`text`:return{...t,type:`text`,text:jF(e.text),color:NF(e.color,`ink`),fontSize:AF(e.fontSize,24),font:PF(e.font,[``,`serif`,`mono`],``),align:PF(e.align,[`left`,`center`,`right`],`left`),bold:MF(e.bold)};case`connector`:return{...t,type:`connector`,source:FF(e.source),target:FF(e.target),mode:PF(e.mode,EF,`curve`),stroke:NF(e.stroke,`ink`),strokeWidth:AF(e.strokeWidth,2),strokeStyle:PF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),startArrow:PF(e.startArrow,DF,`none`),endArrow:PF(e.endArrow,DF,`arrow`),label:jF(e.label),rough:MF(e.rough)};case`brush`:return{...t,type:`brush`,points:Array.isArray(e.points)?e.points.filter(e=>Array.isArray(e)&&e.length>=2).map(e=>[AF(e[0],0),AF(e[1],0),AF(e[2],.5)]):[],color:NF(e.color,`ink`),size:AF(e.size,4)};case`note`:return{...t,type:`note`,page:MF(e.page),background:NF(e.background,`paper`)};case`frame`:return{...t,type:`frame`,title:jF(e.title),background:NF(e.background,`none`)};case`image`:return{...t,type:`image`,src:jF(e.src),alt:jF(e.alt)};case`embed`:return{...t,type:`embed`,url:jF(e.url)};case`group`:return{...t,type:`group`,title:jF(e.title)};case`mindmap`:return{...t,type:`mindmap`,layout:PF(e.layout,OF,`right`),color:NF(e.color,`blue`),nodes:IF(e.nodes)};default:return null}}var RF=e=>![`connector`,`group`,`mindmap`].includes(e.type),zF=e=>[`shape`,`text`,`image`,`brush`].includes(e.type),BF=e=>![`connector`,`brush`,`group`].includes(e.type),VF=0;function HF(){return VF=(VF+1)%1296,Date.now().toString(36).slice(-6)+VF.toString(36).padStart(2,`0`)+Math.random().toString(36).slice(2,8)}var UF={shape:{shape:`rect`,stroke:`blue`,fill:`blue`,strokeWidth:2,strokeStyle:`solid`,rough:!1,textColor:`ink`},connector:{mode:`curve`,stroke:`gray`,strokeWidth:2,strokeStyle:`solid`,startArrow:`none`,endArrow:`arrow`},brush:{color:`ink`,size:4},text:{color:`ink`,fontSize:24,font:``},note:{background:`yellow`},frame:{background:`none`},mindmap:{layout:`right`,color:`blue`}};function WF(e){let t=structuredClone(UF);if(!e||typeof e!=`object`)return t;for(let n of Object.keys(t)){let r=e[n];if(!r||typeof r!=`object`)continue;let i=LF({...t[n],...r,type:n===`note`?`note`:n});if(i)for(let e of Object.keys(t[n])){let a=r[e];a!==void 0&&i[e]===a&&(t[n][e]=a)}}return t}var GF=[`👍`,`⭐`,`❤️`,`✅`,`❌`,`💡`,`❓`,`❗`,`🎉`,`🔥`,`📌`,`🚀`,`👀`,`🎯`,`⚠️`,`🙂`];function KF(e){return[{id:HF(),type:`text`,text:e,fontSize:64,x:0,y:0,w:0,h:0}]}var qF=[`kanban`,`swot`,`flow`,`brainstorm`,`retro`],JF=e=>[{type:`paragraph`,content:e?[{type:`text`,text:e}]:[]}],YF=(e,t,n,r,i,a=`none`)=>({id:HF(),type:`frame`,title:e,x:t,y:n,w:r,h:i,background:a}),XF=(e,t,n,r,i=220)=>({id:HF(),type:`note`,background:r,x:t,y:n,w:i,h:90,body:JF(e)}),ZF=(e,t,n,r,i,a,o)=>({id:HF(),type:`shape`,shape:e,text:t,x:n,y:r,w:i,h:a,stroke:o,fill:o,strokeWidth:2}),QF=(e,t,n=`elbow`)=>({id:HF(),type:`connector`,source:{id:e},target:{id:t},mode:n,stroke:`gray`,endArrow:`arrow`});function $F(e,t){switch(e){case`kanban`:return[[t.todo,`gray`],[t.doing,`blue`],[t.done,`green`]].flatMap(([e,t],n)=>[YF(e,n*300,0,280,520),XF(``,n*300+30,50,t),XF(``,n*300+30,170,t)]);case`swot`:return[[t.strengths,`green`],[t.weaknesses,`red`],[t.opportunities,`blue`],[t.threats,`orange`]].flatMap(([e,t],n)=>[ZF(`roundrect`,e,n%2*380,Math.floor(n/2)*300,360,280,t)]);case`flow`:{let e=ZF(`ellipse`,t.start,0,0,180,70,`green`),n=ZF(`rect`,t.step,0,140,180,80,`blue`),r=ZF(`diamond`,t.decision,-10,290,200,120,`orange`),i=ZF(`rect`,t.step,280,310,180,80,`blue`),a=ZF(`ellipse`,t.end,0,480,180,70,`red`);return[e,n,r,i,a,QF(e.id,n.id),QF(n.id,r.id),QF(r.id,i.id),QF(r.id,a.id)]}case`brainstorm`:{let e=HF(),n={[e]:{text:t.centralIdea,parent:``,pos:0}};for(let r=0;r<4;r++)n[HF()]={text:`${t.idea} ${r+1}`,parent:e,pos:r};return[{id:HF(),type:`mindmap`,layout:`radial`,color:`purple`,x:0,y:0,nodes:n}]}case`retro`:return[[t.wentWell,`green`],[t.toImprove,`orange`],[t.actions,`blue`]].flatMap(([e,t],n)=>[YF(e,n*300,0,280,420),XF(``,n*300+30,50,t)])}}var eI;function tI(){if(eI!==void 0)return eI;try{eI=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{eI=null}return eI}var nI=`"Inter Variable", Inter, ui-sans-serif, system-ui, sans-serif`,rI=`"Source Serif 4 Variable", "Source Serif 4", Georgia, serif`,iI=`"JetBrains Mono Variable", "JetBrains Mono", ui-monospace, monospace`;function aI(e){return e===`serif`?rI:e===`mono`?iI:nI}function oI(e,t,n=nI,r=400){let i=tI();return i?(i.font=`${r} ${t}px ${n}`,i.measureText(e).width):e.length*t*.56}function sI(e,t,n,r=nI,i=400){let a=[];for(let o of e.split(` -`)){if(!o){a.push(``);continue}let e=``;for(let s of o.split(/(\s+)/)){let o=e+s;if(!e||oI(o,t,r,i)<=n)e=o;else for(a.push(e.trimEnd()),e=s.trimStart();e&&oI(e,t,r,i)>n;){let o=e.length-1;for(;o>1&&oI(e.slice(0,o),t,r,i)>n;)o--;a.push(e.slice(0,o)),e=e.slice(o)}}a.push(e)}return a}function cI(e,t){let n=t===0?18:15,r=t===0?600:400,i=sI(e||` `,n,260,nI,r),a=Math.max(...i.map(e=>oI(e,n,nI,r)),t===0?60:40);return{w:Math.ceil(a)+(t===0?32:24),h:i.length*Math.round(n*1.4)+(t===0?20:14)}}var lI=56,uI=14;function dI(e){let t=Object.entries(e).filter(([,t])=>!t.parent||!e[t.parent]);return t.sort((e,t)=>e[1].pos-t[1].pos||(e[0]n.parent===t&&e!==t).sort((e,t)=>e[1].pos-t[1].pos||(e[0]e)}function pI(e,t,n){let r=dI(e),i=new Map,a=[];if(!r)return{root:``,boxes:i,edges:a,bounds:{x:0,y:0,w:0,h:0}};let o=new Map,s=new Set,c=(t,r)=>{if(!(s.has(t)||r>50)){s.add(t),o.set(t,n(e[t].text,r));for(let n of fI(e,t))c(n,r+1)}};c(r,0);let l=t=>fI(e,t).filter(e=>o.has(e)),u=new Map,d=e=>{let t=u.get(e);if(t!==void 0)return t;let n=l(e),r=n.reduce((e,t)=>e+d(t),0)+uI*Math.max(0,n.length-1),i=Math.max(o.get(e).h,r);return u.set(e,i),i},f=(e,t,n,r,a,s)=>{let c=o.get(e),u=a===1?t:t-c.w;i.set(e,{id:e,x:u,y:n-c.h/2,w:c.w,h:c.h,depth:r,dir:a,parent:s}),p(e,l(e),a===1?u+c.w+lI:u-lI,n,r+1,a)},p=(e,t,n,r,i,a)=>{let o=r-(t.reduce((e,t)=>e+d(t),0)+uI*Math.max(0,t.length-1))/2;for(let r of t){let t=d(r);f(r,n,o+t/2,i,a,e),o+=t+uI}},m=o.get(r);i.set(r,{id:r,x:0,y:0,w:m.w,h:m.h,depth:0,dir:1,parent:``});let h=m.h/2,g=l(r);if(t===`right`)p(r,g,m.w+lI,h,1,1);else if(t===`left`)p(r,g,-56,h,1,-1);else{let e=Math.ceil(g.length/2);p(r,g.slice(0,e),m.w+lI,h,1,1),p(r,g.slice(e),-56,h,1,-1)}for(let e of i.values()){if(!e.parent)continue;let t=i.get(e.parent),n=e.dir===1?[t.x+t.w,t.y+t.h/2]:[t.x,t.y+t.h/2],r=e.dir===1?[e.x,e.y+e.h/2]:[e.x+e.w,e.y+e.h/2];a.push({from:n,to:r,child:e.id})}let _=1/0,v=1/0,y=-1/0,b=-1/0;for(let e of i.values())_=Math.min(_,e.x),v=Math.min(v,e.y),y=Math.max(y,e.x+e.w),b=Math.max(b,e.y+e.h);return{root:r,boxes:i,edges:a,bounds:{x:_,y:v,w:y-_,h:b-v}}}function mI(e,t,n,r){let i=e.boxes.get(n);if(!i)return null;if(r===`ArrowUp`||r===`ArrowDown`){let a=i.parent?fI(t,i.parent).filter(t=>e.boxes.get(t)?.dir===i.dir):[];return a[a.indexOf(n)+(r===`ArrowUp`?-1:1)]??null}let a=r===`ArrowRight`?1:-1;return i.parent?a===i.dir?fI(t,n)[0]??null:i.parent:fI(t,n).find(t=>e.boxes.get(t)?.dir===a)??null}function hI(e,t){let n=(e[0]+t[0])/2;return`M${e[0]} ${e[1]} C${n} ${e[1]} ${n} ${t[1]} ${t[0]} ${t[1]}`}function gI(e,t,n,r=e=>e){return e*r(.5-t*(.5-n))}function _I(e){return[-e[0],-e[1]]}function vI(e,t){return[e[0]+t[0],e[1]+t[1]]}function yI(e,t){return[e[0]-t[0],e[1]-t[1]]}function bI(e,t){return[e[0]*t,e[1]*t]}function xI(e,t){return[e[0]/t,e[1]/t]}function SI(e){return[e[1],-e[0]]}function CI(e,t){return e[0]*t[0]+e[1]*t[1]}function wI(e,t){return e[0]===t[0]&&e[1]===t[1]}function TI(e){return Math.hypot(e[0],e[1])}function EI(e){return e[0]*e[0]+e[1]*e[1]}function DI(e,t){return EI(yI(e,t))}function OI(e){return xI(e,TI(e))}function kI(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function AI(e,t,n){let r=Math.sin(n),i=Math.cos(n),a=e[0]-t[0],o=e[1]-t[1],s=a*i-o*r,c=a*r+o*i;return[s+t[0],c+t[1]]}function jI(e,t,n){return vI(e,bI(yI(t,e),n))}function MI(e,t,n){return vI(e,bI(t,n))}var{min:NI,PI}=Math,FI=.275,II=PI+1e-4;function LI(e,t={}){let{size:n=16,smoothing:r=.5,thinning:i=.5,simulatePressure:a=!0,easing:o=e=>e,start:s={},end:c={},last:l=!1}=t,{cap:u=!0,easing:d=e=>e*(2-e)}=s,{cap:f=!0,easing:p=e=>--e*e*e+1}=c;if(e.length===0||n<=0)return[];let m=e[e.length-1].runningLength,h=s.taper===!1?0:s.taper===!0?Math.max(n,m):s.taper,g=c.taper===!1?0:c.taper===!0?Math.max(n,m):c.taper,_=(n*r)**2,v=[],y=[],b=e.slice(0,10).reduce((e,t)=>{let r=t.pressure;if(a){let i=NI(1,t.distance/n);r=NI(1,e+(NI(1,1-i)-e)*(i*FI))}return(e+r)/2},e[0].pressure),x=gI(n,i,e[e.length-1].pressure,o),S,C=e[0].vector,ee=e[0].point,te=ee,ne=ee,re=te,ie=!1;for(let t=0;t_)&&(v.push(ne),ee=ne),re=vI(s,ue),(t<=1||DI(te,re)>_)&&(y.push(re),te=re),b=r,C=c}let ae=e[0].point.slice(0,2),oe=e.length>1?e[e.length-1].point.slice(0,2):vI(e[0].point,[1,1]),se=[],ce=[];if(e.length===1){if(!(h||g)||l){let e=MI(ae,OI(SI(yI(ae,oe))),-(S||x)),t=[];for(let n=1/13,r=n;r<=1;r+=n)t.push(AI(e,ae,II*2*r));return t}}else{if(!(h||g&&e.length===1)){if(u)for(let e=1/13,t=e;t<=1;t+=e){let e=AI(y[0],ae,II*t);se.push(e)}else{let e=yI(v[0],y[0]),t=bI(e,.5),n=bI(e,.51);se.push(yI(ae,t),yI(ae,n),vI(ae,n),vI(ae,t))}}let t=SI(_I(e[e.length-1].vector));if(g||h&&e.length===1)ce.push(oe);else if(f){let e=MI(oe,t,x);for(let t=1/29,n=t;n<1;n+=t)ce.push(AI(e,oe,II*3*n))}else ce.push(vI(oe,bI(t,x)),vI(oe,bI(t,x*.99)),yI(oe,bI(t,x*.99)),yI(oe,bI(t,x)))}return v.concat(ce,y.reverse(),se)}function RI(e,t={}){let{streamline:n=.5,size:r=16,last:i=!1}=t;if(e.length===0)return[];let a=.15+(1-n)*.85,o=Array.isArray(e[0])?e:e.map(({x:e,y:t,pressure:n=.5})=>[e,t,n]);if(o.length===2){let e=o[1];o=o.slice(0,-1);for(let t=1;t<5;t++)o.push(jI(o[0],e,t/4))}o.length===1&&(o=[...o,[...vI(o[0],[1,1]),...o[0].slice(2)]]);let s=[{point:[o[0][0],o[0][1]],pressure:o[0][2]>=0?o[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],c=!1,l=0,u=s[0],d=o.length-1;for(let e=1;e=0?o[e][2]:.5,vector:OI(yI(u.point,t)),distance:n,runningLength:l},s.push(u)}return s[0].vector=s[1]?.vector||[0,0],s}function zI(e,t={}){return LI(RI(e,t),t)}function BI(e,t,n){if(e&&e.length){let[r,i]=t,a=Math.PI/180*n,o=Math.cos(a),s=Math.sin(a);for(let t of e){let[e,n]=t;t[0]=(e-r)*o-(n-i)*s+r,t[1]=(e-r)*s+(n-i)*o+i}}}function VI(e,t){return e[0]===t[0]&&e[1]===t[1]}function HI(e,t,n,r=1){let i=n,a=Math.max(t,.1),o=e[0]&&e[0][0]&&typeof e[0][0]==`number`?[e]:e,s=[0,0];if(i)for(let e of o)BI(e,s,i);let c=function(e,t,n){let r=[];for(let t of e){let e=[...t];VI(e[0],e[e.length-1])||e.push([e[0][0],e[0][1]]),e.length>2&&r.push(e)}let i=[];t=Math.max(t,.1);let a=[];for(let e of r)for(let t=0;te.ymint.ymin?1:e.xt.x?1:e.ymax===t.ymax?0:(e.ymax-t.ymax)/Math.abs(e.ymax-t.ymax))),!a.length)return i;let o=[],s=a[0].ymin,c=0;for(;o.length||a.length;){if(a.length){let e=-1;for(let t=0;ts);t++)e=t;a.splice(0,e+1).forEach((e=>{o.push({s,edge:e})}))}if(o=o.filter((e=>!(e.edge.ymax<=s))),o.sort(((e,t)=>e.edge.x===t.edge.x?0:(e.edge.x-t.edge.x)/Math.abs(e.edge.x-t.edge.x))),(n!==1||c%t==0)&&o.length>1)for(let e=0;e=o.length)break;let n=o[e].edge,r=o[t].edge;i.push([[Math.round(n.x),s],[Math.round(r.x),s]])}s+=n,o.forEach((e=>{e.edge.x=e.edge.x+n*e.edge.islope})),c++}return i}(o,a,r);if(i){for(let e of o)BI(e,s,-i);(function(e,t,n){let r=[];e.forEach((e=>r.push(...e))),BI(r,t,n)})(c,s,-i)}return c}function UI(e,t){let n=t.hachureAngle+90,r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=1;return t.roughness>=1&&(t.randomizer?.next()||Math.random())>.7&&(i=r),HI(e,r,n,i||1)}var WI=class{constructor(e){this.helper=e}fillPolygons(e,t){return this._fillPolygons(e,t)}_fillPolygons(e,t){let n=UI(e,t);return{type:`fillSketch`,ops:this.renderLines(n,t)}}renderLines(e,t){let n=[];for(let r of e)n.push(...this.helper.doubleLineOps(r[0][0],r[0][1],r[1][0],r[1][1],t));return n}};function GI(e){let t=e[0],n=e[1];return Math.sqrt((t[0]-n[0])**2+(t[1]-n[1])**2)}var KI=class extends WI{fillPolygons(e,t){let n=t.hachureGap;n<0&&(n=4*t.strokeWidth),n=Math.max(n,.1);let r=UI(e,Object.assign({},t,{hachureGap:n})),i=Math.PI/180*t.hachureAngle,a=[],o=.5*n*Math.cos(i),s=.5*n*Math.sin(i);for(let[e,t]of r)GI([e,t])&&a.push([[e[0]-o,e[1]+s],[...t]],[[e[0]+o,e[1]-s],[...t]]);return{type:`fillSketch`,ops:this.renderLines(a,t)}}},qI=class extends WI{fillPolygons(e,t){let n=this._fillPolygons(e,t),r=Object.assign({},t,{hachureAngle:t.hachureAngle+90}),i=this._fillPolygons(e,r);return n.ops=n.ops.concat(i.ops),n}},JI=class{constructor(e){this.helper=e}fillPolygons(e,t){let n=UI(e,t=Object.assign({},t,{hachureAngle:0}));return this.dotsOnLines(n,t)}dotsOnLines(e,t){let n=[],r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=t.fillWeight;i<0&&(i=t.strokeWidth/2);let a=r/4;for(let o of e){let e=GI(o),s=e/r,c=Math.ceil(s)-1,l=e-c*r,u=(o[0][0]+o[1][0])/2-r/4,d=Math.min(o[0][1],o[1][1]);for(let e=0;e{let a=GI(e),o=Math.floor(a/(n+r)),s=(a+r-o*(n+r))/2,c=e[0],l=e[1];c[0]>l[0]&&(c=e[1],l=e[0]);let u=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let e=0;e{let i=GI(e),a=Math.round(i/(2*t)),o=e[0],s=e[1];o[0]>s[0]&&(o=e[1],s=e[0]);let c=Math.atan((s[1]-o[1])/(s[0]-o[0]));for(let e=0;er%2?e+n:e+t));a.push({key:`C`,data:e}),t=e[4],n=e[5];break}case`Q`:a.push({key:`Q`,data:[...s]}),t=s[2],n=s[3];break;case`q`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`Q`,data:e}),t=e[2],n=e[3];break}case`A`:a.push({key:`A`,data:[...s]}),t=s[5],n=s[6];break;case`a`:t+=s[5],n+=s[6],a.push({key:`A`,data:[s[0],s[1],s[2],s[3],s[4],t,n]});break;case`H`:a.push({key:`H`,data:[...s]}),t=s[0];break;case`h`:t+=s[0],a.push({key:`H`,data:[t]});break;case`V`:a.push({key:`V`,data:[...s]}),n=s[0];break;case`v`:n+=s[0],a.push({key:`V`,data:[n]});break;case`S`:a.push({key:`S`,data:[...s]}),t=s[2],n=s[3];break;case`s`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`S`,data:e}),t=e[2],n=e[3];break}case`T`:a.push({key:`T`,data:[...s]}),t=s[0],n=s[1];break;case`t`:t+=s[0],n+=s[1],a.push({key:`T`,data:[t,n]});break;case`Z`:case`z`:a.push({key:`Z`,data:[]}),t=r,n=i}return a}function oL(e){let t=[],n=``,r=0,i=0,a=0,o=0,s=0,c=0;for(let{key:l,data:u}of e){switch(l){case`M`:t.push({key:`M`,data:[...u]}),[r,i]=u,[a,o]=u;break;case`C`:t.push({key:`C`,data:[...u]}),r=u[4],i=u[5],s=u[2],c=u[3];break;case`L`:t.push({key:`L`,data:[...u]}),[r,i]=u;break;case`H`:r=u[0],t.push({key:`L`,data:[r,i]});break;case`V`:i=u[0],t.push({key:`L`,data:[r,i]});break;case`S`:{let e=0,a=0;n===`C`||n===`S`?(e=r+(r-s),a=i+(i-c)):(e=r,a=i),t.push({key:`C`,data:[e,a,...u]}),s=u[0],c=u[1],r=u[2],i=u[3];break}case`T`:{let[e,a]=u,o=0,l=0;n===`Q`||n===`T`?(o=r+(r-s),l=i+(i-c)):(o=r,l=i);let d=r+2*(o-r)/3,f=i+2*(l-i)/3,p=e+2*(o-e)/3,m=a+2*(l-a)/3;t.push({key:`C`,data:[d,f,p,m,e,a]}),s=o,c=l,r=e,i=a;break}case`Q`:{let[e,n,a,o]=u,l=r+2*(e-r)/3,d=i+2*(n-i)/3,f=a+2*(e-a)/3,p=o+2*(n-o)/3;t.push({key:`C`,data:[l,d,f,p,a,o]}),s=e,c=n,r=a,i=o;break}case`A`:{let e=Math.abs(u[0]),n=Math.abs(u[1]),a=u[2],o=u[3],s=u[4],c=u[5],l=u[6];e===0||n===0?(t.push({key:`C`,data:[r,i,c,l,c,l]}),r=c,i=l):(r!==c||i!==l)&&(cL(r,i,c,l,e,n,a,o,s).forEach((function(e){t.push({key:`C`,data:e})})),r=c,i=l);break}case`Z`:t.push({key:`Z`,data:[]}),r=a,i=o}n=l}return t}function sL(e,t,n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function cL(e,t,n,r,i,a,o,s,c,l){let u=(d=o,Math.PI*d/180);var d;let f=[],p=0,m=0,h=0,g=0;if(l)[p,m,h,g]=l;else{[e,t]=sL(e,t,-u),[n,r]=sL(n,r,-u);let o=(e-n)/2,l=(t-r)/2,d=o*o/(i*i)+l*l/(a*a);d>1&&(d=Math.sqrt(d),i*=d,a*=d);let f=i*i,_=a*a,v=f*_-f*l*l-_*o*o,y=f*l*l+_*o*o,b=(s===c?-1:1)*Math.sqrt(Math.abs(v/y));h=b*i*l/a+(e+n)/2,g=b*-a*o/i+(t+r)/2,p=Math.asin(parseFloat(((t-g)/a).toFixed(9))),m=Math.asin(parseFloat(((r-g)/a).toFixed(9))),em&&(p-=2*Math.PI),!c&&m>p&&(m-=2*Math.PI)}let _=m-p;if(Math.abs(_)>120*Math.PI/180){let e=m,t=n,s=r;m=c&&m>p?p+120*Math.PI/180*1:p+120*Math.PI/180*-1,f=cL(n=h+i*Math.cos(m),r=g+a*Math.sin(m),t,s,i,a,o,0,c,[m,e,h,g])}_=m-p;let v=Math.cos(p),y=Math.sin(p),b=Math.cos(m),x=Math.sin(m),S=Math.tan(_/4),C=4/3*i*S,ee=4/3*a*S,te=[e,t],ne=[e+C*y,t-ee*v],re=[n+C*x,r-ee*b],ie=[n,r];if(ne[0]=2*te[0]-ne[0],ne[1]=2*te[1]-ne[1],l)return[ne,re,ie].concat(f);{f=[ne,re,ie].concat(f);let e=[];for(let t=0;t2){let i=[];for(let t=0;t2*Math.PI&&(p=0,m=2*Math.PI);let h=2*Math.PI/c.curveStepCount,g=Math.min(h/2,(m-p)/2),_=DL(g,l,u,d,f,p,m,1,c);if(!c.disableMultiStroke){let e=DL(g,l,u,d,f,p,m,1.5,c);_.push(...e)}return o&&(s?_.push(...SL(l,u,l+d*Math.cos(p),u+f*Math.sin(p),c),...SL(l,u,l+d*Math.cos(m),u+f*Math.sin(m),c)):_.push({op:`lineTo`,data:[l,u]},{op:`lineTo`,data:[l+d*Math.cos(p),u+f*Math.sin(p)]})),{type:`path`,ops:_}}function _L(e,t){let n=oL(aL(iL(e))),r=[],i=[0,0],a=[0,0];for(let{key:e,data:o}of n)switch(e){case`M`:a=[o[0],o[1]],i=[o[0],o[1]];break;case`L`:r.push(...SL(a[0],a[1],o[0],o[1],t)),a=[o[0],o[1]];break;case`C`:{let[e,n,i,s,c,l]=o;r.push(...OL(e,n,i,s,c,l,a,t)),a=[c,l];break}case`Z`:r.push(...SL(a[0],a[1],i[0],i[1],t)),a=[i[0],i[1]]}return{type:`path`,ops:r}}function vL(e,t){let n=[];for(let r of e)if(r.length){let e=t.maxRandomnessOffset||0,i=r.length;if(i>2){n.push({op:`move`,data:[r[0][0]+F(e,t),r[0][1]+F(e,t)]});for(let a=1;a500?.4:-.0016668*c+1.233334;let u=i.maxRandomnessOffset||0;u*u*100>s&&(u=c/10);let d=u/2,f=.2+.2*bL(i),p=i.bowing*i.maxRandomnessOffset*(r-t)/200,m=i.bowing*i.maxRandomnessOffset*(e-n)/200;p=F(p,i,l),m=F(m,i,l);let h=[],g=()=>F(d,i,l),_=()=>F(u,i,l),v=i.preserveVertices;return a&&(o?h.push({op:`move`,data:[e+(v?0:g()),t+(v?0:g())]}):h.push({op:`move`,data:[e+(v?0:F(u,i,l)),t+(v?0:F(u,i,l))]})),o?h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+g(),m+t+(r-t)*f+g(),p+e+2*(n-e)*f+g(),m+t+2*(r-t)*f+g(),n+(v?0:g()),r+(v?0:g())]}):h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+_(),m+t+(r-t)*f+_(),p+e+2*(n-e)*f+_(),m+t+2*(r-t)*f+_(),n+(v?0:_()),r+(v?0:_())]}),h}function wL(e,t,n){let r=[];r.push([e[0][0]+F(t,n),e[0][1]+F(t,n)]),r.push([e[0][0]+F(t,n),e[0][1]+F(t,n)]);for(let i=1;i3){let a=[],o=1-n.curveTightness;i.push({op:`move`,data:[e[1][0],e[1][1]]});for(let t=1;t+21&&i.push(n)):i.push(n),i.push(e[t+3])}else{let r=.5,a=e[t+0],o=e[t+1],s=e[t+2],c=e[t+3],l=ML(a,o,r),u=ML(o,s,r),d=ML(s,c,r),f=ML(l,u,r),p=ML(u,d,r),m=ML(f,p,r);NL([a,l,f,m],0,n,i),NL([m,p,d,c],0,n,i)}var a,o;return i}function PL(e,t){return FL(e,0,e.length,t)}function FL(e,t,n,r,i){let a=i||[],o=e[t],s=e[n-1],c=0,l=1;for(let r=t+1;rc&&(c=t,l=r)}return Math.sqrt(c)>r?(FL(e,t,l+1,r,a),FL(e,l,n,r,a)):(a.length||a.push(o),a.push(s)),a}function IL(e,t=.15,n){let r=[],i=(e.length-1)/3;for(let n=0;n0?FL(r,0,r.length,n):r}var LL=`none`,RL=class{constructor(e){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:`#000`,strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:`hachure`,fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=e||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(e){return e?Object.assign({},this.defaultOptions,e):this.defaultOptions}_d(e,t,n){return{shape:e,sets:t||[],options:n||this.defaultOptions}}line(e,t,n,r,i){let a=this._o(i);return this._d(`line`,[uL(e,t,n,r,a)],a)}rectangle(e,t,n,r,i){let a=this._o(i),o=[],s=fL(e,t,n,r,a);if(a.fill){let i=[[e,t],[e+n,t],[e+n,t+r],[e,t+r]];a.fillStyle===`solid`?o.push(vL([i],a)):o.push(yL([i],a))}return a.stroke!==LL&&o.push(s),this._d(`rectangle`,o,a)}ellipse(e,t,n,r,i){let a=this._o(i),o=[],s=mL(n,r,a),c=hL(e,t,a,s);if(a.fill){if(a.fillStyle===`solid`){let n=hL(e,t,a,s).opset;n.type=`fillPath`,o.push(n)}else o.push(yL([c.estimatedPoints],a))}return a.stroke!==LL&&o.push(c.opset),this._d(`ellipse`,o,a)}circle(e,t,n,r){let i=this.ellipse(e,t,n,n,r);return i.shape=`circle`,i}linearPath(e,t){let n=this._o(t);return this._d(`linearPath`,[dL(e,!1,n)],n)}arc(e,t,n,r,i,a,o=!1,s){let c=this._o(s),l=[],u=gL(e,t,n,r,i,a,o,!0,c);if(o&&c.fill){if(c.fillStyle===`solid`){let o=Object.assign({},c);o.disableMultiStroke=!0;let s=gL(e,t,n,r,i,a,!0,!1,o);s.type=`fillPath`,l.push(s)}else l.push(function(e,t,n,r,i,a,o){let s=e,c=t,l=Math.abs(n/2),u=Math.abs(r/2);l+=F(.01*l,o),u+=F(.01*u,o);let d=i,f=a;for(;d<0;)d+=2*Math.PI,f+=2*Math.PI;f-d>2*Math.PI&&(d=0,f=2*Math.PI);let p=(f-d)/o.curveStepCount,m=[];for(let e=d;e<=f;e+=p)m.push([s+l*Math.cos(e),c+u*Math.sin(e)]);return m.push([s+l*Math.cos(f),c+u*Math.sin(f)]),m.push([s,c]),yL([m],o)}(e,t,n,r,i,a,c))}return c.stroke!==LL&&l.push(u),this._d(`arc`,l,c)}curve(e,t){let n=this._o(t),r=[],i=pL(e,n);if(n.fill&&n.fill!==LL&&e.length>=3){if(n.fillStyle===`solid`){let t=pL(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else{let t=IL(function(e,t=0){let n=e.length;if(n<3)throw Error(`A curve must have at least three points.`);let r=[];if(n===3)r.push(kL(e[0]),kL(e[1]),kL(e[2]),kL(e[2]));else{let n=[];n.push(e[0],e[0]);for(let t=1;t{s.length>=4&&a.push(...IL(s,t)),s=[]},l=()=>{c(),a.length&&(i.push(a),a=[])};for(let{key:e,data:t}of r)switch(e){case`M`:l(),o=[t[0],t[1]],a.push(o);break;case`L`:c(),a.push([t[0],t[1]]);break;case`C`:if(!s.length){let e=a.length?a[a.length-1]:o;s.push([e[0],e[1]])}s.push([t[0],t[1]]),s.push([t[2],t[3]]),s.push([t[4],t[5]]);break;case`Z`:c(),a.push([o[0],o[1]])}if(l(),!n)return i;let u=[];for(let e of i){let t=PL(e,n);t.length&&u.push(t)}return u}(e,1,o?4-4*(n.simplification||1):(1+n.roughness)/2),c=_L(e,n);if(i){if(n.fillStyle===`solid`){if(s.length===1){let t=_L(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else r.push(vL(s,n))}else r.push(yL(s,n))}return a&&(o?s.forEach((e=>{r.push(dL(e,!1,n))})):r.push(c)),this._d(`path`,r,n)}opsToPath(e,t){let n=``;for(let r of e.ops){let e=typeof t==`number`&&t>=0?r.data.map((e=>+e.toFixed(t))):r.data;switch(r.op){case`move`:n+=`M${e[0]} ${e[1]} `;break;case`bcurveTo`:n+=`C${e[0]} ${e[1]}, ${e[2]} ${e[3]}, ${e[4]} ${e[5]} `;break;case`lineTo`:n+=`L${e[0]} ${e[1]} `}}return n.trim()}toPaths(e){let t=e.sets||[],n=e.options||this.defaultOptions,r=[];for(let e of t){let t=null;switch(e.type){case`path`:t={d:this.opsToPath(e),stroke:n.stroke,strokeWidth:n.strokeWidth,fill:LL};break;case`fillPath`:t={d:this.opsToPath(e),stroke:LL,strokeWidth:0,fill:n.fill||LL};break;case`fillSketch`:t=this.fillSketch(e,n)}t&&r.push(t)}return r}fillSketch(e,t){let n=t.fillWeight;return n<0&&(n=t.strokeWidth/2),{d:this.opsToPath(e),stroke:t.fill||LL,strokeWidth:n,fill:LL}}_mergedShape(e){return e.filter(((e,t)=>t===0||e.op!==`move`))}},zL=class{constructor(e,t){this.canvas=e,this.ctx=this.canvas.getContext(`2d`),this.gen=new RL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.ctx,i=e.options.fixedDecimalPlaceDigits;for(let a of t)switch(a.type){case`path`:r.save(),r.strokeStyle=n.stroke===`none`?`transparent`:n.stroke,r.lineWidth=n.strokeWidth,n.strokeLineDash&&r.setLineDash(n.strokeLineDash),n.strokeLineDashOffset&&(r.lineDashOffset=n.strokeLineDashOffset),this._drawToContext(r,a,i),r.restore();break;case`fillPath`:{r.save(),r.fillStyle=n.fill||``;let t=e.shape===`curve`||e.shape===`polygon`||e.shape===`path`?`evenodd`:`nonzero`;this._drawToContext(r,a,i,t),r.restore();break}case`fillSketch`:this.fillSketch(r,a,n)}}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2),e.save(),n.fillLineDash&&e.setLineDash(n.fillLineDash),n.fillLineDashOffset&&(e.lineDashOffset=n.fillLineDashOffset),e.strokeStyle=n.fill||``,e.lineWidth=r,this._drawToContext(e,t,n.fixedDecimalPlaceDigits),e.restore()}_drawToContext(e,t,n,r=`nonzero`){e.beginPath();for(let r of t.ops){let t=typeof n==`number`&&n>=0?r.data.map((e=>+e.toFixed(n))):r.data;switch(r.op){case`move`:e.moveTo(t[0],t[1]);break;case`bcurveTo`:e.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5]);break;case`lineTo`:e.lineTo(t[0],t[1])}}t.type===`fillPath`?e.fill(r):e.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a),a}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a),a}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a),a}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i),i}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n),n}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n),n}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c),c}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n),n}path(e,t){let n=this.gen.path(e,t);return this.draw(n),n}},BL=`http://www.w3.org/2000/svg`,VL=class{constructor(e,t){this.svg=e,this.gen=new RL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.svg.ownerDocument||window.document,i=r.createElementNS(BL,`g`),a=e.options.fixedDecimalPlaceDigits;for(let o of t){let t=null;switch(o.type){case`path`:t=r.createElementNS(BL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,n.stroke),t.setAttribute(`stroke-width`,n.strokeWidth+``),t.setAttribute(`fill`,`none`),n.strokeLineDash&&t.setAttribute(`stroke-dasharray`,n.strokeLineDash.join(` `).trim()),n.strokeLineDashOffset&&t.setAttribute(`stroke-dashoffset`,`${n.strokeLineDashOffset}`);break;case`fillPath`:t=r.createElementNS(BL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,`none`),t.setAttribute(`stroke-width`,`0`),t.setAttribute(`fill`,n.fill||``),e.shape!==`curve`&&e.shape!==`polygon`||t.setAttribute(`fill-rule`,`evenodd`);break;case`fillSketch`:t=this.fillSketch(r,o,n)}t&&i.appendChild(t)}return i}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let i=e.createElementNS(BL,`path`);return i.setAttribute(`d`,this.opsToPath(t,n.fixedDecimalPlaceDigits)),i.setAttribute(`stroke`,n.fill||``),i.setAttribute(`stroke-width`,r+``),i.setAttribute(`fill`,`none`),n.fillLineDash&&i.setAttribute(`stroke-dasharray`,n.fillLineDash.join(` `).trim()),n.fillLineDashOffset&&i.setAttribute(`stroke-dashoffset`,`${n.fillLineDashOffset}`),i}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(e,t){return this.gen.opsToPath(e,t)}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a)}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a)}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a)}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i)}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n)}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n)}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c)}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n)}path(e,t){let n=this.gen.path(e,t);return this.draw(n)}},HL={canvas:(e,t)=>new zL(e,t),svg:(e,t)=>new VL(e,t),generator:e=>new RL(e),newSeed:()=>RL.newSeed()},UL=(e,t)=>e===`none`?`none`:e===`ink`?t===`fill`?`var(--dw-surface-sunken)`:`var(--dw-ink)`:e===`paper`?t===`fill`?`var(--dw-surface-raised)`:`var(--dw-surface)`:t===`fill`?`color-mix(in srgb, var(--dw-c-${e}) 22%, var(--dw-surface))`:`var(--dw-c-${e})`,WL=e=>e.replace(/&/g,`&`).replace(//g,`>`).replace(/"/g,`"`),GL=e=>Math.round(e*100)/100,KL=`#000001`,qL=`#000002`;function JL(e,t){return e===`dash`?`stroke-dasharray:${GL(t*4)} ${GL(t*3)};`:``}function YL(e){let t=2166136261;for(let n of e)t=Math.imul(t^n.charCodeAt(0),16777619);return(t>>>0)%2**31||1}function XL(e,t,n){switch(e){case`diamond`:return[[t/2,0],[t,n/2],[t/2,n],[0,n/2]];case`triangle`:return[[t/2,0],[t,n],[0,n]];case`rect`:return[[0,0],[t,0],[t,n],[0,n]];default:return null}}function ZL(e,t){let n=Math.min(16,e*.15,t*.15);return`M${GL(n)} 0 H${GL(e-n)} Q${GL(e)} 0 ${GL(e)} ${GL(n)} V${GL(t-n)} Q${GL(e)} ${GL(t)} ${GL(e-n)} ${GL(t)} H${GL(n)} Q0 ${GL(t)} 0 ${GL(t-n)} V${GL(n)} Q0 0 ${GL(n)} 0 Z`}function QL(e,t){let{w:n,h:r}=e,i=e.strokeStyle===`none`?`none`:t(e.stroke,`line`),a=t(e.fill,`fill`),o=e.strokeStyle===`none`?0:e.strokeWidth;if(e.rough){let t=HL.generator(),s={seed:YL(e.id),roughness:1.2,bowing:1,strokeWidth:Math.max(o,1),stroke:i===`none`?`none`:KL,fill:a===`none`?void 0:qL,fillStyle:`hachure`,hachureGap:8,fillWeight:1.4,disableMultiStroke:o===0},c=XL(e.shape,n,r),l=e.shape===`ellipse`?t.ellipse(n/2,r/2,n,r,s):e.shape===`roundrect`?t.path(ZL(n,r),s):t.polygon(c,s);return t.toPaths(l).map(t=>{if(t.fill===qL)return``;let n=t.stroke===qL,r=n?a.replace(`22%`,`60%`):i;return r===`none`||t.stroke===`none`?``:``}).join(``)}let s=`fill:${a};stroke:${i};stroke-width:${GL(o)};stroke-linejoin:round;${JL(e.strokeStyle,o)}`;return e.shape===`ellipse`?``:e.shape===`roundrect`?``:``}function $L(e,t,n,r,i){if(e===`none`)return``;let a=6+r*2.5,o=(e,r)=>{let i=Math.cos(n),a=Math.sin(n);return`${GL(t[0]+e*i-r*a)},${GL(t[1]+e*a+r*i)}`};switch(e){case`arrow`:return``;case`triangle`:return``;case`circle`:{let[e,t]=o(-a*.45,0).split(`,`).map(Number);return``}case`diamond`:return``}}function eR(e,t,n){let r=e.strokeStyle===`none`?n(`gray`,`line`):n(e.stroke,`line`),i=e.strokeWidth,a;if(e.rough){let n=HL.generator();a=n.toPaths(n.path(t.d,{seed:YL(e.id),roughness:1,strokeWidth:i,stroke:`#000`})).map(e=>``).join(``)}else a=``;let o=t.points[t.points.length-1];return a+$L(e.startArrow,t.points[0],t.startAngle,i,r)+$L(e.endArrow,o,t.endAngle,i,r)}function tR(e,t){let n=zI(e,{size:t,thinning:.55,smoothing:.5,streamline:.4,simulatePressure:e.every(e=>e[2]===.5),last:!0});if(!n.length)return``;let r=(e,t)=>(e+t)/2,i=`M${GL(n[0][0])} ${GL(n[0][1])} Q`;for(let e=0;e`}function rR(e){let t=[];for(let n of e.toArray())if(n instanceof mx)for(let e of n.toDelta()){if(typeof e.insert!=`string`)continue;let n={type:`text`,text:e.insert};e.attributes&&(n.marks=Object.entries(e.attributes).map(([e,t])=>({type:e,attrs:t&&typeof t==`object`?t:{}}))),t.push(n)}else if(n instanceof lx){let e={type:n.nodeName},r=n.getAttributes();Object.keys(r).length&&(e.attrs=r),n.length&&(e.content=rR(n)),t.push(e)}return t}function iR(e,t,n=0){if(n>100)return;let r=0;for(;r{let r=``,i=!1;for(let a of e)a.type===`text`?(r+=a.text??``,i=!0):a.type===`hardBreak`?(t.push(r),r=``):a.content?.length&&a.content.some(e=>e.type!==`text`&&e.type!==`hardBreak`)?(i&&t.push(r),r=``,i=!1,n(a.content)):(i&&t.push(r),t.push((a.content??[]).map(e=>e.text??``).join(``)),r=``,i=!1);i&&t.push(r)};return n(e),t}var oR=`docwell-canvas`,sR=e=>e.getMap(`surface`);function cR(e){let t={};for(let[n,r]of e.entries())r instanceof Bb?t[n]=r.toJSON():r instanceof gb||(t[n]=r);return LF(t)}function lR(e,t){return(e.type===`frame`?0:1)-(t.type===`frame`?0:1)||e.index-t.index||(e.idt.id))}function uR(){return LF({id:kF,type:`note`,page:!0,background:`paper`,x:0,y:0,w:760,h:400,index:0})}var dR=class{doc;map;undo;cache=null;byId=new Map;listeners=new Set;observer=e=>{this.cache=null;let t=new Set;for(let n of e){if(n.target===this.map){t=null;break}let e=n.target;for(;e&&e.parent!==this.map;)e=e.parent;let r=e&&e._item?.parentSub;r&&t.add(r)}for(let e of this.listeners)e(t)};constructor(e,t={}){this.doc=e,this.map=sR(e),this.map.observeDeep(this.observer),this.undo=t.undo===!1?null:new Wy(this.map,{trackedOrigins:new Set([oR]),captureTimeout:400})}destroy(){this.map.unobserveDeep(this.observer),this.undo?.destroy(),this.listeners.clear()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}elements(){if(this.cache)return this.cache;let e=[];for(let[t,n]of this.map.entries()){let r=n instanceof Bb?cR(n):null;r&&e.push({...r,id:t})}return e.some(e=>e.type===`note`&&e.page)||e.push(uR()),e.sort(lR),this.cache=e,this.byId=new Map(e.map(e=>[e.id,e])),e}get(e){return this.elements(),this.byId.get(e)}get isEmpty(){return this.map.size===0}body(e){let t=this.map.get(e);if(!(t instanceof Bb))return null;let n=t.get(`body`);return n instanceof sx?n:null}nodes(e){let t=this.map.get(e)?.get(`nodes`);return t instanceof Bb?t:null}transact(e){this.doc.transact(e,oR)}nextIndex(){let e=0;for(let t of this.elements())t.type!==`frame`&&(e=Math.max(e,t.index));return e+1}ensure(e){let t=this.map.get(e);if(t instanceof Bb)return t;if(e!==`page`)return null;let n=this.get(e),r=new Bb;this.map.set(e,r);for(let[e,t]of Object.entries(n))e!==`id`&&r.set(e,t);return r}add(e,t){let n=e.id||HF();return this.transact(()=>{let r=new Bb;this.map.set(n,r);let{nodes:i,...a}=e;for(let[e,t]of Object.entries(a))e!==`id`&&t!==void 0&&r.set(e,t);if(`index`in a||r.set(`index`,e.type===`frame`?-this.nextIndex():this.nextIndex()),e.type===`note`&&!e.page){let e=new sx;r.set(`body`,e),iR(e,t?.length?t:[{type:`paragraph`}])}if(e.type===`mindmap`){let e=new Bb;r.set(`nodes`,e);let t=i&&Object.keys(i).length?i:{[HF()]:{text:``,parent:``,pos:0}};for(let[n,r]of Object.entries(t))e.set(n,fR(r))}}),n}update(e,t){this.updateMany([[e,t]])}updateMany(e){e.length&&this.transact(()=>{for(let[t,n]of e){let e=this.ensure(t);if(e)for(let[t,r]of Object.entries(n))t!==`id`&&t!==`type`&&t!==`body`&&t!==`nodes`&&(r===void 0?e.delete(t):pR(e.get(t),r)||e.set(t,r))}})}remove(e){let t=this.elements(),n=new Set;for(let r of e){n.add(r);for(let e of t)e.group===r&&n.add(e.id)}n.delete(kF);for(let e of t)e.type===`note`&&e.page&&n.delete(e.id);n.size&&this.transact(()=>{for(let e of t)if(!(e.type!==`connector`||n.has(e.id)))for(let t of[`source`,`target`]){let r=e[t];if(r.id&&n.has(r.id)){let n=this.endPoint(r);this.map.get(e.id)?.set(t,{x:n[0],y:n[1]})}}for(let e of n)this.map.delete(e);let e=this.elements();for(let t of e.filter(e=>e.type===`group`)){let n=e.filter(e=>e.group===t.id);if(n.length<2){for(let e of n)this.map.get(e.id)?.delete(`group`);this.map.delete(t.id)}}})}endPoint(e){let t=e.id?this.get(e.id):void 0;if(!t)return[e.x??0,e.y??0];let[n,r]=e.pos??[.5,.5];return[t.x+t.w*n,t.y+t.h*r]}reorder(e,t){let n=this.elements().filter(e=>e.type!==`frame`),r=new Set(e),i=n.filter(e=>r.has(e.id));if(!i.length)return;let a=n.filter(e=>!r.has(e.id)),o;if(t===`front`)o=[...a,...i];else if(t===`back`)o=[...i,...a];else{o=[...n];let e=t===`forward`?1:-1,a=e=>o.indexOf(e),s=e===1?[...i].reverse():i;for(let t of s){let n=a(t),i=n+e;i<0||i>=o.length||r.has(o[i].id)||([o[n],o[i]]=[o[i],o[n]])}}this.updateMany(o.map((e,t)=>[e.id,{index:t+1}]).filter(([e,t])=>this.get(e)?.index!==t.index))}groupOf(e){let t=e.filter(e=>{let t=this.get(e);return t&&t.type!==`group`&&!(t.type===`note`&&t.page)});if(t.length<2)return null;let n=HF();return this.transact(()=>{let e=new Bb;this.map.set(n,e),e.set(`type`,`group`),e.set(`index`,this.nextIndex());for(let e of t)this.ensure(e)?.set(`group`,n)}),n}ungroup(e){let t=this.elements().filter(t=>t.group===e).map(e=>e.id);return this.transact(()=>{for(let e of t)this.map.get(e)?.delete(`group`);this.map.delete(e)}),t}addNode(e,t,n,r=``){let i=HF();return this.transact(()=>this.nodes(e)?.set(i,fR({text:r,parent:t,pos:n}))),i}updateNode(e,t,n){this.transact(()=>{let r=this.nodes(e)?.get(t);if(r)for(let[e,t]of Object.entries(n))r.get(e)!==t&&r.set(e,t)})}removeNode(e,t){let n=this.get(e);if(n?.type!==`mindmap`)return;if(t===Object.entries(n.nodes).find(([,e])=>!e.parent)?.[0]){this.remove([e]);return}let r=new Set([t]),i=!0;for(;i;){i=!1;for(let[e,t]of Object.entries(n.nodes))!r.has(e)&&r.has(t.parent)&&(r.add(e),i=!0)}this.transact(()=>{let t=this.nodes(e);for(let e of r)t?.delete(e)})}toJSON(e){let t=this.elements(),n;if(e){n=new Set(e);for(let e of t)n.has(e.group)&&n.add(e.id)}else n=new Set(t.map(e=>e.id));return t.filter(e=>n.has(e.id)).map(e=>{let t={...e,id:e.id,type:e.type},n=e.type===`note`&&!e.page?this.body(e.id):null;return n&&(t.body=rR(n)),t})}insertJSON(e,t=0,n=0){let r=e.filter(e=>e&&typeof e==`object`&&!(e.type===`note`&&e.page)),i=new Map(r.map(e=>[String(e.id),HF()])),a=[],o=this.nextIndex();return this.transact(()=>{for(let e of r){let r=LF(e);if(!r)continue;let s=i.get(String(e.id)),c={...r};if(delete c.id,c.x=r.x+t,c.y=r.y+n,c.index=r.type===`frame`?-o++:o++,c.group=r.group&&i.has(r.group)?i.get(r.group):void 0,r.type===`connector`)for(let e of[`source`,`target`]){let a=r[e];if(a.id&&i.has(a.id))c[e]={id:i.get(a.id),...a.pos?{pos:a.pos}:{}};else if(a.id){let r=this.endPoint(a);c[e]={x:r[0]+t,y:r[1]+n}}else c[e]={x:(a.x??0)+t,y:(a.y??0)+n}}for(let e of Object.keys(c))(c[e]===void 0||c[e]===``)&&delete c[e];this.add({...c,id:s,type:r.type},Array.isArray(e.body)?e.body:void 0),a.push(s)}}),a}load(e){this.transact(()=>{for(let e of[...this.map.keys()])this.map.delete(e);for(let t of e){let e=LF(t);if(!e||!t.id)continue;let n={...e},r=String(t.id);delete n.id;for(let e of Object.keys(n))n[e]===``&&delete n[e];this.add({...n,id:r,type:e.type},Array.isArray(t.body)?t.body:void 0)}})}};function fR(e){let t=new Bb;return t.set(`text`,e.text),t.set(`parent`,e.parent),t.set(`pos`,e.pos),t}function pR(e,t){return e===t?!0:typeof e!=`object`||typeof t!=`object`||!e||!t?!1:JSON.stringify(e)===JSON.stringify(t)}var mR=(e,t=18)=>``,hR={rect:``,roundrect:``,ellipse:``,diamond:``,triangle:``,straight:``,curve:``,elbow:``,none:``,arrow:``,triangleEnd:``,circle:``,diamondEnd:``,solid:``,dash:``,noLine:``,right:``,left:``,radial:``},gR=e=>``;function _R(e){return e===`none`?`background:transparent`:e===`ink`?`background:var(--dw-ink)`:e===`paper`?`background:var(--dw-surface)`:`background:var(--dw-c-${e})`}var vR=class{v;bar;zoomBox;props;zoomLabel;pop=null;popFor=``;fileInput;lastProps=``;closePop=e=>{this.pop&&!this.pop.contains(e.target)&&!e.target.closest?.(`[data-pop]`)&&this.hidePop()};constructor(e){this.v=e;let t=e.root;this.bar=this.div(`dw-cv-ui dw-cv-toolbar`),this.bar.setAttribute(`role`,`toolbar`),this.bar.setAttribute(`aria-label`,e.labels.toolbar),this.zoomBox=this.div(`dw-cv-ui dw-cv-zoom`),this.props=this.div(`dw-cv-ui dw-cv-props`),this.props.setAttribute(`role`,`toolbar`),this.zoomLabel=document.createElement(`button`),this.fileInput=document.createElement(`input`),this.fileInput.type=`file`,this.fileInput.accept=`image/*`,this.fileInput.multiple=!0,this.fileInput.hidden=!0,this.fileInput.addEventListener(`change`,()=>{let t=[...this.fileInput.files??[]];this.fileInput.value=``,t.length&&e.addImages(t)}),t.append(this.bar,this.zoomBox,this.props,this.fileInput),document.addEventListener(`pointerdown`,this.closePop,!0),this.buildZoom(),this.refresh()}destroy(){document.removeEventListener(`pointerdown`,this.closePop,!0)}div(e){let t=document.createElement(`div`);return t.className=e,t}button(e,t,n,r={}){let i=document.createElement(`button`);return i.type=`button`,i.className=`dw-cv-btn${r.cls?` ${r.cls}`:``}`,i.innerHTML=e,i.title=t,i.setAttribute(`aria-label`,t),r.active!==void 0&&i.setAttribute(`aria-pressed`,String(r.active)),r.pop&&(i.dataset.pop=r.pop),i.addEventListener(`pointerdown`,e=>e.stopPropagation()),i.addEventListener(`click`,e=>{e.stopPropagation(),n()}),i}buildBar(){let e=this.v,t=e.labels;if(this.bar.replaceChildren(),this.bar.hidden=e.isPresenting,!e.editable){this.bar.append(this.button(mR(`cursor`),t.select,()=>e.setTool(`select`),{active:e.tool===`select`}),this.button(mR(`hand`),t.hand,()=>e.setTool(`hand`),{active:e.tool===`hand`}),this.sep(),this.button(mR(`present`),t.present,()=>e.present()));return}let n=(t,n,r)=>this.button(mR(n),r,()=>e.setTool(t),{active:e.tool===t}),r=this.button(gR(e.shapeKind),t.shape,()=>{e.setTool(`shape`),this.togglePop(`shape`,r,()=>this.shapePop())},{active:e.tool===`shape`,pop:`shape`}),i=this.button(mR(`pen`),t.pen,()=>{e.setTool(`pen`),this.togglePop(`pen`,i,()=>this.penPop())},{active:e.tool===`pen`,pop:`pen`}),a=this.button(mR(`connector`),t.connector,()=>{e.setTool(`connector`),this.togglePop(`connector`,a,()=>this.connectorPop())},{active:e.tool===`connector`,pop:`connector`}),o=this.button(mR(`sticker`),t.library,()=>this.togglePop(`library`,o,()=>this.libraryPop()),{pop:`library`});this.bar.append(n(`select`,`cursor`,t.select),n(`hand`,`hand`,t.hand),this.sep(),n(`note`,`note`,t.note),n(`text`,`type`,t.text),r,a,i,n(`eraser`,`eraser`,t.eraser),n(`frame`,`frame`,t.frame),n(`mindmap`,`mindmap`,t.mindmap),this.button(mR(`image`),t.image,()=>this.pickImage()),this.button(mR(`link`),t.link,()=>void e.addLink()),o,this.sep(),this.button(mR(`present`),t.present,()=>e.present()))}sep(){return this.div(`dw-cv-sep`)}pickImage(){this.v.editable&&this.v.opts.files?.upload&&this.fileInput.click()}togglePop(e,t,n){if(this.pop&&this.popFor===e)return this.hidePop();this.hidePop();let r=n();r.classList.add(`dw-cv-ui`,`dw-cv-pop`),r.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.v.root.append(r),this.pop=r,this.popFor=e;let i=this.v.root.getBoundingClientRect(),a=t.getBoundingClientRect(),o=r.offsetWidth,s=r.offsetHeight,c=a.left-i.left+a.width/2-o/2;c=Math.max(8,Math.min(i.width-o-8,c));let l=a.top-i.top-s-8;l<8&&(l=a.bottom-i.top+8),r.style.left=`${c}px`,r.style.top=`${l}px`}hidePop(){this.pop?.remove(),this.pop=null,this.popFor=``}row(...e){let t=this.div(`dw-cv-row`);return t.append(...e),t}colorRow(e,t,n,r){let i=this.div(`dw-cv-row dw-cv-colors`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,r);let a=this.v.labels,o=[`ink`,...SF,...n?[`paper`,`none`]:[]];for(let n of o){let r=n===`ink`?a.colorInk:n===`paper`?a.colorPaper:n===`none`?a.colorNone:a.colors[n]??n,o=this.button(``,r,()=>{t(n),this.lastProps=``,this.refresh()},{active:n===e});i.append(o)}return i}shapePop(){let e=this.v,t=e.labels,n=this.div(``);return n.append(this.row(...TF.map(n=>this.button(gR(n),t[n],()=>{e.setShapeKind(n),this.hidePop()},{active:e.shapeKind===n}))),this.row(this.button(`${t.general}`,t.general,()=>{e.setStyle(`shape`,{rough:!1}),this.hidePop()},{active:!e.styles.shape.rough}),this.button(`${t.scribbled}`,t.scribbled,()=>{e.setStyle(`shape`,{rough:!0}),this.hidePop()},{active:e.styles.shape.rough}))),n}penPop(){let e=this.v,t=this.div(``);return t.append(this.colorRow(e.styles.brush.color,t=>e.setStyle(`brush`,{color:t}),!1,e.labels.stroke),this.row(...[2,4,8,14].map(t=>this.button(``,`${e.labels.thickness} ${t}`,()=>{e.setStyle(`brush`,{size:t}),this.hidePop()},{active:e.styles.brush.size===t})))),t}connectorPop(){let e=this.v,t=this.div(``);return t.append(this.row(...EF.map(t=>this.button(gR(t),e.labels[t],()=>{e.setStyle(`connector`,{mode:t}),this.hidePop()},{active:e.styles.connector.mode===t})))),t}libraryPop(){let e=this.v,t=e.labels,n=this.div(`dw-cv-library`),r=this.div(`dw-cv-poptitle`);r.textContent=t.stickers;let i=this.div(`dw-cv-stickers`);for(let t of GF)i.append(this.button(`${t}`,t,()=>{e.insertSticker(t),this.hidePop()}));let a=this.div(`dw-cv-poptitle`);a.textContent=t.templates;let o=this.div(`dw-cv-templates`),s={kanban:t.templateKanban,swot:t.templateSwot,flow:t.templateFlow,brainstorm:t.templateBrainstorm,retro:t.templateRetro};for(let t of qF){let n=this.button(`${s[t]}`,s[t],()=>{e.insertTemplate(t),this.hidePop()},{cls:`dw-cv-wide`});o.append(n)}return n.append(r,i,a,o),n}buildZoom(){let e=this.v,t=e.labels;this.zoomLabel.type=`button`,this.zoomLabel.className=`dw-cv-btn dw-cv-zoomlabel`,this.zoomLabel.title=t.zoomReset,this.zoomLabel.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.zoomLabel.addEventListener(`click`,()=>e.zoomAt(1)),this.zoomBox.append(this.button(mR(`zoom-out`),t.zoomOut,()=>e.zoomBy(.8)),this.zoomLabel,this.button(mR(`zoom-in`),t.zoomIn,()=>e.zoomBy(1.25)),this.button(mR(`fit`),t.zoomFit,()=>e.fit()))}zoomChanged(){this.zoomLabel.textContent=`${Math.round(this.v.zoom*100)}%`}refresh(){this.buildBar();let e=(this.v.editable||this.v.opts.onComment)&&!this.v.editing&&!this.v.isPresenting?this.v.selection():[],t=JSON.stringify([e,this.v.activeNode,this.v.styles.shape.rough]);t!==this.lastProps&&(this.lastProps=t,this.buildProps(e)),this.place()}place(){let e=this.props;if(e.hidden)return;let t=this.v.selectionScreenBox();if(!t){e.hidden=!0;return}let n=this.v.root.getBoundingClientRect(),r=e.offsetWidth,i=e.offsetHeight,a=t.x+t.w/2-r/2;a=Math.max(8,Math.min(n.width-r-8,a));let o=t.y-i-40;o<8&&(o=Math.min(n.height-i-64,t.y+t.h+16)),e.style.left=`${a}px`,e.style.top=`${Math.max(8,o)}px`}buildProps(e){let t=this.props;if(t.replaceChildren(),!e.length){t.hidden=!0;return}t.hidden=!1;let n=this.v,r=n.labels,i=n.opts.onComment,a=()=>this.button(mR(`comment`),r.comment,()=>{let t=e[0].id;i?.({id:t,text:n.elementText(t).slice(0,500)})});if(!n.editable){i&&e.length===1?t.append(a()):t.hidden=!0;return}let o=new Set(e.map(e=>e.type)).size===1?e[0]:null,s=[],c=(e,t,n,r)=>{let i=this.button(t,n,()=>this.togglePop(e,i,r),{pop:e});s.push(i)},l=(e,t,r,i,a)=>c(e,``,t,()=>{let e=this.div(``);return e.append(this.colorRow(r,e=>n.restyle({[i]:e}),a,t)),e}),u=(e,t,r,i,a,o,s,l=e=>e)=>c(e,a(r),t,()=>{let e=this.div(``);return e.append(this.row(...i.map(e=>this.button(a(e),s(e),()=>{n.restyle({[o]:l(e)}),this.hidePop(),this.lastProps=``,this.refresh()},{active:e===r})))),e}),d=(e,t,n,r)=>s.push(this.button(e,t,r,{active:n}));if(o?.type===`shape`)u(`kind`,r.shape,o.shape,TF,gR,`shape`,e=>r[e]),l(`fill`,r.fill,o.fill,`fill`,!0),l(`stroke`,r.stroke,o.stroke,`stroke`,!0),u(`style`,r.lineStyle,o.strokeStyle,[`solid`,`dash`,`none`],e=>gR(e===`none`?`noLine`:e),`strokeStyle`,e=>e===`none`?r.noLine:r[e]),u(`width`,r.thickness,String(o.strokeWidth),[`1`,`2`,`4`,`6`],e=>``,`strokeWidth`,e=>`${r.thickness} ${e}`,Number),d(`${r.scribbled}`,r.scribbled,o.rough,()=>{n.restyle({rough:!o.rough}),this.lastProps=``,this.refresh()}),l(`textColor`,r.textColor,o.textColor,`textColor`,!1);else if(o?.type===`connector`){u(`mode`,r.connector,o.mode,EF,gR,`mode`,e=>r[e]),l(`stroke`,r.stroke,o.stroke,`stroke`,!1),u(`style`,r.lineStyle,o.strokeStyle===`none`?`solid`:o.strokeStyle,[`solid`,`dash`],gR,`strokeStyle`,e=>r[e]);let e=e=>gR(e===`triangle`?`triangleEnd`:e===`diamond`?`diamondEnd`:e);u(`start`,r.startArrow,o.startArrow,DF,t=>`${e(t)}`,`startArrow`,e=>e),u(`end`,r.endArrow,o.endArrow,DF,e,`endArrow`,e=>e)}else o?.type===`brush`?l(`color`,r.stroke,o.color,`color`,!1):o?.type===`text`?(l(`color`,r.textColor,o.color,`color`,!1),u(`size`,r.fontSize,String(o.fontSize),[`16`,`24`,`32`,`48`,`64`],e=>`${e}`,`fontSize`,e=>`${r.fontSize} ${e}`,Number),u(`font`,r.font,o.font||`sans`,[`sans`,`serif`,`mono`],e=>`Aa`,`font`,e=>r[e],e=>e===`sans`?``:e),u(`align`,r.alignLeft,o.align,[`left`,`center`,`right`],e=>mR(`align-${e}`),`align`,e=>r[e===`left`?`alignLeft`:e===`center`?`alignCenter`:`alignRight`]),d(mR(`bold`),r.bold,o.bold,()=>{n.restyle({bold:!o.bold}),this.lastProps=``,this.refresh()})):o?.type===`note`||o?.type===`frame`?l(`bg`,r.background,o.background,`background`,!0):o?.type===`mindmap`?(u(`layout`,r.layout,o.layout,OF,e=>gR(e),`layout`,e=>r[e===`right`?`layoutRight`:e===`left`?`layoutLeft`:`layoutRadial`]),l(`color`,r.stroke,o.color,`color`,!1),n.activeNode?.map===o.id&&s.push(this.button(`+ ${r.addChild}`,r.addChild,()=>n.mindmapAdd(`child`),{cls:`dw-cv-wide`}))):o?.type===`embed`&&e.length===1&&s.push(this.button(mR(`open`),r.openLink,()=>window.open(o.url,`_blank`,`noopener,noreferrer`)));t.append(...s),i&&e.length===1&&t.append(a()),s.length&&t.append(this.sep());let f=e.filter(e=>e.type===`group`);e.length>1&&!f.length&&t.append(this.button(mR(`group`),r.group,()=>n.group())),f.length&&t.append(this.button(mR(`layers`),r.ungroup,()=>n.ungroup()));let p=e.every(e=>e.type===`note`&&e.page);t.append(this.button(mR(`arrow-up`),r.bringFront,()=>n.reorder(`front`)),this.button(mR(`send-back`),r.sendBack,()=>n.reorder(`back`))),p||t.append(this.button(mR(`copy`),r.duplicate,()=>n.duplicate()),this.button(mR(`trash`),r.delete,()=>n.deleteSelection(),{cls:`dw-cv-danger`}))}toast(e){let t=this.div(`dw-cv-ui dw-cv-toast`);t.setAttribute(`role`,`status`),t.textContent=e,this.v.root.append(t),setTimeout(()=>t.remove(),2600)}presentBar(){let e=this.v,t=e.labels,n=this.div(`dw-cv-ui dw-cv-presentbar`),r=this.div(`dw-cv-step`);return r.setAttribute(`aria-live`,`polite`),n.append(this.button(mR(`chevron-left`),t.presentPrevious,()=>e.presentStep(-1)),r,this.button(mR(`chevron-right`),t.presentNext,()=>e.presentStep(1)),this.button(mR(`close`),t.presentExit,()=>e.stopPresenting())),e.root.append(n),this.hidePop(),this.refresh(),n}presentStep(e,t){let n=this.v.root.querySelector(`.dw-cv-step`);n&&(n.textContent=this.v.labels.presentStep.replace(`{n}`,String(e+1)).replace(`{total}`,String(t)))}};function yR(e){let t=getComputedStyle(e),n=(e,n)=>t.getPropertyValue(e).trim()||n,r=n(`--dw-surface`,`#ffffff`),i=e=>{let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!t)return null;let n=t[1].length===3?[...t[1]].map(e=>e+e).join(``):t[1];return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))},a=(e,t,n)=>{let r=i(e),a=i(t);return!r||!a?e:`#${r.map((e,t)=>Math.round(e*n+a[t]*(1-n)).toString(16).padStart(2,`0`)).join(``)}`};return(e,t)=>{if(e===`none`)return`none`;if(e===`ink`)return t===`fill`?n(`--dw-surface-sunken`,`#f3f3f1`):n(`--dw-ink`,`#1d1f1e`);if(e===`paper`)return t===`fill`?n(`--dw-surface-raised`,`#ffffff`):r;let i=n(`--dw-c-${e}`,`#888888`);return t===`fill`?a(i,r,.22):i}}function bR(e){let t=[],n=e=>(e.content??[]).map(e=>e.type===`text`?e.text??``:e.type===`hardBreak`?` -`:n(e)).join(``),r=(e,i)=>{for(let a of e)if(a.type===`heading`){let e=Number(a.attrs?.level)||1;t.push({text:n(a),size:[0,26,21,18,16,16,16][e]??16,weight:650})}else if(a.type===`paragraph`)t.push({text:i+n(a),size:15,weight:400});else if(a.type===`listItem`||a.type===`taskItem`){let e=a.type===`taskItem`?a.attrs?.checked?`☑ `:`☐ `:`• `,[i,...o]=a.content??[];i&&t.push({text:e+n(i),size:15,weight:400}),r(o,` `)}else a.type===`codeBlock`?t.push({text:n(a),size:13,weight:400}):a.content?.length&&r(a.content,i)};return r(e,``),t}function xR(e,t,n,r,i,a,o=400,s=`start`){let c=Math.round(r*1.35);return n.map((n,l)=>`${WL(n)}`).join(``)}async function SR(e){if(e.startsWith(`data:`))return e;try{let t=await fetch(e,{credentials:`include`});if(!t.ok)return null;let n=await t.blob();return await new Promise(e=>{let t=new FileReader;t.onload=()=>e(typeof t.result==`string`?t.result:null),t.onerror=()=>e(null),t.readAsDataURL(n)})}catch{return null}}async function CR(e){let t=yR(e.root),n=e.elements.filter(e=>e.type!==`group`),r=QP(ZP(n.map(t=>e.boxOf(t)))??{x:0,y:0,w:400,h:300},32),i=t(`ink`,`line`),a=[];for(let r of n){let n=e.boxOf(r),o=r.rotate?` rotate(${r.rotate} ${n.w/2} ${n.h/2})`:``,s=e=>`${e}`;switch(r.type){case`shape`:{let e=sI(r.text,r.fontSize,Math.max(20,n.w-16)),i=Math.round(r.fontSize*1.35),o=n.h/2-e.length*i/2-r.fontSize*.25;a.push(s(QL(r,t)+(r.text?xR(n.w/2,o,e,r.fontSize,t(r.textColor,`line`),nI,400,`middle`):``)));break}case`text`:{let e=aI(r.font),i=r.w?sI(r.text,r.fontSize,r.w,e):r.text.split(` -`),o=r.align===`center`?n.w/2:r.align===`right`?n.w:0,c=r.align===`center`?`middle`:r.align===`right`?`end`:`start`;a.push(s(xR(o,0,i,r.fontSize,t(r.color,`line`),e,r.bold?650:400,c)));break}case`connector`:{let n=e.routeOf(r);if(a.push(eR(r,n,t)),r.label){let e=Math.min(240,r.label.length*8+16);a.push(``+xR(n.mid[0],n.mid[1]-12+3,[r.label],13,i,nI,400,`middle`))}break}case`brush`:a.push(s(nR(r,t)));break;case`frame`:a.push(s(``+xR(4,-24,[r.title],13,t(`gray`,`line`),nI,600)));break;case`note`:{let o=e.noteBody(r),c=o?bR(rR(o)):[],l=18,u=``;if(r.page&&e.pageTitle){let t=sI(e.pageTitle,26,n.w-48,nI,650);u+=xR(24,l-4,t,26,i,nI,650),l+=t.length*35+8}for(let e of c){let t=sI(e.text,e.size,n.w-48,nI,e.weight);if(u+=xR(24,l,t,e.size,i,nI,e.weight),l+=t.length*Math.round(e.size*1.35)+8,l>n.h-12)break}a.push(s(u));break}case`image`:{let i=await SR(e.resolve(r.src));a.push(s(i?``:``));break}case`embed`:a.push(s(``+xR(16,16,sI(r.url,13,n.w-32),13,t(`blue`,`line`),nI)));break;case`mindmap`:{let n=e.layoutOf(r),o=t(r.color,`line`),s=t(r.color,`fill`),c=n.edges.map(e=>``).join(``);for(let e of n.boxes.values()){let n=e.depth===0?18:15,a=e.depth===0?600:400,l=e.depth===0?o:e.depth===1?s:t(`paper`,`line`),u=e.depth===0?t(`paper`,`line`):i;c+=``;let d=sI(r.nodes[e.id]?.text||` `,n,260,nI,a);c+=xR(e.x+e.w/2,e.y+(e.h-d.length*Math.round(n*1.4))/2-2,d,n,u,nI,a,`middle`)}a.push(`${c}`);break}}}return{svg:`${a.join(``)}`,box:r}}async function wR(e,t){let{svg:n,box:r}=await CR(t),i=new Blob([n],{type:`image/svg+xml`});if(e===`svg`)return i;let a=Math.min(2,8192/Math.max(r.w,r.h,1)),o=URL.createObjectURL(i);try{let e=await new Promise((e,t)=>{let n=new Image;n.onload=()=>e(n),n.onerror=()=>t(Error(`could not draw the canvas`)),n.src=o}),t=document.createElement(`canvas`);t.width=Math.ceil(r.w*a),t.height=Math.ceil(r.h*a);let n=t.getContext(`2d`);if(!n)throw Error(`could not draw the canvas`);return n.drawImage(e,0,0,t.width,t.height),await new Promise((e,n)=>t.toBlob(t=>t?e(t):n(Error(`could not draw the canvas`)),`image/png`))}finally{URL.revokeObjectURL(o)}}var TR=.1,ER=4,DR=`http://www.w3.org/2000/svg`,OR=e=>e instanceof HTMLElement&&(e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`),kR=class{opts;store;labels;root;styles;editable;tool=`select`;shapeKind;selected=new Set;activeNode=null;editing=null;entered=null;world;overlay;ui;view={x:0,y:0,zoom:1};rendered=new Map;measured=new Map;layouts=new Map;routes=new Map;previews=new Map;drag=null;guides=[];marquee=null;hover=null;raf=0;spaceDown=!1;pointers=new Map;pinch=null;presenting=null;comments=[];activeComment=``;resize=typeof ResizeObserver>`u`?null:new ResizeObserver(e=>this.onResize(e));unsub;cleanups=[];saveTimer;constructor(e,t){this.opts=t,this.labels=t.labels??xF,this.editable=t.editable,this.styles=WF(t.styles),this.shapeKind=this.styles.shape.shape,this.store=new dR(t.doc,{undo:t.undo!==!1}),this.root=document.createElement(`div`),this.root.className=`dw-cv`,this.root.tabIndex=0,this.root.setAttribute(`role`,`application`),this.root.dataset.testid=`edgeless-canvas`,this.world=document.createElement(`div`),this.world.className=`dw-cv-world`,this.overlay=document.createElementNS(DR,`svg`),this.overlay.classList.add(`dw-cv-overlay`),this.root.append(this.world,this.overlay),e.append(this.root),this.ui=new vR(this),this.root.classList.toggle(`dw-cv-readonly`,!this.editable),this.unsub=this.store.onChange(()=>this.schedule()),this.listen(),this.render(),this.restoreView()||this.fit(void 0,!1),this.applyView()}destroy(){cancelAnimationFrame(this.raf),clearTimeout(this.saveTimer),this.saveView(),this.unsub(),this.resize?.disconnect();for(let e of this.cleanups)e();for(let e of this.rendered.values())e.note?.destroy();this.rendered.clear(),this.ui.destroy(),this.store.destroy(),this.root.remove()}setEditable(e){if(e!==this.editable){this.editable=e,this.root.classList.toggle(`dw-cv-readonly`,!e),e||(this.stopEditing(),this.tool=`select`);for(let t of this.rendered.values())t.note?.setEditable(e);this.ui.refresh()}}get(e){return this.store.get(e)}elements(){return this.store.elements()}boxOf(e){switch(e.type){case`note`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:e.w,h:t?.h??e.h}}case`text`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:t?.w??e.w,h:t?.h??e.h}}case`group`:return ZP(this.elements().filter(t=>t.group===e.id).map(e=>this.outerBox(e)))??{x:e.x,y:e.y,w:0,h:0};case`mindmap`:{let t=this.layoutOf(e);return{x:e.x+t.bounds.x,y:e.y+t.bounds.y,w:t.bounds.w,h:t.bounds.h}}case`connector`:{let t=this.routeOf(e),n=t.points.map(e=>e[0]),r=t.points.map(e=>e[1]);return tF([Math.min(...n),Math.min(...r)],[Math.max(...n),Math.max(...r)])}default:return{x:e.x,y:e.y,w:e.w,h:e.h}}}outerBox(e){let t=this.boxOf(e);return e.rotate?rF(t,e.rotate):t}layoutOf(e){let t=this.layouts.get(e.id),n=JSON.stringify([e.layout,e.nodes]);return t&&t.key===n||(t=pI(e.nodes,e.layout,cI),t.key=n,this.layouts.set(e.id,t)),t}routeOf(e){let t=uF(e,e=>{let t=this.get(e);return!t||t.type===`connector`?null:{box:this.outerBox(t),ellipse:t.type===`shape`&&t.shape===`ellipse`}});return mF(e.mode,t[0],t[1])}selection(){return[...this.selected].map(e=>this.get(e)).filter(e=>!!e)}expanded(e){let t=new Set,n=this.elements();for(let r of e){t.add(r);for(let e of n)e.group===r&&t.add(e.id)}return[...t]}schedule(){this.raf||=requestAnimationFrame(()=>{this.raf=0,this.render()})}render(){let e=this.elements(),t=new Set,n=null;for(let r of e){t.add(r.id);let e=this.rendered.get(r.id);e&&e.type!==r.type&&(e.note?.destroy(),e.el.remove(),e=void 0),e||(e={el:document.createElement(`div`),key:``,type:r.type},e.el.className=`dw-cv-el dw-cv-${r.type}`,e.el.dataset.id=r.id,this.rendered.set(r.id,e),(r.type===`note`||r.type===`text`)&&this.resize?.observe(e.el));let i=this.keyOf(r);e.key===i||this.editing?.id===r.id&&this.stopEditingFn&&r.type!==`note`||(this.draw(e,r),e.key=i),e.el.classList.toggle(`dw-cv-selected`,this.selected.has(r.id)),e.el.classList.toggle(`dw-cv-editing`,this.editing?.id===r.id);let a=n?n.nextElementSibling:this.world.firstElementChild;a!==e.el&&this.world.insertBefore(e.el,a),n=e.el}for(let[e,n]of this.rendered)t.has(e)||(n.note?.destroy(),this.resize?.unobserve(n.el),n.el.remove(),this.rendered.delete(e),this.measured.delete(e),this.selected.delete(e));this.editing&&!t.has(this.editing.id)&&(this.editing=null),this.drawOverlay(),this.ui.refresh()}keyOf(e){if(e.type===`connector`){let t=this.routeOf(e);return this.routes.set(e.id,t),JSON.stringify(e)+t.d}return e.type===`note`&&e.page?JSON.stringify(e)+(this.opts.pageTitle?.()??``):JSON.stringify(e)}place(e,t,n=0,r=!1){e.style.transform=`translate(${t.x}px, ${t.y}px)${n?` rotate(${n}deg)`:``}`,e.style.width=r?``:`${t.w}px`,e.style.height=r?``:`${t.h}px`}draw(e,t){let n=e.el,r=this.editing?.id===t.id;switch(t.type){case`shape`:{this.place(n,t,t.rotate);let e=r?n.querySelector(`.dw-cv-label`):null;n.innerHTML=`${QL(t,UL)}`;let i=e??document.createElement(`div`);i.className=`dw-cv-label`,e||(i.textContent=t.text),i.style.color=UL(t.textColor,`line`),i.style.fontSize=`${t.fontSize}px`,n.append(i);return}case`text`:{n.style.transform=`translate(${t.x}px, ${t.y}px)${t.rotate?` rotate(${t.rotate}deg)`:``}`,n.style.width=t.w?`${t.w}px`:``,n.style.height=``;let e=n.querySelector(`.dw-cv-textbody`);e||(e=document.createElement(`div`),e.className=`dw-cv-textbody`,n.append(e)),r||(e.textContent=t.text),e.dataset.placeholder=this.labels.textPlaceholder,Object.assign(e.style,{color:UL(t.color,`line`),fontSize:`${t.fontSize}px`,fontFamily:aI(t.font),textAlign:t.align,fontWeight:t.bold?`650`:``,whiteSpace:t.w?`pre-wrap`:`pre`});return}case`connector`:{let e=this.routes.get(t.id)??this.routeOf(t),i=this.boxOf(t),a=24+t.strokeWidth*3,o={x:i.x-a,y:i.y-a,w:i.w+a*2,h:i.h+a*2};this.place(n,o);let s=``,c=t.label||r;n.innerHTML=`${eR(t,e,UL)}${s}`+(c?`
${WL(t.label)}
`:``);return}case`brush`:this.place(n,t,t.rotate),n.innerHTML=`${nR(t,UL).replace(``;return;case`note`:this.drawNote(e,t);return;case`frame`:{this.place(n,t);let e=r?n.querySelector(`.dw-cv-frametitle`):null;n.innerHTML=``;let i=e??document.createElement(`div`);i.className=`dw-cv-frametitle`,e||(i.textContent=t.title||this.labels.frameTitle),n.append(i);return}case`image`:{this.place(n,t,t.rotate);let e=this.opts.files?.resolve(t.src)??t.src,r=n.querySelector(`img`);r||(r=document.createElement(`img`),r.draggable=!1,n.replaceChildren(r)),r.getAttribute(`src`)!==e&&(r.src=e),r.alt=t.alt;return}case`embed`:this.drawEmbed(n,t);return;case`group`:n.style.display=`none`;return;case`mindmap`:this.drawMindmap(n,t);return}}drawNote(e,t){let n=e.el;if(n.style.transform=`translate(${t.x}px, ${t.y}px)`,n.style.width=`${t.w}px`,n.style.height=``,n.style.setProperty(`--dw-cv-note-bg`,UL(t.background,`fill`)),n.classList.toggle(`dw-cv-pagenote`,t.page),!e.note){let r=document.createElement(`div`);r.className=`dw-cv-notehead`;let i=document.createElement(`div`);i.className=`dw-cv-notebody`,n.replaceChildren(r,i);let a=t.page?this.opts.doc.getXmlFragment(`default`):this.store.body(t.id);if(a)try{e.note=this.opts.notes.mount(i,{id:t.id,page:t.page,fragment:a,doc:this.opts.doc,editable:this.editable})}catch(e){this.opts.onError?.(e)}}let r=n.querySelector(`.dw-cv-notehead`);r&&(r.textContent=t.page?this.opts.pageTitle?.()||this.labels.pageNote:``)}drawEmbed(e,t){this.place(e,t);let n=this.opts.embedSource?.(t.url)??null;if(n){if(e.querySelector(`iframe`)?.getAttribute(`src`)===n.src)return;let r=document.createElement(`iframe`);r.src=n.src,r.title=t.url,r.allow=`fullscreen; picture-in-picture; encrypted-media`,r.referrerPolicy=`strict-origin-when-cross-origin`,r.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`),e.replaceChildren(r);return}let r=this.previews.get(t.url);r===void 0&&this.opts.links&&(this.previews.set(t.url,`loading`),this.opts.links.preview(t.url).then(e=>this.previews.set(t.url,e)).catch(()=>this.previews.set(t.url,null)).finally(()=>{let e=this.rendered.get(t.id);e&&(e.key=``),this.schedule()}),r=`loading`);let i=r&&r!==`loading`?r:null,a=t.url;try{a=new URL(t.url).hostname}catch{}let o=i?.image?``:``;e.innerHTML=`${o}${WL(i?.title||a)}${i?.description?`${WL(i.description)}`:``}${WL(i?.site||a)}`}drawMindmap(e,t){let n=this.layoutOf(t),r=n.bounds;this.place(e,{x:t.x+r.x,y:t.y+r.y,w:r.w,h:r.h});let i=UL(t.color,`line`),a=UL(t.color,`fill`),o=n.edges.map(e=>``).join(``),s=this.editing?.id===t.id?this.editing.node:void 0,c=s?e.querySelector(`[data-node="${s}"]`):null,l=[...n.boxes.values()].map(e=>{let n=e.depth===0?`dw-cv-node dw-cv-root`:`dw-cv-node`,o=this.activeNode?.map===t.id&&this.activeNode.node===e.id?` dw-cv-active`:``,s=`left:${e.x-r.x}px;top:${e.y-r.y}px;width:${e.w}px;height:${e.h}px;${e.depth===0?`background:${i};color:var(--dw-surface)`:e.depth===1?`background:${a};border-color:${i}`:`border-color:${i}`}`;return`
${WL(t.nodes[e.id]?.text??``)}
`});e.innerHTML=`${o}${l.join(``)}`,c&&s&&e.querySelector(`[data-node="${s}"]`)?.replaceWith(c)}onResize(e){let t=!1;for(let n of e){let e=n.target,r=e.dataset.id;if(!r)continue;let i={w:e.offsetWidth,h:e.offsetHeight},a=this.measured.get(r);a&&a.w===i.w&&a.h===i.h||(this.measured.set(r,i),t=!0)}if(t){for(let e of this.rendered.values())e.type===`connector`&&(e.key=``);this.schedule()}}toScreen([e,t]){return[e*this.view.zoom+this.view.x,t*this.view.zoom+this.view.y]}toWorld(e,t){let n=this.root.getBoundingClientRect();return[(e-n.left-this.view.x)/this.view.zoom,(t-n.top-this.view.y)/this.view.zoom]}get zoom(){return this.view.zoom}selectionScreenBox(){let e=ZP(this.selection().map(e=>this.outerBox(e)));if(!e)return null;let[t,n]=this.toScreen([e.x,e.y]);return{x:t,y:n,w:e.w*this.view.zoom,h:e.h*this.view.zoom}}drawOverlay(){let e=[],t=this.view.zoom,n=(e,t)=>{let n=XP(e);return[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>this.toScreen(nF(e,n,t)).join(`,`)).join(` `)};if(this.entered){let t=this.get(this.entered);t&&e.push(``)}if(this.hover&&this.hover!==this.editing?.id){let t=this.get(this.hover);t&&e.push(``)}let r=this.presenting?[]:this.selection();for(let t of r)if(t.type===`connector`){let n=this.routes.get(t.id)??this.routeOf(t);e.push(``)}else e.push(``);if(this.editable&&!this.presenting&&r.length&&!this.editing){let i=r.length===1?r[0]:null;if(i?.type===`connector`){let t=this.routes.get(i.id)??this.routeOf(i);for(let[n,r]of[[`source`,t.points[0]],[`target`,t.points[t.points.length-1]]]){let[t,i]=this.toScreen(r);e.push(``)}}else if(r.some(RF)&&i?.type!==`mindmap`){let a=i?i.rotate:0,o=i?this.boxOf(i):ZP(r.map(e=>this.outerBox(e)));r.length>1&&e.push(``);let s=XP(o),c=[[`nw`,[o.x,o.y]],[`n`,[o.x+o.w/2,o.y]],[`ne`,[o.x+o.w,o.y]],[`e`,[o.x+o.w,o.y+o.h/2]],[`se`,[o.x+o.w,o.y+o.h]],[`s`,[o.x+o.w/2,o.y+o.h]],[`sw`,[o.x,o.y+o.h]],[`w`,[o.x,o.y+o.h/2]]],l=i?.type===`note`;for(let[n,r]of c){if(l&&n!==`e`&&n!==`w`||o.w*t<24&&(n===`n`||n===`s`)||o.h*t<24&&(n===`e`||n===`w`))continue;let[i,c]=this.toScreen(nF(r,s,a));e.push(``)}if(i&&zF(i)){let[n,r]=this.toScreen(nF([o.x+o.w/2,o.y-28/t],s,a));e.push(``)}}}if(this.presenting||this.drawComments(e,n),this.marquee){let[n,r]=this.toScreen([this.marquee.x,this.marquee.y]);e.push(``)}for(let t of this.guides){let n=this.toScreen(t.axis===`x`?[t.value,t.from]:[t.from,t.value]),r=this.toScreen(t.axis===`x`?[t.value,t.to]:[t.to,t.value]);e.push(``)}this.overlay.innerHTML=e.join(``),this.ui.place()}applyView(){let{x:e,y:t,zoom:n}=this.view;this.world.style.transform=`translate(${e}px, ${t}px) scale(${n})`;let r=24*n;this.root.style.backgroundSize=`${r}px ${r}px`,this.root.style.backgroundPosition=`${e}px ${t}px`,this.root.style.setProperty(`--dw-cv-zoom`,String(n)),this.drawOverlay(),this.ui.zoomChanged(),clearTimeout(this.saveTimer),this.saveTimer=setTimeout(()=>this.saveView(),500)}saveView(){if(this.opts.viewKey)try{localStorage.setItem(this.opts.viewKey,JSON.stringify(this.view))}catch{}}restoreView(){if(!this.opts.viewKey)return!1;try{let e=JSON.parse(localStorage.getItem(this.opts.viewKey)??`null`);if(e&&[e.x,e.y,e.zoom].every(e=>typeof e==`number`&&Number.isFinite(e))&&e.zoom>0)return this.view={x:e.x,y:e.y,zoom:Math.min(ER,Math.max(TR,e.zoom))},!0}catch{}return!1}zoomAt(e,t){let n=Math.min(ER,Math.max(TR,e)),r=this.root.getBoundingClientRect(),[i,a]=t??[r.width/2,r.height/2],o=(i-this.view.x)/this.view.zoom,s=(a-this.view.y)/this.view.zoom;this.view={zoom:n,x:i-o*n,y:a-s*n},this.applyView()}zoomBy(e){this.zoomAt(this.view.zoom*e)}fit(e,t=!0,n=48){let r=e??ZP(this.elements().map(e=>this.outerBox(e))),i=this.root.getBoundingClientRect(),a=i.width||800,o=i.height||600;if(!r)this.view={x:a/2,y:o/3,zoom:1};else{let t=Math.min(ER,Math.max(TR,Math.min((a-n*2)/Math.max(r.w,1),(o-n*2)/Math.max(r.h,1),e?ER:1)));this.view={zoom:t,x:a/2-(r.x+r.w/2)*t,y:o/2-(r.y+r.h/2)*t},!e&&r.h*t>o&&(this.view.y=n-r.y*t)}t&&this.applyView()}animateTo(e){let t={...this.view},n=performance.now(),r=i=>{let a=Math.min(1,(i-n)/350),o=1-(1-a)**3;this.view={x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o,zoom:t.zoom+(e.zoom-t.zoom)*o},this.applyView(),a<1&&requestAnimationFrame(r)};requestAnimationFrame(r)}setTool(e){(this.editable||e===`select`||e===`hand`)&&(this.stopEditing(),this.tool=e,e!==`select`&&this.clearSelection(),this.root.dataset.tool=e,this.ui.refresh())}setShapeKind(e){this.shapeKind=e,this.setStyle(`shape`,{shape:e}),this.setTool(`shape`)}setStyle(e,t){this.styles={...this.styles,[e]:{...this.styles[e],...t}},this.opts.onStyles?.(this.styles)}restyle(e){let t=[];for(let n of this.selection()){let r=Object.fromEntries(Object.entries(e).filter(([e])=>e in n));if(!Object.keys(r).length)continue;t.push([n.id,r]);let i=n.type;if(i in this.styles){let e=Object.fromEntries(Object.entries(r).filter(([e])=>e in this.styles[i]));Object.keys(e).length&&!(n.type===`note`&&n.page)&&this.setStyle(i,e)}}this.store.updateMany(t)}select(e,t=!1){t||this.selected.clear();for(let t of e)this.selected.add(t);this.activeNode&&!this.selected.has(this.activeNode.map)&&(this.activeNode=null),this.refreshSelection()}clearSelection(){(this.selected.size||this.activeNode||this.entered)&&(this.selected.clear(),this.activeNode=null,this.entered=null,this.refreshSelection())}refreshSelection(){for(let[e,t]of this.rendered)t.el.classList.toggle(`dw-cv-selected`,this.selected.has(e)),t.type===`mindmap`&&(t.key=``);this.schedule(),this.drawOverlay(),this.ui.refresh()}pick(e){let t=this.get(e);return t?.group&&this.entered!==t.group&&this.get(t.group)?t.group:e}hit(e){if(!(e instanceof Element)||!this.world.contains(e))return null;let t=e.closest(`[data-id]`);if(!t?.dataset.id)return null;let n=e.closest(`[data-node]`)?.dataset.node;return{id:t.dataset.id,node:n}}connectableAt(e,t,n){for(let r of document.elementsFromPoint(e,t)){let e=this.hit(r);if(!e||n.has(e.id))continue;let t=this.get(e.id);if(t&&BF(t))return t}return null}listen(){let e=(e,t,n,r)=>{e.addEventListener(t,n,r),this.cleanups.push(()=>e.removeEventListener(t,n,r))};e(this.root,`pointerdown`,e=>this.onDown(e)),e(this.root,`pointermove`,e=>this.onMove(e)),e(this.root,`pointerup`,e=>this.onUp(e)),e(this.root,`pointercancel`,e=>this.onUp(e)),e(this.root,`dblclick`,e=>this.onDouble(e)),e(this.root,`wheel`,e=>this.onWheel(e),{passive:!1}),e(this.root,`keydown`,e=>this.onKey(e)),e(this.root,`keyup`,e=>{e.key===` `&&(this.spaceDown=!1,this.root.classList.remove(`dw-cv-panning`))}),e(document,`copy`,e=>this.onCopy(e,!1)),e(document,`cut`,e=>this.onCopy(e,!0)),e(document,`paste`,e=>this.onPaste(e)),e(this.root,`dragover`,e=>{this.editable&&e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()}),e(this.root,`drop`,e=>{let t=[...e.dataTransfer?.files??[]].filter(e=>e.type.startsWith(`image/`));this.editable&&t.length&&(e.preventDefault(),this.addImages(t,this.toWorld(e.clientX,e.clientY)))}),e(document,`fullscreenchange`,()=>{!document.fullscreenElement&&this.presenting&&this.stopPresenting()}),e(this.root,`click`,e=>{e.target.closest?.(`a.dw-cv-card`)&&this.editable&&e.preventDefault()})}inEditor(e){if(!(e instanceof Element))return!1;if(e.closest(`.dw-cv-ui`))return!0;if(this.editing){let t=this.rendered.get(this.editing.id);if(t&&t.el.contains(e)&&(e.closest(`[contenteditable=true]`)||e.closest(`.dw-cv-notebody`)||e.closest(`iframe`)))return!0}return!(this.editable||!e.closest(`.dw-cv-notebody, a.dw-cv-card`))}onDown(e){let t=e.target instanceof Element?e.target.closest(`[data-comment]`):null;if(t?.dataset.comment){e.preventDefault(),this.opts.onCommentSelect?.(t.dataset.comment);return}if(this.inEditor(e.target)||e.button===2)return;if(e.preventDefault(),this.root.focus({preventScroll:!0}),this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pointers.size===2){this.cancelDrag();let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect();this.pinch={dist:Math.hypot(e[0]-t[0],e[1]-t[1]),mid:[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],zoom:this.view.zoom,vx:this.view.x,vy:this.view.y};return}if(this.pointers.size>2)return;this.editing&&this.stopEditing();let n=this.toWorld(e.clientX,e.clientY),r=e.pointerType===`touch`,i=()=>{this.drag={kind:`pan`,sx:e.clientX,sy:e.clientY,vx:this.view.x,vy:this.view.y},this.root.classList.add(`dw-cv-panning`)};if(this.root.setPointerCapture?.(e.pointerId),e.button===1||this.tool===`hand`||this.spaceDown||this.presenting)return e.preventDefault(),i();let a=e.target;if(!this.editable){let e=this.opts.onComment&&this.tool===`select`?this.hit(a):null;if(e){let t=this.pick(e.id);this.select([t]);return}return i()}switch(this.tool){case`pen`:{let t=document.createElementNS(DR,`svg`);t.classList.add(`dw-cv-temp`),this.world.append(t),this.drag={kind:`pen`,points:[[n[0],n[1],e.pressure||.5]],temp:t};return}case`eraser`:this.drag={kind:`erase`,hits:new Set},this.erase(e);return;case`shape`:case`frame`:this.drag={kind:`create`,type:this.tool,start:n,id:null};return;case`connector`:{let t=this.connectableAt(e.clientX,e.clientY,new Set),r=t?this.endOn(t,n):{x:n[0],y:n[1]},i=this.store.add({type:`connector`,...this.styles.connector,source:r,target:{x:n[0],y:n[1]}});this.drag={kind:`end`,id:i,side:`target`};return}case`note`:this.addNote(n);return;case`text`:this.addText(n);return;case`mindmap`:this.addMindmap(n);return}let o=a.dataset?.handle,s=a.dataset?.end;if(s){let e=this.selection()[0];e?.type===`connector`&&(this.store.undo?.stopCapturing(),this.drag={kind:`end`,id:e.id,side:s});return}if(o===`rotate`){let e=this.selection()[0],t=XP(this.boxOf(e));this.store.undo?.stopCapturing(),this.drag={kind:`rotate`,id:e.id,c:t,a0:Math.atan2(n[1]-t[1],n[0]-t[0]),r0:e.rotate};return}if(o){let e=this.selection(),t=e.length===1?e[0]:null,n=new Map(this.expanded(this.selected).map(e=>[e,this.get(e)]));for(let[e,t]of n){let r=this.measured.get(e);t.type===`text`&&r&&n.set(e,{...t,w:r.w,h:r.h}),t.type===`note`&&r&&n.set(e,{...t,h:r.h})}this.store.undo?.stopCapturing(),this.drag={kind:`resize`,handle:o,box:t?this.boxOf(t):ZP(e.map(e=>this.outerBox(e))),deg:t?t.rotate:0,orig:n,keep:e.some(e=>e.type===`image`||e.type===`text`||e.type===`brush`)||e.length>1};return}let c=this.hit(a);if(c){let t=this.pick(c.id),r=this.get(t);if(r?.type===`mindmap`&&c.node){this.activeNode={map:t,node:c.node};let e=this.rendered.get(t);e&&(e.key=``)}else r?.type!==`mindmap`&&(this.activeNode=null);e.shiftKey?(this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.refreshSelection()):this.selected.has(t)?this.refreshSelection():this.select([t]),this.startMove(n,t)}else{if(r)return i();this.entered=null,this.drag={kind:`marquee`,start:n,add:e.shiftKey,base:e.shiftKey?new Set(this.selected):new Set},e.shiftKey||this.clearSelection()}}startMove(e,t){let n=this.expanded(this.selected);for(let e of[...n]){let t=this.get(e);if(t?.type===`frame`)for(let e of this.elements())e.type!==`frame`&&!n.includes(e.id)&&eF(t,this.outerBox(e))&&n.push(...this.expanded([e.id]))}let r=[...new Set(n)].filter(e=>this.get(e)?.type!==`group`),i=new Map(r.map(e=>[e,this.get(e)])),a=ZP(r.map(e=>this.outerBox(this.get(e))))??{x:e[0],y:e[1],w:0,h:0};this.store.undo?.stopCapturing(),this.drag={kind:`move`,start:e,ids:r,orig:i,box:a,moved:!1,clickId:t}}endOn(e,t){let n=this.outerBox(e),r=bF(n,t,14/this.view.zoom);return r?{id:e.id,pos:[(r[0]-n.x)/Math.max(n.w,1),(r[1]-n.y)/Math.max(n.h,1)]}:{id:e.id}}onMove(e){if(this.pointers.has(e.pointerId)&&this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pinch&&this.pointers.size>=2){let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect(),r=Math.hypot(e[0]-t[0],e[1]-t[1]),i=[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],a=this.pinch,o=Math.min(ER,Math.max(TR,a.zoom*r/Math.max(a.dist,1))),s=(a.mid[0]-a.vx)/a.zoom,c=(a.mid[1]-a.vy)/a.zoom;this.view={zoom:o,x:i[0]-s*o,y:i[1]-c*o},this.applyView();return}let t=this.drag,n=this.toWorld(e.clientX,e.clientY);if(t)switch(t.kind){case`pan`:this.view={...this.view,x:t.vx+e.clientX-t.sx,y:t.vy+e.clientY-t.sy},this.applyView();return;case`move`:{let r=n[0]-t.start[0],i=n[1]-t.start[1];if(!t.moved&&Math.hypot(r,i)*this.view.zoom<3)return;if(t.moved=!0,e.altKey)this.guides=[];else{let e=new Set(t.ids),n=this.visibleBoxes().filter(([t])=>!e.has(t)).map(([,e])=>e),a=yF({...t.box,x:t.box.x+r,y:t.box.y+i},n,6/this.view.zoom);r+=a.dx,i+=a.dy,this.guides=a.guides}let a=[];for(let[e,n]of t.orig)if(n.type===`connector`){let t={};for(let e of[`source`,`target`]){let a=n[e];a.id||(t[e]={x:(a.x??0)+r,y:(a.y??0)+i})}Object.keys(t).length&&a.push([e,t])}else a.push([e,{x:n.x+r,y:n.y+i}]);this.store.updateMany(a);return}case`marquee`:{this.marquee=tF(t.start,n);let e=new Set(t.base),r=this.marquee;for(let t of this.elements()){if(t.group&&this.get(t.group))continue;let n=this.outerBox(t);(t.type===`frame`?eF(r,n):$P(r,n))&&e.add(t.id)}for(let t of this.elements().filter(e=>e.type===`group`))$P(r,this.boxOf(t))&&e.add(t.id);this.selected.clear();for(let t of e)this.selected.add(t);this.refreshSelection();return}case`resize`:this.doResize(t,n,e.shiftKey);return;case`rotate`:{let r=t.r0+(Math.atan2(n[1]-t.c[1],n[0]-t.c[0])-t.a0)*180/Math.PI;e.shiftKey&&(r=Math.round(r/15)*15),r=(r%360+360)%360,this.store.update(t.id,{rotate:Math.round(r*10)/10});return}case`create`:{let r=tF(t.start,n);if(!t.id&&r.w*this.view.zoom<4&&r.h*this.view.zoom<4)return;e.shiftKey&&(r.w=r.h=Math.max(r.w,r.h)),t.id?this.store.update(t.id,{...r}):t.id=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...r}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...r});return}case`end`:{let r=this.get(t.id);if(r?.type!==`connector`)return;let i=r[t.side===`source`?`target`:`source`],a=new Set([t.id]),o=this.connectableAt(e.clientX,e.clientY,a);this.hover=o?.id??null;let s=o&&o.id!==i.id?this.endOn(o,n):{x:n[0],y:n[1]};this.store.update(t.id,{[t.side]:s});return}case`pen`:t.points.push([n[0],n[1],e.pressure||.5]),t.temp.innerHTML=``;return;case`erase`:this.erase(e);return}else if(this.editable&&this.tool===`connector`){let t=this.connectableAt(e.clientX,e.clientY,new Set);(t?.id??null)!==this.hover&&(this.hover=t?.id??null,this.drawOverlay())}}erase(e){let t=this.drag;if(t?.kind!==`erase`)return;let n=this.toWorld(e.clientX,e.clientY),r=6/this.view.zoom;for(let n of document.elementsFromPoint(e.clientX,e.clientY)){let e=this.hit(n);if(!e)continue;let r=this.get(e.id);r&&r.type!==`note`&&r.type!==`frame`&&(t.hits.add(r.id),this.rendered.get(r.id)?.el.classList.add(`dw-cv-erasing`))}for(let e of this.elements())e.type!==`brush`||t.hits.has(e.id)||aF(n,e.points.map(t=>[t[0]+e.x,t[1]+e.y]))<=r+e.size/2&&(t.hits.add(e.id),this.rendered.get(e.id)?.el.classList.add(`dw-cv-erasing`))}doResize(e,t,n){let r=e.box,i=XP(r),a=nF(t,i,-e.deg),o=r.x,s=r.y,c=r.x+r.w,l=r.y+r.h;e.handle.includes(`w`)&&(o=a[0]),e.handle.includes(`e`)&&(c=a[0]),e.handle.includes(`n`)&&(s=a[1]),e.handle.includes(`s`)&&(l=a[1]);let u=8/this.view.zoom;c-o[e[0]*m,e[1]*h,e[2]??.5])}]);break;case`mindmap`:case`group`:v.push([t,{x:e,y:i}]);break;default:v.push([t,{x:e,y:i,w:n.w*m,h:n.h*h}])}}this.store.updateMany(v)}visibleBoxes(){let e=this.root.getBoundingClientRect(),t=tF(this.toWorld(e.left,e.top),this.toWorld(e.right,e.bottom)),n=[];for(let e of this.elements()){if(e.type===`connector`||e.type===`group`)continue;let r=this.outerBox(e);if($P(t,r)&&n.push([e.id,r]),n.length>300)break}return n}onUp(e){if(this.pointers.delete(e.pointerId),this.pinch){this.pointers.size<2&&(this.pinch=null);return}let t=this.drag;if(this.drag=null,this.root.classList.remove(`dw-cv-panning`),this.guides=[],this.marquee=null,this.hover=null,!t)return;let n=this.toWorld(e.clientX,e.clientY);switch(t.kind){case`create`:{let e=t.id;if(!e){let r=t.type===`frame`?{w:800,h:600}:{w:140,h:100},i={x:n[0]-r.w/2,y:n[1]-r.h/2,...r};e=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...i}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...i})}this.tool=`select`,this.root.dataset.tool=`select`,this.select([e]);break}case`end`:{let e=this.get(t.id);if(e?.type===`connector`){let n=this.routeOf(e),r=n.points[0],i=n.points[n.points.length-1];Math.hypot(r[0]-i[0],r[1]-i[1])*this.view.zoom<8&&this.tool===`connector`?this.store.remove([t.id]):this.tool===`connector`&&this.select([t.id])}break}case`pen`:{t.temp.remove(),t.points.length<2&&t.points.push([t.points[0][0]+.5,t.points[0][1]+.5,.5]);let e=t.points.map(e=>e[0]),n=t.points.map(e=>e[1]),r=this.styles.brush.size,i=Math.min(...e)-r,a=Math.min(...n)-r,o=Math.max(...e)+r-i,s=Math.max(...n)+r-a;this.store.add({type:`brush`,...this.styles.brush,x:i,y:a,w:o,h:s,points:t.points.map(e=>[Math.round((e[0]-i)*10)/10,Math.round((e[1]-a)*10)/10,Math.round((e[2]??.5)*100)/100])});break}case`erase`:for(let e of t.hits)this.rendered.get(e)?.el.classList.remove(`dw-cv-erasing`);t.hits.size&&this.store.remove(t.hits)}this.drawOverlay(),this.ui.refresh()}cancelDrag(){let e=this.drag;e?.kind===`pen`&&e.temp.remove(),this.drag=null,this.marquee=null,this.guides=[]}onDouble(e){if(this.inEditor(e.target)||!this.editable||this.tool!==`select`)return;let t=this.hit(e.target);if(!t){this.addText(this.toWorld(e.clientX,e.clientY));return}let n=this.get(t.id);n&&(n.group&&this.entered!==n.group&&this.get(n.group)?(this.entered=n.group,this.select([n.id])):(n.type!==`frame`||e.target.closest(`.dw-cv-frametitle`))&&this.startEdit(n.id,t.node))}onWheel(e){if(this.presenting||e.target instanceof Element&&e.target.closest(`.dw-cv-ui`))return;e.preventDefault();let t=this.root.getBoundingClientRect();if(e.ctrlKey||e.metaKey){this.zoomAt(this.view.zoom*Math.exp(-e.deltaY*.01),[e.clientX-t.left,e.clientY-t.top]);return}let n=e.deltaMode===1?16:1,r=e.shiftKey&&!e.deltaX?e.deltaY:e.deltaX,i=e.shiftKey&&!e.deltaX?0:e.deltaY;this.view={...this.view,x:this.view.x-r*n,y:this.view.y-i*n},this.applyView()}onKey(e){if(this.presenting){this.presentKey(e);return}if(OR(e.target)||this.inEditor(e.target))return;let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(e.key===` `&&!t){this.spaceDown=!0,this.root.classList.add(`dw-cv-panning`),e.preventDefault();return}if(t&&(n===`=`||n===`+`))return e.preventDefault(),this.zoomBy(1.25);if(t&&n===`-`)return e.preventDefault(),this.zoomBy(.8);if(e.altKey&&!t&&(e.code===`Digit0`||e.code===`Digit1`||e.code===`Digit2`)){if(e.preventDefault(),e.code===`Digit0`)return this.zoomAt(1);if(e.code===`Digit1`)return this.fit();let t=ZP(this.selection().map(e=>this.outerBox(e)));return this.fit(t??void 0)}if(e.key===`Escape`){this.entered?(this.select([this.entered]),this.entered=null):this.selected.size?this.clearSelection():this.setTool(`select`);return}if(!this.editable){!t&&n===`h`&&this.setTool(`hand`),!t&&n===`v`&&this.setTool(`select`);return}if(this.activeNode&&this.mindmapKey(e))return;if(t&&n===`z`){e.preventDefault(),e.shiftKey?this.store.undo?.redo():this.store.undo?.undo();return}if(t&&n===`y`){e.preventDefault(),this.store.undo?.redo();return}if(t&&n===`a`){e.preventDefault(),this.select(this.elements().filter(e=>!e.group||!this.get(e.group)).map(e=>e.id));return}if(t&&n===`d`){e.preventDefault(),this.duplicate();return}if(t&&n===`g`){e.preventDefault(),e.shiftKey?this.ungroup():this.group();return}if((e.key===`Delete`||e.key===`Backspace`)&&this.selected.size){e.preventDefault(),this.deleteSelection();return}if(e.key===`Enter`&&this.selected.size===1){e.preventDefault();let t=[...this.selected][0];this.startEdit(t);return}if(e.key.startsWith(`Arrow`)&&this.selected.size){e.preventDefault();let t=e.shiftKey?10:1,n=e.key===`ArrowLeft`?-t:e.key===`ArrowRight`?t:0,r=e.key===`ArrowUp`?-t:e.key===`ArrowDown`?t:0;this.nudge(n,r);return}if(t||e.altKey)return;let r={v:`select`,h:`hand`,n:`note`,t:`text`,s:`shape`,c:`connector`,p:`pen`,e:`eraser`,f:`frame`,m:`mindmap`};r[n]?(e.preventDefault(),this.setTool(r[n])):n===`i`?this.ui.pickImage():n===`l`&&this.addLink()}nudge(e,t){let n=this.expanded(this.selected),r=[];for(let i of n){let n=this.get(i);if(n&&n.type!==`group`){if(n.type===`connector`){let a={};for(let r of[`source`,`target`]){let i=n[r];i.id||(a[r]={x:(i.x??0)+e,y:(i.y??0)+t})}r.push([i,a])}else r.push([i,{x:n.x+e,y:n.y+t}])}}this.store.updateMany(r)}startEdit(e,t){if(!this.editable)return;let n=this.get(e),r=this.rendered.get(e);if(n&&r){if(n.type===`group`)this.entered=e;else if(n.type===`mindmap`){let i=t??(this.activeNode?.map===e?this.activeNode.node:dI(n.nodes));if(!i)return;this.activeNode={map:e,node:i},this.editing={id:e,node:i},this.draw(r,n);let a=r.el.querySelector(`[data-node="${i}"]`);a&&this.editText(a,n.nodes[i]?.text??``,!0,t=>this.store.updateNode(e,i,{text:t}))}else if(n.type!==`image`&&n.type!==`brush`)switch(this.select([e]),this.editing={id:e,node:t},r.el.classList.add(`dw-cv-editing`),this.drawOverlay(),this.ui.refresh(),n.type){case`note`:r.note?.focus();return;case`embed`:return;case`text`:{let t=r.el.querySelector(`.dw-cv-textbody`);t&&this.editText(t,n.text,!1,t=>t.trim()?this.store.update(e,{text:t}):this.store.remove([e]));return}case`shape`:{let t=r.el.querySelector(`.dw-cv-label`);t&&this.editText(t,n.text,!1,t=>this.store.update(e,{text:t}));return}case`frame`:{let t=r.el.querySelector(`.dw-cv-frametitle`);t&&this.editText(t,n.title,!0,t=>this.store.update(e,{title:t}));return}case`connector`:{this.draw(r,n);let t=r.el.querySelector(`.dw-cv-clabel`);t&&this.editText(t,n.label,!0,t=>this.store.update(e,{label:t}));return}}}}editText(e,t,n,r){e.contentEditable=`true`,e.spellcheck=!0,e.textContent=t,e.classList.add(`dw-cv-typing`);let i=!1,a=n=>{if(i)return;i=!0,this.stopEditingFn=null,e.contentEditable=`false`,e.classList.remove(`dw-cv-typing`),e.removeEventListener(`keydown`,o),e.removeEventListener(`blur`,s),e.removeEventListener(`paste`,c);let a=(e.innerText??e.textContent??``).replace(/\n$/,``),l=this.editing?.id;if(this.editing=null,(n&&a!==t||n&&!a.trim())&&r(a),l){let e=this.rendered.get(l);e&&(e.key=``)}this.schedule(),this.ui.refresh()},o=e=>{e.stopPropagation(),e.key===`Escape`||e.key===`Enter`&&(n||e.ctrlKey||e.metaKey)&&!e.shiftKey?(e.preventDefault(),a(!0),this.root.focus({preventScroll:!0})):e.key===`Tab`&&this.activeNode&&(e.preventDefault(),a(!0),this.mindmapAdd(`child`))},s=()=>a(!0),c=e=>{e.preventDefault(),e.stopPropagation(),document.execCommand(`insertText`,!1,e.clipboardData?.getData(`text/plain`)??``)};e.addEventListener(`keydown`,o),e.addEventListener(`blur`,s),e.addEventListener(`paste`,c),this.stopEditingFn=()=>a(!0),e.focus({preventScroll:!0});let l=document.createRange();l.selectNodeContents(e);let u=getSelection();u?.removeAllRanges(),u?.addRange(l)}stopEditingFn=null;stopEditing(){let e=this.stopEditingFn;if(this.stopEditingFn=null,e?.(),this.editing){let e=this.rendered.get(this.editing.id);e?.el.classList.remove(`dw-cv-editing`),e?.note&&document.activeElement&&e.el.contains(document.activeElement)&&document.activeElement.blur(),this.editing=null,this.drawOverlay(),this.ui.refresh()}}frameName(){let e=this.elements().filter(e=>e.type===`frame`).length+1;return`${this.labels.frameTitle} ${e}`}addNote(e){let t=this.store.add({type:`note`,...this.styles.note,x:e[0]-24,y:e[1]-24,w:320,h:120});this.setTool(`select`),this.select([t]),this.render(),this.startEdit(t)}addText(e){let t=this.store.add({type:`text`,...this.styles.text,x:e[0],y:e[1]-this.styles.text.fontSize*.7,w:0,h:0,text:``});this.setTool(`select`),this.render(),this.startEdit(t)}addMindmap(e){let t=`r${Date.now().toString(36)}`,n=this.store.add({type:`mindmap`,...this.styles.mindmap,x:e[0],y:e[1],nodes:{[t]:{text:this.labels.centralIdea,parent:``,pos:0}}});this.setTool(`select`),this.select([n]),this.activeNode={map:n,node:t},this.render(),this.startEdit(n,t)}viewCentre(){let e=this.root.getBoundingClientRect();return this.toWorld(e.left+e.width/2,e.top+e.height/2)}async addImages(e,t){let n=this.opts.files?.upload;if(!n)return;let[r,i]=t??this.viewCentre(),a=[];for(let t of e)try{let e=await n.call(this.opts.files,t),o=await AR(this.opts.files?.resolve(e.url)??e.url),s=Math.min(1,480/Math.max(o.w,1)),c=o.w*s,l=o.h*s;a.push(this.store.add({type:`image`,src:e.url,alt:e.name,x:r-c/2,y:i-l/2,w:c,h:l})),r+=24,i+=24}catch(e){this.opts.onError?.(e)}a.length&&this.select(a)}async addLink(e,t){let n=(e??window.prompt(this.labels.linkPrompt,`https://`))?.trim();if(!n||!/^https?:\/\//i.test(n))return;let[r,i]=t??this.viewCentre(),a=this.opts.embedSource?.(n),o=a?560:380,s=a?a.ratio===`video`?315:420:120,c=this.store.add({type:`embed`,url:n,x:r-o/2,y:i-s/2,w:o,h:s});this.setTool(`select`),this.select([c])}insertElements(e){let t=ZP(e.map(e=>({x:Number(e.x)||0,y:Number(e.y)||0,w:Number(e.w)||0,h:Number(e.h)||0})))??{x:0,y:0,w:0,h:0},[n,r]=this.viewCentre(),i=this.store.insertJSON(e,n-(t.x+t.w/2),r-(t.y+t.h/2));this.setTool(`select`),this.select(i.filter(e=>!i.includes(this.get(e)?.group??``)))}insertSticker(e){this.insertElements(KF(e))}insertTemplate(e){this.insertElements($F(e,this.labels))}deleteSelection(){let e=[...this.selected];this.clearSelection(),this.store.remove(e)}duplicate(){let e=this.store.toJSON(this.selected);if(!e.length)return;let t=this.store.insertJSON(e,24,24);this.select(t.filter(e=>!this.get(e)?.group||!t.includes(this.get(e).group)))}group(){let e=this.store.groupOf([...this.selected]);e&&this.select([e])}ungroup(){let e=this.selection().filter(e=>e.type===`group`),t=e.flatMap(e=>this.store.ungroup(e.id));e.length&&this.select(t)}reorder(e){this.store.reorder(this.expanded(this.selected),e)}mindmapAdd(e){let t=this.activeNode,n=t?this.get(t.map):void 0;if(!t||n?.type!==`mindmap`)return;let r=n.nodes[t.node];if(!r)return;let i=e===`child`||!r.parent?t.node:r.parent,a=fI(n.nodes,i),o;if(e===`sibling`&&r.parent){let e=a.indexOf(t.node),r=n.nodes[a[e]]?.pos??0;o=(r+(a[e+1]?n.nodes[a[e+1]]?.pos??r+2:r+2))/2}else o=a.length?Math.max(...a.map(e=>n.nodes[e]?.pos??0))+1:0;let s=this.store.addNode(t.map,i,o,``);this.activeNode={map:t.map,node:s},this.render(),this.startEdit(t.map,s)}mindmapKey(e){let t=this.activeNode,n=this.get(t.map);if(n?.type!==`mindmap`||!this.selected.has(t.map))return!1;if(e.key===`Tab`)return e.preventDefault(),this.mindmapAdd(`child`),!0;if(e.key===`Enter`)return e.preventDefault(),this.mindmapAdd(`sibling`),!0;if(e.key===`F2`)return e.preventDefault(),this.startEdit(t.map,t.node),!0;if(e.key===`Delete`||e.key===`Backspace`){e.preventDefault();let r=n.nodes[t.node]?.parent;return this.store.removeNode(t.map,t.node),this.activeNode=r?{map:t.map,node:r}:null,this.schedule(),!0}if(e.key.startsWith(`Arrow`)&&!e.shiftKey){e.preventDefault();let r=mI(this.layoutOf(n),n.nodes,t.node,e.key);if(r){this.activeNode={map:t.map,node:r};let e=this.rendered.get(t.map);e&&(e.key=``),this.schedule()}return!0}return!1}owns(){let e=document.activeElement;return!!e&&(e===this.root||this.root.contains(e)&&!OR(e)&&!this.inEditor(e))}onCopy(e,t){if(!this.owns()||!this.selected.size||getSelection()?.toString())return;let n=this.store.toJSON(this.selected);e.clipboardData?.setData(`text/plain`,`docwell-canvas:${JSON.stringify(n)}`),e.preventDefault(),t&&this.editable&&this.deleteSelection()}onPaste(e){if(!this.editable||!this.owns())return;let t=[...e.clipboardData?.files??[]].filter(e=>e.type.startsWith(`image/`));if(t.length){e.preventDefault(),this.addImages(t);return}let n=e.clipboardData?.getData(`text/plain`)??``;if(!n)return;if(e.preventDefault(),n.startsWith(`docwell-canvas:`)){try{let e=JSON.parse(n.slice(15));Array.isArray(e)&&this.insertElements(e)}catch{}return}if(/^https?:\/\/\S+$/i.test(n.trim())){this.addLink(n.trim());return}let[r,i]=this.viewCentre(),a=this.store.add({type:`text`,...this.styles.text,x:r,y:i,w:n.length>60?480:0,h:0,text:n});this.select([a])}setComments(e,t=``){this.comments=e;let n=t!==this.activeComment;this.activeComment=t;let r=t?e.find(e=>e.comment===t):void 0;n&&r&&this.reveal(r.element),this.drawOverlay()}reveal(e){let t=this.get(e);if(!t)return;let n=this.outerBox(t),r=this.root.getBoundingClientRect(),[i,a]=this.toScreen([n.x,n.y]),[o,s]=this.toScreen([n.x+n.w,n.y+n.h]);if(i>=0&&a>=0&&o<=r.width&&s<=r.height)return;let c={...this.view};if(n.w*c.zoome.comment===this.activeComment);o&&e.push(``);let[s,c]=this.toScreen([a.x+a.w,a.y]),l=(o??i[0]).comment;e.push(`${WL(this.labels.comment)}${i.length}`)}}async exportImage(e,t=!1){let n=t&&this.selected.size?new Set(this.expanded(this.selected)):null,r=this.elements().filter(e=>!n||n.has(e.id));return wR(e,{root:this.root,elements:r,boxOf:e=>this.boxOf(e),routeOf:e=>this.routes.get(e.id)??this.routeOf(e),layoutOf:e=>this.layoutOf(e),noteBody:e=>e.page?this.opts.doc.getXmlFragment(`default`):this.store.body(e.id),pageTitle:this.opts.pageTitle?.()??``,resolve:e=>this.opts.files?.resolve(e)??e})}frames(){return this.elements().filter(e=>e.type===`frame`).sort((e,t)=>t.index-e.index)}present(){let e=this.frames().map(e=>e.id);if(!e.length){this.ui.toast(this.labels.presentNoFrames);return}this.stopEditing(),this.clearSelection();let t=this.ui.presentBar();this.presenting={frames:e,at:0,bar:t},this.root.classList.add(`dw-cv-presenting`),this.root.requestFullscreen?.().catch(()=>{}),requestAnimationFrame(()=>this.goTo(0))}goTo(e){let t=this.presenting;if(!t)return;t.at=Math.max(0,Math.min(t.frames.length-1,e));let n=this.get(t.frames[t.at]);if(n){let e={...this.view};this.fit(this.boxOf(n),!1,24);let t={...this.view};this.view=e,this.animateTo(t)}this.ui.presentStep(t.at,t.frames.length)}presentStep(e){this.presenting&&this.goTo(this.presenting.at+e)}stopPresenting(){let e=this.presenting;e&&(this.presenting=null,e.bar.remove(),this.root.classList.remove(`dw-cv-presenting`),document.fullscreenElement===this.root&&document.exitFullscreen().catch(()=>{}),this.drawOverlay())}get isPresenting(){return!!this.presenting}presentKey(e){[`ArrowRight`,`ArrowDown`,`PageDown`,` `,`Enter`].includes(e.key)?(e.preventDefault(),this.presentStep(1)):[`ArrowLeft`,`ArrowUp`,`PageUp`,`Backspace`].includes(e.key)?(e.preventDefault(),this.presentStep(-1)):e.key===`Escape`&&(e.preventDefault(),this.stopPresenting())}};function AR(e){return new Promise(t=>{let n=new Image;n.onload=()=>t({w:n.naturalWidth||320,h:n.naturalHeight||240}),n.onerror=()=>t({w:320,h:240}),n.src=e})}var jR={database:`Database`,untitled:`Untitled database`,untitledRow:`Untitled`,newRow:`New record`,addColumn:`Add property`,columnName:`Property name`,search:`Search records`,filter:`Filter`,sort:`Sort`,group:`Group`,properties:`Properties`,more:`More`,addView:`Add view`,viewName:`View name`,renameView:`Rename view`,duplicateView:`Duplicate view`,deleteView:`Delete view`,layout:`Layout`,viewTable:`Table`,viewKanban:`Kanban`,viewCalendar:`Calendar`,noValue:`No value`,checked:`Checked`,unchecked:`Unchecked`,noRows:`No records`,noMatches:`No records match`,rename:`Rename`,type:`Type`,hide:`Hide in view`,show:`Show in view`,sortAscending:`Sort ascending`,sortDescending:`Sort descending`,filterBy:`Filter by this property`,insertLeft:`Insert left`,insertRight:`Insert right`,moveLeft:`Move left`,moveRight:`Move right`,duplicate:`Duplicate`,deleteColumn:`Delete property`,typeTitle:`Title`,typeText:`Text`,typeNumber:`Number`,typeCheckbox:`Checkbox`,typeSelect:`Select`,typeMultiSelect:`Multi-select`,typeDate:`Date`,typeProgress:`Progress`,typeLink:`Link`,typeAttachment:`Attachment`,typeMember:`Member`,typeCreatedTime:`Created time`,typeCreatedBy:`Created by`,typeRelation:`Relation`,typeRollup:`Rollup`,linkedCount:`{n} linked`,rollupDays:`{n} days`,relationTo:`Related database`,relationPick:`Choose a database`,relationThisPage:`On this page`,relationOtherPage:`On another page…`,relationSearchPage:`Find a page`,relationNoDatabases:`No databases on that page`,relationMissing:`The related database is not available.`,relationTwoWay:`Two-way`,relationOneWay:`Links kept here`,relationMirror:`Show the links of “{n}”`,relationShowOn:`Show on “{n}” too`,relationBackReadOnly:`Change these links on the page that holds the related database.`,linkRecord:`Link a record`,searchRecords:`Search records`,noRecords:`No records`,openRelated:`Open record`,rollupSettings:`Rollup`,rollupRelation:`Relation`,rollupProperty:`Property`,rollupFn:`Calculate`,rollupRecords:`Records`,rollupNeedsRelation:`Add a relation property first.`,fnShowOriginal:`Show values`,fnCount:`Count records`,fnCountValues:`Count values`,fnCountUnique:`Count unique values`,fnCountEmpty:`Count empty`,fnCountNotEmpty:`Count not empty`,fnPercentNotEmpty:`Percent not empty`,fnSum:`Sum`,fnAverage:`Average`,fnMedian:`Median`,fnMin:`Min`,fnMax:`Max`,fnRange:`Range`,fnEarliest:`Earliest date`,fnLatest:`Latest date`,fnChecked:`Checked`,fnPercentChecked:`Percent checked`,openFullPage:`Open as full page`,backToPage:`Back to the page`,recordNotFound:`This record is not in the database any more.`,opContains:`contains`,opNotContains:`does not contain`,opIs:`is`,opIsNot:`is not`,opIsEmpty:`is empty`,opIsNotEmpty:`is not empty`,opGt:`is greater than`,opLt:`is less than`,opGte:`is at least`,opLte:`is at most`,opBefore:`is before`,opAfter:`is after`,opChecked:`is checked`,opUnchecked:`is not checked`,addFilter:`Add filter`,matchAll:`Every filter matches`,matchAny:`Any filter matches`,remove:`Remove`,value:`Value`,noFilters:`No filters yet`,addSort:`Add sort`,ascending:`Ascending`,descending:`Descending`,noSorts:`No sorts yet`,groupBy:`Group by`,noGrouping:`No grouping`,showAll:`Show all`,hideAll:`Hide all`,dateColumn:`Date property`,today:`Today`,previousMonth:`Previous month`,nextMonth:`Next month`,noDateColumn:`Add a date property to place records on the calendar.`,noDate:`No date ({n})`,noGroupColumn:`Add a select, checkbox or member property to sort cards into columns.`,openRow:`Open`,copyLink:`Copy link to record`,deleteRow:`Delete record`,duplicateRow:`Duplicate record`,insertAbove:`Insert above`,insertBelow:`Insert below`,deleteRows:`Delete`,selected:`{n} selected`,selectRow:`Select record`,dragRow:`Drag to move`,close:`Close`,expand:`Full width`,collapse:`Narrow`,previousRow:`Previous record`,nextRow:`Next record`,bodyPlaceholder:`Write about this record…`,bodyReadOnly:`This record has no notes.`,searchOptions:`Find or create a choice`,createOption:`Create “{n}”`,optionColor:`Colour`,deleteOption:`Delete choice`,renameOption:`Rename choice`,searchPeople:`Find a person`,noPeople:`Nobody found`,upload:`Upload a file`,linkPlaceholder:`Paste a link`,clear:`Clear`,exportCsv:`Export as CSV`,importCsv:`Import CSV`,imported:`Added {n} records`,copyNotice:`Copied {n} cells`,readOnly:`Only people who can edit the page can change this database.`,resize:`Drag to change the width`,groupAsDatabase:`Group as database`,done:`Done`},MR={title:`typeTitle`,text:`typeText`,number:`typeNumber`,checkbox:`typeCheckbox`,select:`typeSelect`,multiSelect:`typeMultiSelect`,date:`typeDate`,progress:`typeProgress`,link:`typeLink`,attachment:`typeAttachment`,member:`typeMember`,createdTime:`typeCreatedTime`,createdBy:`typeCreatedBy`,relation:`typeRelation`,rollup:`typeRollup`},NR=(e,t)=>e[MR[t]],PR={contains:`opContains`,notContains:`opNotContains`,is:`opIs`,isNot:`opIsNot`,isEmpty:`opIsEmpty`,isNotEmpty:`opIsNotEmpty`,gt:`opGt`,lt:`opLt`,gte:`opGte`,lte:`opLte`,before:`opBefore`,after:`opAfter`,checked:`opChecked`,unchecked:`opUnchecked`},FR=(e,t)=>e[PR[t]],IR=(e,t)=>t===`kanban`?e.viewKanban:t===`calendar`?e.viewCalendar:e.viewTable,LR=(e,t)=>e.replace(`{n}`,String(t)),{colors:RR,...zR}=xF,BR={slashMenu:`Insert block`,noMatches:`No matching blocks`,slash:{text:{label:`Text`,description:`Plain paragraph`},h1:{label:`Heading 1`,description:`Big section heading`},h2:{label:`Heading 2`,description:`Medium section heading`},h3:{label:`Heading 3`,description:`Small section heading`},otherHeadings:{label:`Other headings`,description:`Headings 4 to 6`},h4:{label:`Heading 4`,description:`A heading below level 3`},h5:{label:`Heading 5`,description:`A heading below level 4`},h6:{label:`Heading 6`,description:`The smallest heading`},bullet:{label:`Bulleted list`,description:`A simple list`},ordered:{label:`Numbered list`,description:`A list with numbers`},todo:{label:`To-do list`,description:`Tasks to tick off (or type [])`},callout:{label:`Callout`,description:`Set a note apart with an emoji and colour`},columns:{label:`Columns`,description:`Put blocks side by side`},columns2:{label:`2 columns`,description:`Two blocks side by side`},columns3:{label:`3 columns`,description:`Three blocks side by side`},columns4:{label:`4 columns`,description:`Four blocks side by side`},table:{label:`Table`,description:`Rows and columns`},quote:{label:`Quote`,description:`Set text apart as a quote`},code:{label:`Code block`,description:`Monospaced code`},divider:{label:`Divider`,description:`A line between sections`},image:{label:`Image`,description:`Upload a picture`},file:{label:`File`,description:`Attach a file to download`},math:{label:`Math block`,description:`A formula on its own line (LaTeX)`},mathInline:{label:`Inline math`,description:`A formula inside the text (LaTeX)`},mermaid:{label:`Mermaid diagram`,description:`Flowcharts and sequences from text`},drawio:{label:`Draw.io diagram`,description:`Draw a diagram with diagrams.net`},excalidraw:{label:`Excalidraw drawing`,description:`Sketch by hand`},toc:{label:`Table of contents`,description:`The page's headings, kept up to date`},pageLink:{label:`Link to page`,description:`Link another page (or type [[)`},toggle:{label:`Toggle`,description:`A heading that hides the blocks under it`},embed:{label:`Embed`,description:`A video, design or document from YouTube, Figma and more`},linkCard:{label:`Link card`,description:`A link with its page's title and picture`},syncedPage:{label:`Synced page`,description:`Show another page here, always up to date`},database:{label:`Database`,description:`Records in a table, board or calendar`},newPage:{label:`New page`,description:`Make a page and link it here`},today:{label:`Today`,description:`Insert today's date`},tomorrow:{label:`Tomorrow`,description:`Insert tomorrow's date`},yesterday:{label:`Yesterday`,description:`Insert yesterday's date`},now:{label:`Now`,description:`Insert the date and time`}},format:{bold:`Bold`,italic:`Italic`,strike:`Strikethrough`,code:`Inline code`,link:`Link`,linkPrompt:`Link address (leave empty to remove the link)`,comment:`Comment`,underline:`Underline`,color:`Colour`,textColor:`Text colour`,highlight:`Highlight`,noColor:`Default`,align:`Align`,alignLeft:`Align left`,alignCenter:`Align centre`,alignRight:`Align right`,math:`Inline math`,linkedPage:`Make a linked page`},colors:{gray:`Grey`,red:`Red`,orange:`Orange`,yellow:`Yellow`,green:`Green`,teal:`Teal`,blue:`Blue`,purple:`Purple`,pink:`Pink`},table:{toolbar:`Table`,dragRow:`Drag to move the row`,dragColumn:`Drag to move the column`,moveRowUp:`Move row up`,moveRowDown:`Move row down`,moveColumnLeft:`Move column left`,moveColumnRight:`Move column right`,addRowBefore:`Add row above`,addRowAfter:`Add row below`,addColumnBefore:`Add column left`,addColumnAfter:`Add column right`,deleteRow:`Delete row`,deleteColumn:`Delete column`,toggleHeaderRow:`Header row`,mergeCells:`Merge cells`,splitCell:`Split cell`,deleteTable:`Delete table`},blockMenu:{open:`Drag to move, click for actions`,turnInto:`Turn into`,moveUp:`Move up`,moveDown:`Move down`,duplicate:`Duplicate`,copy:`Copy`,delete:`Delete`,showLineNumbers:`Show line numbers`,hideLineNumbers:`Hide line numbers`,showPages:`Show pages`,showAsFile:`Show as file`},mentions:`Mention someone`,noPeople:`Nobody found`,pageLinks:`Link to a page`,noPages:`No pages found`,blocks:{edit:`Edit`,done:`Done`,cancel:`Cancel`,save:`Save`,remove:`Remove`,saving:`Saving…`,latex:`LaTeX formula`,mermaid:`Mermaid diagram source`,mermaidError:`This diagram has an error:`,emptyDrawio:`Empty diagram. Click to draw.`,emptyExcalidraw:`Empty drawing. Click to sketch.`,loadFailed:`The editor could not be loaded.`,toc:`Contents`,tocEmpty:`Add headings to the page to fill the table of contents.`,expand:`Show contents`,collapse:`Hide contents`,embed:`Embedded content`,embedUrl:`Address of the video, design or document`,embedInvalid:`This address can't be embedded.`,syncedPage:`Synced page`,syncedOpen:`Open`,syncedFold:`Fold`,syncedUnfold:`Unfold`,syncedLoading:`Loading the page…`,syncedDenied:`You can't open this page.`,syncedSelf:`A page can't show itself.`,linkUrl:`Address of the page to link`,copyBlockLink:`Copy link to this block`,calloutEmoji:`Change emoji`,calloutColor:`Change colour`,resizeColumn:`Drag to resize the columns`,addColumn:`Add a column`,pdfLoading:`Loading PDF…`,pdfPage:`Page {n}`,transcribe:`Transcribe`,transcribeHint:`Add a summary and the transcript below, with AI`,transcribing:`Transcribing…`,transcribeFailed:`The recording could not be transcribed.`},suggest:{mode:`Suggesting`,hint:`Your edits show as suggestions until someone accepts them`,one:`1 suggestion`,count:`{n} suggestions`,accept:`Accept`,reject:`Reject`,acceptAll:`Accept all`,rejectAll:`Reject all`,adds:`Adds`,removes:`Removes`},find:{find:`Find in page`,replace:`Replace with`,previous:`Previous match`,next:`Next match`,replaceOne:`Replace`,replaceAll:`Replace all`,matchCase:`Match case`,close:`Close`,count:`{current} of {total}`,none:`No matches`},ai:{button:`Ask AI`,rewrite:`Improve writing`,summarize:`Summarise`,translate:`Translate`,continue:`Continue writing`,shorter:`Make shorter`,longer:`Make longer`,fix:`Fix spelling and grammar`,custom:`Ask AI to…`,customPlaceholder:`Tell AI what to do with the selection`,language:`Language`,run:`Go`,working:`Writing…`,replace:`Replace selection`,insertBelow:`Insert below`,discard:`Discard`,stop:`Stop`,retry:`Try again`,failed:`AI could not finish this.`},dates:{today:`Today`,tomorrow:`Tomorrow`,yesterday:`Yesterday`,nextWeek:`Next week`,remindWord:`remind`,remindMe:`Remind me`,reminderAt:`Reminder at 9:00 on the day`,someoneElse:`Someone else set a reminder on this date.`,edit:`Change date`,openJournal:`Open journal`},database:jR,edgeless:zR},VR=[`title`,`text`,`number`,`checkbox`,`select`,`multiSelect`,`date`,`progress`,`link`,`attachment`,`member`,`createdTime`,`createdBy`,`relation`,`rollup`],HR=VR.filter(e=>e!==`title`),UR=[`table`,`kanban`,`calendar`];function WR(){let e=new Uint8Array(6);return crypto.getRandomValues(e),[...e].map(e=>e.toString(36).padStart(2,`0`)).join(``).slice(0,10)}function GR(e,t,n){let r=n.find(e=>KR.includes(e.type)),i=n.find(e=>e.type===`date`||e.type===`createdTime`);return{id:WR(),name:t,type:e,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:e===`kanban`?r?.id??null:null,dateColumn:e===`calendar`?i?.id??null:null,widths:{}}}var KR=[`select`,`multiSelect`,`checkbox`,`member`,`createdBy`];function qR(e){let t=XR(e)?e:{},n=(Array.isArray(t.columns)?t.columns:[]).flatMap(e=>{if(!XR(e)||typeof e.id!=`string`||!e.id)return[];let t=VR.includes(String(e.type))?e.type:`text`,n={id:e.id,name:typeof e.name==`string`?e.name:``,type:t};Array.isArray(e.options)&&(n.options=e.options.flatMap(JR));let r=t===`relation`?bz(e.relation):void 0;r&&(n.relation=r);let i=t===`rollup`?xz(e.rollup):void 0;return i&&(n.rollup=i),[n]});n.some(e=>e.type===`title`)||n.unshift({id:WR(),name:``,type:`title`});let r=(Array.isArray(t.rows)?t.rows:[]).flatMap(e=>{if(!XR(e)||typeof e.id!=`string`||!e.id)return[];let t={id:e.id,cells:XR(e.cells)?{...e.cells}:{},createdAt:typeof e.createdAt==`number`?e.createdAt:0,createdBy:YR(e.createdBy)};return Array.isArray(e.body)&&e.body.length&&(t.body=e.body,t.hasBody=!0),[t]}),i=new Set(n.map(e=>e.id)),a=(Array.isArray(t.views)?t.views:[]).flatMap(e=>{if(!XR(e)||typeof e.id!=`string`||!e.id)return[];let t=UR.includes(String(e.type))?e.type:`table`;return[{id:e.id,name:typeof e.name==`string`?e.name:``,type:t,hidden:Array.isArray(e.hidden)?e.hidden.filter(e=>typeof e==`string`):[],filters:Array.isArray(e.filters)?e.filters.filter(e=>XR(e)&&typeof e.column==`string`&&typeof e.op==`string`):[],filterMode:e.filterMode===`or`?`or`:`and`,sorts:Array.isArray(e.sorts)?e.sorts.flatMap(e=>XR(e)&&typeof e.column==`string`?[{column:e.column,desc:!!e.desc}]:[]):[],groupBy:typeof e.groupBy==`string`&&i.has(e.groupBy)?e.groupBy:null,dateColumn:typeof e.dateColumn==`string`&&i.has(e.dateColumn)?e.dateColumn:null,widths:XR(e.widths)?Object.fromEntries(Object.entries(e.widths).filter(e=>typeof e[1]==`number`)):{}}]});return{title:typeof t.title==`string`?t.title:``,columns:n,rows:r,views:a}}function JR(e){return!XR(e)||typeof e.id!=`string`?[]:[{id:e.id,name:typeof e.name==`string`?e.name:``,color:IP(e.color)?e.color:`gray`}]}function YR(e){return XR(e)&&typeof e.id==`string`?{id:e.id,name:typeof e.name==`string`?e.name:``}:null}function XR(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ZR(e){return e.columns.find(e=>e.type===`title`)??e.columns[0]}function QR(e,t){return t.type===`createdTime`?e.createdAt||null:t.type===`createdBy`?e.createdBy?[e.createdBy]:[]:t.type===`rollup`?e.computed?.[t.id]?.value??null:t.type===`relation`&&t.relation?.back?e.computed?.[t.id]?.value??[]:e.cells[t.id]}function $R(e){return e==null||e===``||e===!1||Array.isArray(e)&&e.length===0}function ez(e){return typeof e==`number`&&e>0?tz(new Date(e)):typeof e==`string`&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function tz(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function nz(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e.trim().replace(`,`,`.`));return Number.isFinite(t)?t:null}return null}function rz(e){return Array.isArray(e)?e:[]}function iz(e,t){let n=QR(e,t);switch(t.type){case`title`:case`text`:case`link`:return typeof n==`string`?n:``;case`number`:case`progress`:{let e=nz(n);return e===null?``:String(e)}case`checkbox`:return n===!0?`true`:`false`;case`select`:return t.options?.find(e=>e.id===n)?.name??``;case`multiSelect`:return rz(n).map(e=>t.options?.find(t=>t.id===e)?.name).filter(e=>!!e).join(`, `);case`date`:case`createdTime`:return ez(n);case`attachment`:return rz(n).map(e=>e?.name??``).join(`, `);case`member`:case`createdBy`:return rz(n).map(e=>e?.name??``).join(`, `);case`relation`:case`rollup`:return e.computed?.[t.id]?.text??``}}function az(e){switch(e){case`number`:case`progress`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`isEmpty`,`isNotEmpty`];case`checkbox`:return[`checked`,`unchecked`];case`select`:return[`is`,`isNot`,`isEmpty`,`isNotEmpty`];case`multiSelect`:case`member`:case`createdBy`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`date`:case`createdTime`:return[`is`,`before`,`after`,`isEmpty`,`isNotEmpty`];case`attachment`:return[`isEmpty`,`isNotEmpty`];case`relation`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`rollup`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`contains`,`isEmpty`,`isNotEmpty`];default:return[`contains`,`notContains`,`is`,`isNot`,`isEmpty`,`isNotEmpty`]}}var oz=e=>![`isEmpty`,`isNotEmpty`,`checked`,`unchecked`].includes(e);function sz(e,t,n){let r=QR(e,t);if(t.type===`relation`){let e=Cz(r).length===0;if(n.op===`isEmpty`)return e;if(n.op===`isNotEmpty`)return!e}if(n.op===`isEmpty`)return $R(r)||iz(e,t)===``;if(n.op===`isNotEmpty`)return!($R(r)||iz(e,t)===``);if(n.op===`checked`)return r===!0;if(n.op===`unchecked`)return r!==!0;if(n.value===void 0||n.value===null||n.value===``)return!0;switch(t.type===`rollup`&&(typeof r==`number`||r===null)&&[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`].includes(n.op)?`number`:t.type){case`number`:case`progress`:{let e=nz(r),t=nz(n.value);return t===null?!0:e===null?n.op===`isNot`:{is:e===t,isNot:e!==t,gt:e>t,lt:e=t,lte:e<=t}[n.op]}case`select`:return n.op===`is`?r===n.value:r!==n.value;case`multiSelect`:{let e=rz(r).includes(String(n.value));return n.op===`notContains`?!e:e}case`member`:case`createdBy`:{let e=String(n.value).toLowerCase(),t=rz(r).some(t=>t?.id===n.value||t?.name?.toLowerCase().includes(e));return n.op===`notContains`?!t:t}case`date`:case`createdTime`:{let e=ez(r),t=ez(n.value);return e?n.op===`before`?et:e===t:!1}default:{let r=iz(e,t).toLowerCase(),i=String(n.value).toLowerCase();switch(n.op){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`is`:return r===i;case`isNot`:return r!==i;default:return!0}}}}function cz(e,t,n){let r=iz(e,n)===``&&n.type!==`checkbox`,i=iz(t,n)===``&&n.type!==`checkbox`;if(r||i)return r===i?0:r?1:-1;switch(n.type){case`number`:case`progress`:return(nz(QR(e,n))??0)-(nz(QR(t,n))??0);case`checkbox`:return Number(QR(e,n)===!0)-Number(QR(t,n)===!0);case`createdTime`:return e.createdAt-t.createdAt;case`rollup`:{let r=QR(e,n),i=QR(t,n);return typeof r==`number`&&typeof i==`number`?r-i:iz(e,n).localeCompare(iz(t,n),void 0,{numeric:!0,sensitivity:`base`})}case`select`:{let r=e=>n.options?.findIndex(t=>t.id===QR(e,n))??-1;return r(e)-r(t)}default:return iz(e,n).localeCompare(iz(t,n),void 0,{numeric:!0,sensitivity:`base`})}}function lz(e,t,n=``){let r=new Map(e.columns.map(e=>[e.id,e])),i=t.filters.flatMap(e=>{let t=r.get(e.column);return t?[{f:e,col:t}]:[]}),a=n.trim().toLowerCase(),o=e.rows.filter(n=>{if(i.length){let e=({f:e,col:t})=>sz(n,t,e);if(t.filterMode===`or`?!i.some(e):!i.every(e))return!1}return!a||e.columns.some(e=>iz(n,e).toLowerCase().includes(a))}),s=t.sorts.flatMap(e=>{let t=r.get(e.column);return t?[{col:t,desc:e.desc}]:[]});return s.length&&(o=o.map((e,t)=>({r:e,i:t})).sort((e,t)=>{for(let n of s){let r=cz(e.r,t.r,n.col);if(r!==0){let i=iz(e.r,n.col)===``||iz(t.r,n.col)===``;return n.desc&&!(i&&n.col.type!==`checkbox`)?-r:r}}return e.i-t.i}).map(e=>e.r)),o}function uz(e,t){return e.columns.filter(e=>e.type===`title`||!t.hidden.includes(e.id))}function dz(e,t,n,r,i){let a=new Map,o=(e,t,n)=>(a.has(e)||a.set(e,{key:e,label:t,color:n,rows:[]}),a.get(e));if(t.type===`checkbox`)o(`false`,i),o(`true`,r);else{o(``,n);for(let e of t.options??[])o(e.id,e.name,e.color)}for(let n of e)for(let e of pz(n,t))(a.get(e)??o(e,fz(n,t,e)||e)).rows.push(n);return[...a.values()]}function fz(e,t,n){return rz(QR(e,t)).find(e=>e?.id===n)?.name??``}function pz(e,t){let n=QR(e,t);switch(t.type){case`checkbox`:return[n===!0?`true`:`false`];case`select`:return[typeof n==`string`&&t.options?.some(e=>e.id===n)?n:``];case`multiSelect`:{let e=rz(n).filter(e=>t.options?.some(t=>t.id===e));return e.length?e:[``]}case`member`:case`createdBy`:{let e=rz(n).flatMap(e=>e?.id?[e.id]:[]);return e.length?e:[``]}default:return[``]}}function mz(e,t,n,r,i=[]){let a=QR(e,t);switch(t.type){case`checkbox`:return r===`true`;case`select`:return r||null;case`multiSelect`:{let e=rz(a).filter(e=>e!==n&&e!==r);return r?[...e,r]:e}case`member`:{let e=rz(a).filter(e=>e?.id!==n&&e?.id!==r),t=i.find(e=>e.id===r)??rz(a).find(e=>e?.id===r);return r&&t?[...e,t]:e}default:return a}}function hz(e){let t=FP.filter(e=>e!==`gray`);return t[e.length%t.length]}function gz(e,t,n,r){if(t.type===n)return{value:e,options:r};let i=iz({id:``,cells:{[t.id]:e},createdAt:0,createdBy:null},t),a=e=>{let t=e.trim();if(!t)return null;let n=r.find(e=>e.name.toLowerCase()===t.toLowerCase());return n||(n={id:WR(),name:t,color:hz(r)},r=[...r,n]),n.id};switch(n){case`title`:case`text`:case`link`:return{value:i||null,options:r};case`number`:return{value:nz(i),options:r};case`progress`:{let e=nz(i);return{value:e===null?null:Math.max(0,Math.min(100,Math.round(e))),options:r}}case`checkbox`:return{value:[`true`,`yes`,`1`,`x`,`✓`,`done`].includes(i.trim().toLowerCase()),options:r};case`select`:return{value:a(i.split(`,`)[0]??``),options:r};case`multiSelect`:{let e=i.split(`,`).flatMap(e=>{let t=a(e);return t?[t]:[]});return{value:[...new Set(e)],options:r}}case`date`:return{value:ez(i)||null,options:r};case`member`:return{value:t.type===`member`||t.type===`createdBy`?e:[],options:r};default:return{value:null,options:r}}}function _z(e,t,n=1){let r=(new Date(e,t,1).getDay()-n+7)%7,i=new Date(e,t,1-r),a=new Date(e,t+1,0).getDate(),o=Math.ceil((r+a)/7);return Array.from({length:o*7},(e,t)=>tz(new Date(i.getFullYear(),i.getMonth(),i.getDate()+t)))}var vz=e=>e.type===`relation`&&!!e.relation?.back,yz=[`showOriginal`,`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`,`sum`,`average`,`median`,`min`,`max`,`range`,`earliest`,`latest`,`checked`,`percentChecked`];function bz(e){if(!XR(e)||typeof e.database!=`string`||!e.database)return;let t={page:typeof e.page==`string`?e.page:``,database:e.database};return typeof e.back==`string`&&e.back&&(t.back=e.back),t}function xz(e){if(!XR(e)||typeof e.relation!=`string`)return;let t=yz.includes(String(e.fn))?e.fn:`count`;return{relation:e.relation,property:typeof e.property==`string`?e.property:``,fn:t}}function Sz(e){let t=[`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`];switch(e){case`number`:case`progress`:return[`sum`,`average`,`median`,`min`,`max`,`range`,...t,`showOriginal`];case`date`:case`createdTime`:return[`earliest`,`latest`,`range`,...t,`showOriginal`];case`checkbox`:return[`checked`,`percentChecked`,`count`,`showOriginal`];default:return[`showOriginal`,...t]}}var Cz=e=>rz(e).filter(e=>typeof e==`string`&&!!e);function wz(e,t,n){let r=t.relation?.back;return r?n?n.rows.filter(t=>Cz(t.cells[r]).includes(e.id)).map(e=>e.id):[]:Cz(e.cells[t.id])}var Tz=e=>String(Number.isInteger(e)?e:Math.round(e*100)/100),Ez=(e,t)=>Math.round((Date.parse(t)-Date.parse(e))/864e5);function Dz(e,t,n,r){let i=t.map(e=>n?QR(e,n):e.id),a=t.map(e=>n?iz(e,n):``),o=a.filter((e,t)=>n?.type===`checkbox`?i[t]===!0:e!==``),s=n?i.map(nz).filter(e=>e!==null):[],c=n?i.map(ez).filter(Boolean).sort():[],l=e=>({text:e===null?``:Tz(e),value:e});switch(e){case`count`:return l(t.length);case`countValues`:return l(o.length);case`countUnique`:return l(new Set(o).size);case`countEmpty`:return l(t.length-o.length);case`countNotEmpty`:return l(o.length);case`percentNotEmpty`:return t.length?{text:`${Tz(o.length/t.length*100)}%`,value:o.length/t.length*100}:l(null);case`sum`:return l(s.length?s.reduce((e,t)=>e+t,0):null);case`average`:return l(s.length?s.reduce((e,t)=>e+t,0)/s.length:null);case`median`:{if(!s.length)return l(null);let e=[...s].sort((e,t)=>e-t),t=Math.floor(e.length/2);return l(e.length%2?e[t]:(e[t-1]+e[t])/2)}case`min`:return l(s.length?Math.min(...s):null);case`max`:return l(s.length?Math.max(...s):null);case`range`:if(n&&(n.type===`date`||n.type===`createdTime`)){if(!c.length)return l(null);let e=Ez(c[0],c[c.length-1]);return{text:r.rollupDays.replace(`{n}`,String(e)),value:e}}return l(s.length?Math.max(...s)-Math.min(...s):null);case`earliest`:return{text:c[0]??``,value:c[0]??null};case`latest`:return{text:c[c.length-1]??``,value:c[c.length-1]??null};case`checked`:return l(i.filter(e=>e===!0).length);case`percentChecked`:return t.length?{text:`${Tz(i.filter(e=>e===!0).length/t.length*100)}%`,value:i.filter(e=>e===!0).length/t.length*100}:l(null);case`showOriginal`:{let e=a.filter(Boolean);return{text:e.join(`, `),value:e}}}}function Oz(e,t,n){let r=e.columns.filter(e=>e.type===`relation`&&e.relation),i=e.columns.filter(e=>e.type===`rollup`&&e.rollup);if(!r.length&&!i.length)return e;let a=new Map;for(let e of r)a.set(e.id,t(e.relation));let o=e.rows.map(e=>{let t={};for(let i of r){let r=a.get(i.id),o=wz(e,i,r);if(!r){t[i.id]={text:o.length?n.linkedCount.replace(`{n}`,String(o.length)):``,value:o};continue}let s=r.columns.find(e=>e.type===`title`),c=new Map(r.rows.map(e=>[e.id,e])),l=o.flatMap(e=>{let t=c.get(e);return t?[{id:e,title:s?iz(t,s):``}]:[]});t[i.id]={text:l.map(e=>e.title).join(`, `),value:o,links:l}}for(let o of i){let i=o.rollup,s=r.find(e=>e.id===i.relation),c=s?a.get(s.id):null;if(!s||!c){t[o.id]={text:``,value:null};continue}let l=new Map(c.rows.map(e=>[e.id,e])),u=wz(e,s,c).flatMap(e=>{let t=l.get(e);return t?[t]:[]}),d=i.property?c.columns.find(e=>e.id===i.property)??null:c.columns.find(e=>e.type===`title`)??null;t[o.id]=Dz(i.fn,u,d,n)}return{...e,computed:t}});return{...e,rows:o}}function I(e,t={},...n){let r=document.createElement(e);for(let[e,n]of Object.entries(t))if(n!=null&&n!==!1){if(e===`class`)r.className=String(n);else if(e===`on`)for(let[e,t]of Object.entries(n))r.addEventListener(e,t);else e===`dataset`?Object.assign(r.dataset,n):e===`style`?Object.assign(r.style,n):e in r&&typeof n!=`string`?r[e]=n:r.setAttribute(e,n===!0?``:String(n))}for(let e of n.flat())e!=null&&e!==!1&&r.append(e);return r}function kz(e,t=16){return Hj(e,t)}function Az(e,t,n,r){let i=I(`button`,{type:`button`,class:r?`dw-db__btn`:`dw-db__btn dw-db__btn--icon`,title:t,"aria-label":t},kz(e,15),r?I(`span`,{},r):null);return i.addEventListener(`click`,e=>{e.preventDefault(),n(e)}),i}var jz=null;function Mz(e,t,n={}){jz?.close();let r=I(`div`,{class:`dw-db-pop ${n.class??``}`,role:`dialog`,"aria-label":n.label}),i=!1,a=()=>{i||(i=!0,c(),r.remove(),document.removeEventListener(`mousedown`,o,!0),document.removeEventListener(`keydown`,s,!0),jz?.box===r&&(jz=null),n.onClose?.())},o=t=>{let n=t.target;r.contains(n)||e.contains(n)||n instanceof Element&&n.closest(`.dw-block-menu`)||a()},s=t=>{t.key===`Escape`&&!document.querySelector(`.dw-block-menu`)&&(t.preventDefault(),t.stopPropagation(),a(),e instanceof HTMLElement&&e.focus())};document.body.append(r);let c=jj(e,r,()=>{Fj(e,r,{placement:n.placement??`bottom-start`,strategy:`fixed`,middleware:[Mj(4),Pj(),Nj({padding:8})]}).then(({x:e,y:t})=>Object.assign(r.style,{left:`${e}px`,top:`${t}px`}))});return document.addEventListener(`mousedown`,o,!0),document.addEventListener(`keydown`,s,!0),t(r,a),jz={box:r,close:a},jz}function Nz(){jz?.close()}function Pz(e,t){let n=I(`input`,{type:t.type??`text`,class:t.class??`dw-db-input`,placeholder:t.placeholder,"aria-label":t.label??t.placeholder});n.value=e;let r=!1,i=()=>{r||(r=!0,t.onCommit(n.value))};return n.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),i()):e.key===`Escape`&&(r=!0,t.onCancel?.())}),n.addEventListener(`blur`,i),n}function Fz(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=I(`a`,{href:r,download:e});document.body.append(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function Iz(e){return new Promise(t=>{let n=I(`input`,{type:`file`,accept:e});n.onchange=()=>t(n.files?.[0]??null),n.click()})}function Lz(e,t){let n=e.read(t);return!n||!e.pointsHere?[]:n.columns.filter(n=>n.type===`relation`&&n.relation&&!n.relation.back&&e.pointsHere(t,n.relation))}var Rz=e=>`fn${e[0].toUpperCase()}${e.slice(1)}`,zz=(e,t)=>e[Rz(t)];function Bz(e,t,n,r){let i=I(`div`,{class:`dw-db-pop__item${t?` is-active`:``}`,role:`option`,"aria-selected":String(t)},I(`span`,{},e),r?I(`small`,{class:`dw-db-pop__sub`},r):null);return i.addEventListener(`mousedown`,e=>e.preventDefault()),i.addEventListener(`click`,n),i}function Vz(e,t,n,r){let i=e.store,a=e.linked;if(!i||!a)return;let o=e.labels;Mz(t,(t,r)=>{let s=n.relation,c=e=>{let c={page:e.page,database:e.database},l=Lz(a,c);if(!l.length)return i.setRelation(n.id,c),r();let u=!!s&&s.page===e.page&&s.database===e.database;t.replaceChildren(I(`div`,{class:`dw-db-pop__title`},e.title||o.untitled),I(`div`,{class:`dw-db-pop__list`,role:`listbox`},Bz(o.relationOneWay,u&&!s.back,()=>{i.setRelation(n.id,c),r()}),...l.map(e=>Bz(LR(o.relationMirror,e.name||o.typeRelation),u&&s.back===e.id,()=>{i.setRelation(n.id,{...c,back:e.id}),r()},o.relationTwoWay))))},l=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});if((()=>{let e=a.local();l.replaceChildren(I(`div`,{class:`dw-db-pop__heading`},o.relationThisPage),...e.length?e.map(e=>Bz(e.title||o.untitled,!!s&&!s.page&&s.database===e.database,()=>c(e))):[I(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})(),t.append(I(`div`,{class:`dw-db-pop__title`},o.relationPick),l),a.searchPages&&a.databasesOn){let e=I(`input`,{class:`dw-db-input`,placeholder:o.relationSearchPage,"aria-label":o.relationOtherPage}),n=I(`div`,{class:`dw-db-pop__list`,role:`listbox`}),r=0;e.addEventListener(`input`,async()=>{let t=e.value.trim(),i=++r;if(!t)return n.replaceChildren();let l=await a.searchPages(t).catch(()=>[]);i===r&&n.replaceChildren(...l.slice(0,8).map(e=>Bz(e.title||o.untitled,!1,async()=>{let t=await a.databasesOn(e.id).catch(()=>[]);i===r&&n.replaceChildren(I(`div`,{class:`dw-db-pop__heading`},e.title||o.untitled),...t.length?t.map(e=>Bz(e.title||o.untitled,s?.page===e.page&&s.database===e.database,()=>c(e))):[I(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})))}),e.addEventListener(`keydown`,e=>e.stopPropagation()),t.append(I(`div`,{class:`dw-db-pop__heading`},o.relationOtherPage),e,n)}if(s&&!s.back&&a.addBack&&a.writable?.(s)){let i=a.read(s),c=i?.columns.some(e=>e.relation?.back===n.id&&a.pointsHere?.(s,e.relation));if(i&&!c){let c=I(`button`,{type:`button`,class:`dw-db__btn dw-db-pop__add`},kz(`plus`,14),I(`span`,{},LR(o.relationShowOn,i.title||o.untitled)));c.addEventListener(`click`,()=>{a.addBack(s,n.id,e.db.title||n.name||o.typeRelation),r()}),t.append(c)}}},{class:`dw-db-pop--choices`,label:o.relationTo,onClose:r})}function Hz(e,t,n,r,i){let a=e.store,o=e.labels,s=r.relation,c=s?e.linked?.read(s):null;if(!s||!c){if(t.append(I(`div`,{class:`dw-db-pop__empty`},s?o.relationMissing:o.relationPick)),!s&&e.linked){let n=I(`button`,{type:`button`,class:`dw-db__btn`},o.relationTo);n.addEventListener(`click`,()=>{i(),Vz(e,t,r)}),t.append(n)}return}let l=ZR(c),u=!!s.back,d=!u||!!e.linked?.writable?.(s),f=wz(n,r,c),p=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),m=I(`input`,{class:`dw-db-input`,placeholder:o.searchRecords,"aria-label":o.linkRecord}),h=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(p),d?t.append(m,h):t.append(I(`div`,{class:`dw-db-pop__empty`},o.relationBackReadOnly));let g=e=>iz(e,l)||o.untitledRow,_=t=>{if(!d)return;let i=!f.includes(t);if(u){if(!e.linked?.link?.(s,n.id,t,i))return}else a.setCell(n.id,r.id,i?[...f,t]:f.filter(e=>e!==t));f=i?[...f,t]:f.filter(e=>e!==t),b()},v=0,y=[],b=()=>{let e=new Map(c.rows.map(e=>[e.id,e]));p.replaceChildren(...f.flatMap(t=>{let n=e.get(t);if(!n)return[];let r=I(`span`,{class:`dw-db-tag`,dataset:{color:`gray`}},g(n));if(d){let e=I(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,()=>_(t)),r.append(e)}return[r]}));let t=m.value.trim().toLowerCase();y=c.rows.filter(e=>!t||g(e).toLowerCase().includes(t)).slice(0,50),v=Math.min(v,Math.max(0,y.length-1)),h.replaceChildren(...y.length?y.map((e,t)=>{let n=Bz(g(e),t===v,()=>_(e.id));return f.includes(e.id)&&n.prepend(I(`span`,{class:`dw-db-pop__check`},`✓`)),n}):[I(`div`,{class:`dw-db-pop__empty`},o.noRecords)])};m.addEventListener(`input`,()=>{v=0,b()}),m.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),y.length&&(v=(v+(e.key===`ArrowDown`?1:-1)+y.length)%y.length),b();else if(e.key===`Enter`){e.preventDefault();let t=y[v];t&&_(t.id)}else e.key===`Escape`&&(e.preventDefault(),i())}),b(),d&&m.focus({preventScroll:!0})}function Uz(e,t,n,r){let i=e.store;if(!i)return;let a=e.labels;Mz(t,t=>{let r=e.db.columns.filter(e=>e.type===`relation`);if(!r.length){t.append(I(`div`,{class:`dw-db-pop__empty`},a.rollupNeedsRelation));return}let o=n.rollup??{relation:r[0].id,property:``,fn:`count`},s=(e,t,n,r)=>{let i=I(`select`,{class:`dw-db-input`,"aria-label":e});for(let[e,n]of t)i.append(I(`option`,{value:e},n));return i.value=n,i.addEventListener(`change`,()=>r(i.value)),I(`label`,{class:`dw-db-pop__field`},I(`span`,{},e),i)},c=()=>{let l=r.find(e=>e.id===o.relation)??r[0],u=l.relation?e.linked?.read(l.relation):null,d=[[``,a.rollupRecords]];for(let e of u?.columns??[])d.push([e.id,e.name||NR(a,e.type)]);let f=u?.columns.find(e=>e.id===o.property),p=Sz(f?f.type:``);p.includes(o.fn)||(o.fn=o.property?p[0]:`count`),t.replaceChildren(s(a.rollupRelation,r.map(e=>[e.id,e.name||a.typeRelation]),l.id,e=>{o.relation=e,o.property=``,o.fn=`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupProperty,d,o.property,e=>{o.property=e;let t=u?.columns.find(t=>t.id===e);o.fn=e?Sz(t?t.type:``)[0]:`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupFn,(o.property?p:[`count`,`showOriginal`]).map(e=>[e,zz(a,e)]),o.fn,e=>{o.fn=e,i.setRollup(n.id,{...o})}),u?I(`span`):I(`div`,{class:`dw-db-pop__empty`},a.relationMissing))};n.rollup||i.setRollup(n.id,{...o}),c()},{class:`dw-db-pop--choices`,label:a.rollupSettings,onClose:r})}function Wz(e,t,n){let r=t.computed?.[n.id],i=I(`span`,{class:`dw-db-tags`});if(r?.links&&n.relation){let t=n.relation;for(let n of r.links){let r=I(`button`,{type:`button`,class:`dw-db-tag dw-db-rel`,dataset:{color:`gray`},title:e.labels.openRelated},n.title||e.labels.untitledRow);r.addEventListener(`click`,r=>{r.stopPropagation(),e.linked?.openRecord(t,n.id)}),i.append(r)}}else r?.text&&i.append(I(`span`,{class:`dw-db-cell__text`},r.text));return i}var Gz={title:`text`,text:`type`,number:`sigma`,checkbox:`todo`,select:`tag`,multiSelect:`layers`,date:`calendar`,progress:`sliders`,link:`link`,attachment:`paperclip`,member:`users`,createdTime:`clock`,createdBy:`at`,relation:`relation`,rollup:`rollup`},Kz=[`title`,`text`,`number`,`link`],qz=[`createdTime`,`createdBy`,`rollup`];function Jz(e,t){let[n,r,i]=e.split(`-`).map(Number);return!n||!r||!i?e:new Date(n,r-1,i).toLocaleDateString(t,{year:`numeric`,month:`short`,day:`numeric`})}function Yz(e,t,n){let r=I(`span`,{class:`dw-db-tag`,dataset:{color:t??`gray`}},e);if(n){let e=I(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{e.stopPropagation(),n()}),r.append(e)}return r}function Xz(e){try{let t=new URL(e.includes(`://`)?e:`https://${e}`);return t.protocol===`http:`||t.protocol===`https:`||t.protocol===`mailto:`?t.href:null}catch{return null}}function Zz(e,t,n){let r=QR(t,n),i=e.labels;switch(n.type){case`title`:{let e=typeof r==`string`?r:``;return I(`span`,{class:e?`dw-db-cell__title`:`dw-db-cell__title is-empty`},e||i.untitledRow)}case`text`:return I(`span`,{class:`dw-db-cell__text`},typeof r==`string`?r:``);case`number`:{let t=nz(r);return I(`span`,{class:`dw-db-cell__number`},t===null?``:t.toLocaleString(e.locale))}case`checkbox`:return I(`span`,{class:r===!0?`dw-db-check is-on`:`dw-db-check`,role:`img`,"aria-label":r===!0?i.checked:i.unchecked},r===!0?kz(`check`,13):null);case`select`:{let e=n.options?.find(e=>e.id===r);return I(`span`,{class:`dw-db-tags`},e?Yz(e.name,e.color):null)}case`multiSelect`:return I(`span`,{class:`dw-db-tags`},rz(r).flatMap(e=>{let t=n.options?.find(t=>t.id===e);return t?[Yz(t.name,t.color)]:[]}));case`date`:case`createdTime`:{let t=ez(r);return I(`span`,{class:`dw-db-cell__text`},t?Jz(t,e.locale):``)}case`progress`:{let e=nz(r);if(e===null)return I(`span`);let t=Math.max(0,Math.min(100,e));return I(`span`,{class:`dw-db-progress`},I(`span`,{class:`dw-db-progress__bar`},I(`span`,{class:`dw-db-progress__fill`,style:{width:`${t}%`}})),I(`span`,{class:`dw-db-progress__num`},`${t}%`))}case`link`:{let e=typeof r==`string`?r:``,t=e?Xz(e):null;if(!t)return I(`span`,{class:`dw-db-cell__text`},e);let n=I(`a`,{class:`dw-db-cell__link`,href:t,target:`_blank`,rel:`noopener noreferrer`},e);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}case`attachment`:return I(`span`,{class:`dw-db-tags`},rz(r).map(t=>{let n=I(`a`,{class:`dw-db-file`,href:e.files?e.files.resolve(t.src):t.src,target:`_blank`,rel:`noopener noreferrer`},kz(`paperclip`,12),t.name);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}));case`member`:case`createdBy`:return I(`span`,{class:`dw-db-tags`},rz(r).map(e=>I(`span`,{class:`dw-db-person`},I(`span`,{class:`dw-db-person__dot`},(e?.name||`?`).slice(0,1).toUpperCase()),e?.name??``)));case`relation`:return Wz(e,t,n);case`rollup`:{let r=t.computed?.[n.id],i=r?.value;return typeof i==`number`?I(`span`,{class:`dw-db-cell__number`},/^-?\d+(\.\d+)?%?$/.test(r.text)?i.toLocaleString(e.locale,{maximumFractionDigits:2})+(r.text.endsWith(`%`)?`%`:``):r.text):I(`span`,{class:`dw-db-cell__text`},r?.text??``)}}}function Qz(e,t,n,r,i){let a=e.store;if(!a||qz.includes(r.type))return i.onDone();let o=QR(n,r);if(r.type===`checkbox`)return a.setCell(n.id,r.id,o!==!0),i.onDone();e.setEditing(!0);let s=t=>{e.setEditing(!1),i.onDone(t)};if(Kz.includes(r.type)){let e=i.initial??(r.type===`number`?nz(o)?.toString()??``:typeof o==`string`?o:``),c,l=Pz(e,{class:`dw-db-cell__input`,type:(r.type,`text`),label:r.name,onCommit:e=>{let t=e.trim(),i=r.type===`number`?nz(t):r.type===`title`||r.type===`text`?e:t;i!==(o??null)&&(i!==``||o!==void 0)&&a.setCell(n.id,r.id,i),s(c)},onCancel:()=>s()});l.addEventListener(`keydown`,e=>{e.key===`Enter`&&(c=`down`),e.key===`Tab`&&(e.preventDefault(),c=e.shiftKey?`left`:`right`,l.blur())}),t.replaceChildren(l),t.classList.add(`is-editing`),l.focus(),i.initial===void 0?l.select():l.setSelectionRange(l.value.length,l.value.length);return}let c=(e,n=``)=>Mz(t,e,{class:n,onClose:()=>s(),label:r.name});switch(r.type){case`select`:case`multiSelect`:c((t,a)=>$z(e,t,n,r,a,i.initial),`dw-db-pop--choices`);break;case`date`:c((t,i)=>{let s=I(`input`,{type:`date`,class:`dw-db-input`,"aria-label":r.name});s.value=ez(o),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,s.value||null)),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&i()});let c=I(`button`,{type:`button`,class:`dw-db__btn`},e.labels.clear);c.addEventListener(`click`,()=>{a.setCell(n.id,r.id,null),i()});let l=I(`button`,{type:`button`,class:`dw-db__btn`},e.labels.today);l.addEventListener(`click`,()=>{let e=new Date;a.setCell(n.id,r.id,`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`),i()}),t.append(s,I(`div`,{class:`dw-db-pop__row`},l,c)),s.focus({preventScroll:!0})});break;case`progress`:c((e,t)=>{let i=nz(o)??0,s=I(`input`,{type:`range`,min:`0`,max:`100`,step:`1`,class:`dw-db-range`,"aria-label":r.name});s.value=String(i);let c=I(`span`,{class:`dw-db-progress__num`},`${i}%`);s.addEventListener(`input`,()=>c.textContent=`${s.value}%`),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,Number(s.value))),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&t()}),e.append(I(`div`,{class:`dw-db-pop__row`},s,c)),s.focus({preventScroll:!0})});break;case`member`:c((t,i)=>eB(e,t,n,r,i),`dw-db-pop--choices`);break;case`attachment`:c(t=>tB(e,t,n,r),`dw-db-pop--choices`);break;case`relation`:c((t,i)=>Hz(e,t,n,r,i),`dw-db-pop--choices`);break;default:s()}}function $z(e,t,n,r,i,a){let o=e.store,s=e.labels,c=r.type===`multiSelect`,l=[...r.options??[]],u=c?rz(QR(n,r)):[String(QR(n,r)??``)].filter(Boolean),d=0,f=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),p=I(`input`,{class:`dw-db-input`,placeholder:s.searchOptions,"aria-label":s.searchOptions});p.value=a??``;let m=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(f,p,m);let h=()=>o.setCell(n.id,r.id,c?u:u[0]??null),g=e=>{u=c?u.includes(e)?u.filter(t=>t!==e):[...u,e]:u[0]===e?[]:[e],h(),c?b():i()},_=e=>{let t={id:WR(),name:e,color:hz(l)};l=[...l,t],o.tx(()=>{o.setOptions(r.id,l),u=c?[...u,t.id]:[t.id],h()}),p.value=``,c?b():i()},v=(t,n)=>{Kj(t,[{id:`rename`,label:s.renameOption,icon:`pencil`,run:()=>{let e=window.prompt(s.renameOption,n.name)?.trim();e&&(l=l.map(t=>t.id===n.id?{...t,name:e}:t),o.setOptions(r.id,l),b())}},{id:`color`,label:s.optionColor,icon:`palette`,children:FP.map(t=>({id:t,label:e.colorNames[t]??t,icon:t===n.color?`check`:`drop`,run:()=>{l=l.map(e=>e.id===n.id?{...e,color:t}:e),o.setOptions(r.id,l),b()}}))},{id:`delete`,label:s.deleteOption,icon:`trash`,danger:!0,run:()=>{l=l.filter(e=>e.id!==n.id),u=u.filter(e=>e!==n.id),o.setOptions(r.id,l),b()}}],s.optionColor,()=>p.focus())},y=[];function b(){f.replaceChildren(...u.flatMap(e=>{let t=l.find(t=>t.id===e);return t?[Yz(t.name,t.color,()=>g(e))]:[]}));let e=p.value.trim();y=l.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())).map(e=>({kind:`option`,o:e})),e&&!l.some(t=>t.name.toLowerCase()===e.toLowerCase())&&y.push({kind:`create`,name:e}),d=Math.min(d,Math.max(0,y.length-1)),m.replaceChildren(...y.map((e,t)=>{let n=I(`div`,{class:`dw-db-pop__item${t===d?` is-active`:``}`,role:`option`,"aria-selected":String(e.kind===`option`&&u.includes(e.o.id))});if(n.addEventListener(`mousedown`,e=>e.preventDefault()),e.kind===`option`){n.append(I(`span`,{class:`dw-db-pop__check`},u.includes(e.o.id)?kz(`check`,13):null),Yz(e.o.name,e.o.color));let t=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon dw-db-pop__more`,"aria-label":s.optionColor},kz(`more`,14));t.addEventListener(`click`,n=>{n.stopPropagation(),v(t,e.o)}),n.append(t),n.addEventListener(`click`,()=>g(e.o.id))}else n.append(I(`span`,{class:`dw-db-pop__check`},kz(`plus`,13)),I(`span`,{},LR(s.createOption,e.name))),n.addEventListener(`click`,()=>_(e.name));return n}))}p.addEventListener(`input`,()=>{d=0,b()}),p.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),y.length&&(d=(d+(e.key===`ArrowDown`?1:-1)+y.length)%y.length),b();else if(e.key===`Enter`){e.preventDefault();let t=y[d];t?.kind===`option`?g(t.o.id):t?.kind===`create`?_(t.name):i()}else e.key===`Backspace`&&!p.value&&c&&u.length&&g(u[u.length-1])}),b(),p.focus({preventScroll:!0}),p.setSelectionRange(p.value.length,p.value.length)}function eB(e,t,n,r,i){let a=e.store,o=e.labels,s=rz(QR(n,r)).filter(e=>e?.id),c=I(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),l=I(`input`,{class:`dw-db-input`,placeholder:o.searchPeople,"aria-label":o.searchPeople}),u=I(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(c,l,u);let d=()=>a.setCell(n.id,r.id,s),f=()=>c.replaceChildren(...s.map(e=>Yz(e.name,`gray`,()=>{s=s.filter(t=>t.id!==e.id),d(),f()}))),p=0,m=[],h=0,g=()=>{u.replaceChildren(...m.length?m.map((e,t)=>{let n=I(`div`,{class:`dw-db-pop__item${t===h?` is-active`:``}`,role:`option`},I(`span`,{class:`dw-db-person__dot`},(e.name||`?`).slice(0,1).toUpperCase()),I(`span`,{},e.name));return n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>_(e)),n}):[I(`div`,{class:`dw-db-pop__empty`},l.value.trim()?o.noPeople:``)])},_=e=>{s.some(t=>t.id===e.id)||(s=[...s,e]),d(),l.value=``,m=[],f(),g()};l.addEventListener(`input`,async()=>{let t=l.value.trim(),n=++p,r=e.people&&t?await e.people.search(t).catch(()=>[]):[];n===p&&(m=r.slice(0,8).map(e=>({id:e.id,name:e.label})),h=0,g())}),l.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),m.length&&(h=(h+(e.key===`ArrowDown`?1:-1)+m.length)%m.length),g();else if(e.key===`Enter`){e.preventDefault();let t=m[h];t?_(t):i()}}),f(),g(),l.focus({preventScroll:!0})}function tB(e,t,n,r){let i=e.store,a=e.labels,o=rz(QR(n,r)).filter(e=>e?.src),s=I(`div`,{class:`dw-db-pop__list`}),c=()=>s.replaceChildren(...o.map((t,s)=>{let l=e.files?e.files.resolve(t.src):t.src,u=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":a.remove,title:a.remove},kz(`trash`,14));return u.addEventListener(`click`,()=>{o=o.filter((e,t)=>t!==s),i.setCell(n.id,r.id,o),c()}),I(`div`,{class:`dw-db-pop__item`},I(`a`,{class:`dw-db-file`,href:l,target:`_blank`,rel:`noopener noreferrer`},kz(`paperclip`,12),t.name),u)}));t.append(s);let l=e.files?.upload;if(l){let s=I(`button`,{type:`button`,class:`dw-db__btn`},kz(`upload`,14),I(`span`,{},a.upload));s.addEventListener(`click`,()=>{let t=I(`input`,{type:`file`,multiple:!0});t.onchange=async()=>{for(let a of[...t.files??[]])try{let t=await l.call(e.files,a);o=[...o,{name:t.name,src:t.url,size:t.size,mime:t.mime}],i.setCell(n.id,r.id,o),c()}catch{}},t.click()}),t.append(I(`div`,{class:`dw-db-pop__row`},s))}c()}var nB=class{host;db;rowId;order;onClose;dom;panel;head=I(`div`,{class:`dw-db-peek__head`});props=I(`div`,{class:`dw-db-peek__props`});bodyEl=I(`div`,{class:`dw-db-peek__body`});unmount=null;editing=0;pending=!1;wide=!1;returnFocus;constructor(e,t,n,r,i){this.host=e,this.db=t,this.rowId=n,this.order=r,this.onClose=i,this.returnFocus=document.activeElement,this.panel=I(`div`,{class:`dw-db-peek__panel`,role:`dialog`,"aria-modal":`true`,tabIndex:-1},this.head,this.props,this.bodyEl),this.dom=I(`div`,{class:e.page?`dw-db-peek dw-db-peek--page`:`dw-db-peek`},this.panel),this.dom.addEventListener(`mousedown`,e=>{e.target===this.dom&&!this.host.page&&this.close()}),this.dom.addEventListener(`keydown`,e=>{e.key===`Escape`&&!document.querySelector(`.dw-db-pop, .dw-block-menu`)&&(e.preventDefault(),e.stopPropagation(),this.close())}),e.page?(this.panel.removeAttribute(`aria-modal`),this.panel.setAttribute(`role`,`region`),e.page.container.replaceChildren(this.dom)):document.body.append(this.dom),this.draw(!0),this.panel.focus({preventScroll:!0})}get row(){return this.rowId}ctx(){return{...this.host.ctx,db:this.db,openRow:e=>this.show(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw(!1))}}}update(e,t){if(this.db=e,t&&(this.host={...this.host,ctx:{...this.host.ctx,...t}}),!e.rows.some(e=>e.id===this.rowId))return this.close();this.editing?this.pending=!0:this.draw(!1)}show(e){e!==this.rowId&&(this.rowId=e,this.draw(!0))}draw(e){let t=this.db.rows.find(e=>e.id===this.rowId);if(!t)return;let n=this.ctx(),r=n.labels,i=n.store;this.panel.classList.toggle(`is-wide`,this.wide);let a=this.order.indexOf(this.rowId),o=Az(`chevron-up`,r.previousRow,()=>this.show(this.order[a-1])),s=Az(`chevron-down`,r.nextRow,()=>this.show(this.order[a+1]));o.disabled=a<=0,s.disabled=a<0||a>=this.order.length-1;let c=this.host.page;this.head.replaceChildren(...c?[Az(`chevron-left`,r.backToPage,()=>this.close())]:[],I(`span`,{class:`dw-db-peek__db`},kz(`database`,14),this.db.title||r.untitled),I(`span`,{class:`dw-db-peek__grow`}),o,s,...c?[]:[Az((this.wide,`width`),this.wide?r.collapse:r.expand,()=>{this.wide=!this.wide,this.panel.classList.toggle(`is-wide`,this.wide)})],...this.host.openPage?[Az(`open`,r.openFullPage,()=>this.host.openPage(this.rowId))]:[],...this.host.copyLink?[Az(`link`,r.copyLink,()=>this.host.copyLink(this.rowId))]:[],...c?[]:[Az(`close`,r.close,()=>this.close())]);let l=ZR(this.db),u=String(QR(t,l)??``),d=i?(()=>{let e=I(`input`,{class:`dw-db-peek__title`,placeholder:r.untitledRow,"aria-label":l.name||r.typeTitle});return e.value=u,e.addEventListener(`focus`,()=>n.setEditing(!0)),e.addEventListener(`blur`,()=>{e.value!==u&&i.setCell(t.id,l.id,e.value),n.setEditing(!1)}),e.addEventListener(`keydown`,t=>{t.stopPropagation(),t.key===`Enter`&&e.blur()}),e})():I(`h2`,{class:`dw-db-peek__title`},u||r.untitledRow);this.panel.setAttribute(`aria-label`,u||r.untitledRow);let f=[d,...this.db.columns.filter(e=>e.type!==`title`).map(e=>{let a=I(`div`,{class:`dw-db-peek__value dw-db-t__cell--${e.type}`,tabIndex:i&&!qz.includes(e.type)?0:-1},Zz(n,t,e)),o=()=>{i&&Qz(n,a,t,e,{onDone:()=>this.draw(!1)})};return a.addEventListener(`click`,e=>{e.target.closest(`a, button`)||o()}),a.addEventListener(`keydown`,e=>{e.target===a&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())}),I(`div`,{class:`dw-db-peek__prop`},I(`div`,{class:`dw-db-peek__label`},kz(Gz[e.type],14),I(`span`,{},e.name||NR(r,e.type))),a)})];if(i){let e=Az(`plus`,r.addColumn,()=>Kj(e,HR.map(e=>({id:e,label:NR(r,e),icon:Gz[e],run:()=>i.addColumn(e,NR(r,e))})),r.addColumn),r.addColumn);e.classList.add(`dw-db-peek__add`),f.push(e)}let p=this.props.contains(document.activeElement);this.props.replaceChildren(...f),p&&this.panel.focus({preventScroll:!0}),e&&(this.unmount?.(),this.bodyEl.replaceChildren(),this.unmount=this.host.mountBody(this.bodyEl,t))}close(e=!0){this.unmount?.(),this.unmount=null,this.dom.remove(),this.onClose(),e&&this.host.page?.onLeave?.(),this.returnFocus instanceof HTMLElement&&this.returnFocus.isConnected&&this.returnFocus.focus({preventScroll:!0})}},rB=`docwell-database`,iB=e=>e.getMap(`blocks`);function aB(e){let t=new Bb;t.set(`title`,e.title);let n=(e,t)=>{let n=new Lb;return n.push(e.map((e,n)=>oB(t(e),n))),n};return t.set(`columns`,n(e.columns,sB)),t.set(`rows`,n(e.rows,cB)),t.set(`views`,n(e.views,lB)),t}function oB(e,t){return e.set(`pos`,t),e}function sB(e){let t=new Bb;return t.set(`id`,e.id),t.set(`name`,e.name),t.set(`type`,e.type),e.options&&t.set(`options`,e.options),e.relation&&t.set(`relation`,e.relation),e.rollup&&t.set(`rollup`,e.rollup),t}function cB(e){let t=new Bb;t.set(`id`,e.id),t.set(`createdAt`,e.createdAt),e.createdBy&&t.set(`createdBy`,e.createdBy);let n=new Bb;for(let[t,r]of Object.entries(e.cells))r!=null&&n.set(t,r);return t.set(`cells`,n),t}function lB(e){let t=new Bb;for(let[n,r]of Object.entries(e))t.set(n,r);return t}function uB(e){return e.toArray().filter(e=>e instanceof Bb).map((e,t)=>({m:e,p:dB(e,t),i:t})).sort((e,t)=>e.p-t.p||e.i-t.i).map(e=>e.m)}function dB(e,t){let n=e?.get(`pos`);return typeof n==`number`?n:t}function fB(e,t,n){let r=n?e.filter(e=>e!==n):e,i=Math.max(0,Math.min(t,r.length)),a=i>0?dB(r[i-1],i-1):null,o=i{let n=e.get(t);return n instanceof Lb?uB(n):[]},n=e=>{let t=e.toJSON();return delete t.pos,t},r=new Set,i=t(`rows`).map(e=>{let t=e.get(`cells`),n=e.get(`body`),i=e.get(`id`);return typeof i==`string`&&n instanceof sx&&n.length>0&&r.add(i),{id:i,createdAt:e.get(`createdAt`),createdBy:e.get(`createdBy`),cells:t instanceof Bb?t.toJSON():{}}}),a=qR({title:e.get(`title`),columns:t(`columns`).map(n),rows:i,views:t(`views`).map(n)});for(let e of a.rows)r.has(e.id)&&(e.hasBody=!0);return a}function mB(e,t=``){let n=[{id:WR(),name:e.columnName(`title`),type:`title`},{id:WR(),name:e.columnName(`select`),type:`select`,options:[]}],r=Date.now();return{title:t,columns:n,rows:[0,1,2].map(e=>({id:WR(),cells:{},createdAt:r+e,createdBy:null})),views:[GR(`table`,e.tableView,n)]}}var hB=e=>e==null||e===``||Array.isArray(e)&&!e.length,gB=class{doc;map;me;constructor(e,t,n){this.doc=e,this.map=t,this.me=n}snapshot(){return pB(this.map)}observe(e){let t=()=>e();return this.map.observeDeep(t),()=>this.map.unobserveDeep(t)}tx(e){this.doc.transact(e,rB)}list(e){let t=this.map.get(e);return t instanceof Lb||(t=new Lb,this.map.set(e,t)),t}find(e,t){let n=uB(this.list(e)),r=n.findIndex(e=>e.get(`id`)===t);return r<0?null:{item:n[r],index:r}}insertAt(e,t,n){let r=this.list(e),i=uB(r),a=Math.max(0,Math.min(t??i.length,i.length));for(let e of n)e.set(`pos`,fB(i,a)),i.splice(a++,0,e);r.push(n)}moveTo(e,t,n){let r=this.find(e,t);r&&r.index!==n&&r.item.set(`pos`,fB(uB(this.list(e)),n,r.item))}remove(e,t){let n=this.list(e),r=n.toArray().indexOf(t);r>=0&&n.delete(r,1)}setTitle(e){this.tx(()=>this.map.set(`title`,e))}addColumn(e,t,n){let r={id:WR(),name:t,type:e};return(e===`select`||e===`multiSelect`)&&(r.options=[]),this.tx(()=>this.insertAt(`columns`,n,[sB(r)])),r.id}renameColumn(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`name`,t))}setRelation(e,t){this.tx(()=>{let n=this.find(`columns`,e);if(!n)return;let r=n.item.get(`relation`);if(n.item.set(`relation`,t),t.back||r&&(r.page!==t.page||r.database!==t.database))for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Bb&&n.delete(e)}})}setRollup(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`rollup`,t))}setOptions(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`options`,t))}changeType(e,t){let n=this.snapshot(),r=n.columns.find(t=>t.id===e);if(!r||r.type===t||r.type===`title`||t===`title`)return;let i=t===`select`||t===`multiSelect`?r.options??[]:[],a=new Map;for(let o of n.rows){let n=gz(o.cells[e],r,t,i);i=n.options,a.set(o.id,n.value)}this.tx(()=>{let n=this.find(`columns`,e);if(n){n.item.set(`type`,t),t===`select`||t===`multiSelect`?n.item.set(`options`,i):n.item.delete(`options`),t!==`relation`&&n.item.delete(`relation`),t!==`rollup`&&n.item.delete(`rollup`);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);if(!(n instanceof Bb))continue;let r=a.get(String(t.get(`id`)));hB(r)||r===!1?n.delete(e):n.set(e,r)}}})}deleteColumn(e){this.tx(()=>{let t=this.find(`columns`,e);if(t&&t.item.get(`type`)!==`title`){this.remove(`columns`,t.item);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Bb&&n.delete(e)}}})}moveColumn(e,t){this.tx(()=>this.moveTo(`columns`,e,t))}duplicateColumn(e,t){let n=this.snapshot().columns.find(t=>t.id===e);if(!n||n.type===`title`)return null;let r={...structuredClone(n),id:WR(),name:t};return this.tx(()=>{let t=this.find(`columns`,e);if(t){this.insertAt(`columns`,t.index+1,[sB(r)]);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof Bb&&n.has(e)&&n.set(r.id,n.get(e))}}}),r.id}addRow(e={},t){return this.addRows([e],t)[0]}addRows(e,t){let n=this.me(),r=Date.now(),i=e.map((e,t)=>({id:WR(),cells:e,createdAt:r+t,createdBy:n}));return this.tx(()=>this.insertAt(`rows`,t,i.map(cB))),i.map(e=>e.id)}setCell(e,t,n){this.setCells([{row:e,col:t,value:n}])}setCells(e){this.tx(()=>{for(let{row:t,col:n,value:r}of e){let e=this.find(`rows`,t)?.item.get(`cells`);e instanceof Bb&&(hB(r)?e.delete(n):e.set(n,r))}})}deleteRows(e){this.tx(()=>{let t=this.list(`rows`);for(let n=t.length-1;n>=0;n--)e.includes(String(t.get(n)?.get(`id`)))&&t.delete(n,1)})}moveRow(e,t){this.tx(()=>this.moveTo(`rows`,e,t))}duplicateRow(e){let t=this.find(`rows`,e);if(!t)return null;let n=_B(t.item,this.me());return this.tx(()=>this.insertAt(`rows`,t.index+1,[n])),String(n.get(`id`))}rowBody(e){let t=this.find(`rows`,e);if(!t)return null;let n=t.item.get(`body`);if(n instanceof sx)return n;let r=new sx;return this.tx(()=>t.item.set(`body`,r)),r}rowIndex(e){return this.find(`rows`,e)?.index??-1}addView(e,t){let n=GR(e,t,this.snapshot().columns);return this.tx(()=>this.insertAt(`views`,void 0,[lB(n)])),n.id}updateView(e,t){this.tx(()=>{let n=this.find(`views`,e);if(n)for(let[e,r]of Object.entries(t))n.item.set(e,r)})}duplicateView(e,t){let n=this.snapshot().views.find(t=>t.id===e);if(!n)return null;let r={...structuredClone(n),id:WR(),name:t};return this.tx(()=>{let t=this.find(`views`,e);this.insertAt(`views`,(t?.index??-1)+1,[lB(r)])}),r.id}deleteView(e){this.tx(()=>{let t=this.find(`views`,e);t&&this.list(`views`).length>1&&this.remove(`views`,t.item)})}moveView(e,t){this.tx(()=>this.moveTo(`views`,e,t))}};function _B(e,t){let n=new Bb;n.set(`id`,WR()),n.set(`createdAt`,Date.now());let r=t??e.get(`createdBy`);XR(r)&&n.set(`createdBy`,r);let i=new Bb,a=e.get(`cells`);if(a instanceof Bb)for(let[e,t]of a.entries())i.set(e,t);n.set(`cells`,i);let o=e.get(`body`);if(o instanceof sx&&o.length){let e=new sx;e.insert(0,o.toArray().map(e=>e.clone())),n.set(`body`,e)}return n}function vB(e,t){let n=pB(e),r=e.get(`rows`);if(r instanceof Lb){let e=new Map;for(let t of r.toArray()){let n=t.get(`body`);n instanceof sx&&n.length&&e.set(String(t.get(`id`)),n)}for(let r of n.rows){let n=e.get(r.id);n&&(r.body=t(n))}}return n}function yB(e,t,n,r){e.transact(()=>{let i=aB(n);iB(e).set(t,i);let a=i.get(`rows`),o=new Map(n.rows.map(e=>[e.id,e]));for(let e of a.toArray()){let t=o.get(String(e.get(`id`)))?.body;if(!t?.length)continue;let n=new sx;e.set(`body`,n),r(t,n)}},rB)}function bB(e,t=`,`){let n=[],r=[],i=``,a=!1,o=0,s=e.replace(/^\uFEFF/,``);for(;o({tr:r,dispatch:i,editor:a})=>{let o=uP(a.schema,e,t,n);if(i){let e=r.selection.from+1;r.replaceSelectionWith(o).scrollIntoView().setSelection(T.near(r.doc.resolve(e)))}return!0},addColumnBefore:()=>({state:e,dispatch:t})=>zM(e,t),addColumnAfter:()=>({state:e,dispatch:t})=>BM(e,t),deleteColumn:()=>({state:e,dispatch:t})=>{let n=_u(e.selection.$from,e=>e.type.name===`table`);return HM(e,t&&(e=>{n&&pP(e,n.pos),t(e)}))},addRowBefore:()=>({state:e,dispatch:t})=>GM(e,t),addRowAfter:()=>({state:e,dispatch:t})=>KM(e,t),deleteRow:()=>({state:e,dispatch:t})=>{let n=_u(e.selection.$from,e=>e.type.name===`table`);return JM(e,t&&(e=>{n&&pP(e,n.pos),t(e)}))},deleteTable:()=>({state:e,dispatch:t})=>sN(e,t),mergeCells:()=>({state:e,dispatch:t})=>ZM(e,t),splitCell:()=>({state:e,dispatch:t})=>QM(e,t),toggleHeaderColumn:()=>({state:e,dispatch:t})=>rN(`column`)(e,t),toggleHeaderRow:()=>({state:e,dispatch:t})=>rN(`row`)(e,t),toggleHeaderCell:()=>({state:e,dispatch:t})=>iN(e,t),mergeOrSplit:()=>({state:e,dispatch:t})=>ZM(e,t)?!0:QM(e,t),setCellAttribute:(e,t)=>({state:n,dispatch:r})=>eN(e,t)(n,r),goToNextCell:()=>({state:e,dispatch:t})=>oN(1)(e,t),goToPreviousCell:()=>({state:e,dispatch:t})=>oN(-1)(e,t),fixTables:()=>({state:e,dispatch:t})=>(t&&FM(e),!0),setCellSelection:e=>({tr:t,dispatch:n})=>{if(n){let n=DM.create(t.doc,e.anchorCell,e.headCell);t.setSelection(n)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:fP,"Mod-Backspace":fP,Delete:fP,"Mod-Delete":fP}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[AN({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:null,lastColumnResizable:this.options.lastColumnResizable})]:[],WN({allowTableNodeSelection:this.options.allowTableNodeSelection}),CP()]},addNodeView(){let e=this.options.View;return e?({node:t,view:n,HTMLAttributes:r})=>{let i=j(this.options.HTMLAttributes,r);return new e(t,this.options.cellMinWidth,n,i)}:null},extendNodeSchema(e){return{tableRole:Mu(A(e,`tableRole`,{name:e.name,options:e.options,storage:e.storage}))}}}),TP=wp.create({name:`tableKit`,addExtensions(){let e=[];return this.options.table!==!1&&e.push(wP.configure(this.options.table)),this.options.tableCell!==!1&&e.push(tP.configure(this.options.tableCell)),this.options.tableHeader!==!1&&e.push(nP.configure(this.options.tableHeader)),this.options.tableRow!==!1&&e.push(rP.configure(this.options.tableRow)),e}}),EP=wp.create({name:`textAlign`,addOptions(){return{types:[],alignments:[`left`,`center`,`right`,`justify`],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:e=>{let t=e.style.textAlign;return this.options.alignments.includes(t)?t:this.options.defaultAlignment},renderHTML:e=>!Nf(e.textAlign)||!this.options.alignments.includes(e.textAlign)?{}:{style:`text-align: ${e.textAlign}`}}}}]},addCommands(){return{setTextAlign:e=>({commands:t})=>this.options.alignments.includes(e)?this.options.types.map(n=>t.updateAttributes(n,{textAlign:e})).some(e=>e):!1,unsetTextAlign:()=>({commands:e})=>this.options.types.map(t=>e.resetAttributes(t,`textAlign`)).some(e=>e),toggleTextAlign:e=>({editor:t,commands:n})=>this.options.alignments.includes(e)?t.isActive({textAlign:e})?n.unsetTextAlign():n.setTextAlign(e):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign(`left`),"Mod-Shift-e":()=>this.editor.commands.setTextAlign(`center`),"Mod-Shift-r":()=>this.editor.commands.setTextAlign(`right`),"Mod-Shift-j":()=>this.editor.commands.setTextAlign(`justify`)}}});function DP(){return[zk.configure({HTMLAttributes:{class:`dw-tasks`}}),Rk.configure({nested:!0})]}function OP(){return[TP.configure({table:{resizable:!0,cellMinWidth:60,HTMLAttributes:{class:`dw-table`}}})]}var kP=EP.configure({types:[`heading`,`paragraph`],alignments:[`left`,`center`,`right`]}),AP=wp.create({name:`headingShortcuts`,addKeyboardShortcuts(){let e={"Mod-Shift-0":()=>this.editor.commands.setParagraph()};for(let t of[1,2,3,4,5,6])e[`Mod-Shift-${t}`]=()=>this.editor.commands.toggleHeading({level:t});return e}}),jP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/,MP=/(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g,NP=gp.create({name:`highlight`,addOptions(){return{multicolor:!1,HTMLAttributes:{}}},addAttributes(){return this.options.multicolor?{color:{default:null,parseHTML:e=>e.getAttribute(`data-color`)||kf(e,`background-color`)||e.style.backgroundColor,renderHTML:e=>Nf(e.color)?{"data-color":e.color,style:`background-color: ${e.color}; color: inherit`}:{}}}:{}},parseHTML(){return[{tag:`mark`}]},renderHTML({HTMLAttributes:e}){return[`mark`,j(this.options.HTMLAttributes,e),0]},renderMarkdown:(e,t)=>`==${t.renderChildren(e)}==`,parseMarkdown:(e,t)=>t.applyMark(`highlight`,t.parseInline(e.tokens||[])),markdownTokenizer:{name:`highlight`,level:`inline`,start:e=>e.indexOf(`==`),tokenize(e,t,n){let r=/^(==)(?!\s)([^=]*[^=\s])(==)/.exec(e);if(r){let e=r[2].trim(),t=n.inlineTokens(e);return{type:`highlight`,raw:r[0],text:e,tokens:t}}}},addCommands(){return{setHighlight:e=>({commands:t})=>t.setMark(this.name,e),toggleHighlight:e=>({commands:t})=>t.toggleMark(this.name,e),unsetHighlight:()=>({commands:e})=>e.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-h":()=>this.editor.commands.toggleHighlight()}},addInputRules(){return[Vp({find:jP,type:this.type})]},addPasteRules(){return[Jp({find:MP,type:this.type})]}}),PP=[`gray`,`red`,`orange`,`yellow`,`green`,`teal`,`blue`,`purple`,`pink`],FP=e=>typeof e==`string`&&PP.includes(e),IP=gp.create({name:`textColor`,addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return FP(t)?t:null},renderHTML:e=>e.color?{"data-color":e.color}:{}}}},parseHTML(){return[{tag:`span[data-color]`,getAttrs:e=>FP(e.getAttribute(`data-color`))?{}:!1}]},renderHTML({HTMLAttributes:e}){return[`span`,j(e,{class:`dw-text-color`}),0]},addCommands(){return{setTextColor:e=>({commands:t})=>t.setMark(this.name,{color:e}),unsetTextColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),LP=NP.extend({addOptions(){return{...this.parent(),multicolor:!0}},addAttributes(){return{color:{default:null,parseHTML:e=>{let t=e.getAttribute(`data-color`);return FP(t)?t:null},renderHTML:e=>({"data-color":FP(e.color)?e.color:`yellow`})}}},renderHTML({HTMLAttributes:e}){return[`mark`,j(e,{class:`dw-highlight`}),0]}}),RP=`💡`;function zP(e){let t=e.trim();return t&&[...t].length<=4?t:``}var BP=qp.create({name:`callout`,group:`block`,content:`block+`,defining:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{emoji:{default:RP,parseHTML:e=>zP(e.getAttribute(`data-emoji`)??``)||RP,renderHTML:e=>({"data-emoji":e.emoji})},color:{default:`blue`,parseHTML:e=>{let t=e.getAttribute(`data-color`);return FP(t)?t:`blue`},renderHTML:e=>({"data-color":e.color})}}},parseHTML(){return[{tag:`aside[data-type=callout]`,contentElement:e=>e.querySelector(`:scope > .callout-body`)??e}]},renderHTML({HTMLAttributes:e}){return[`aside`,j(e,{"data-type":`callout`,class:`dw-callout`}),0]},addCommands(){return{setCallout:e=>({commands:t})=>t.wrapIn(this.name,e),unsetCallout:()=>({commands:e})=>e.lift(this.name)}},addKeyboardShortcuts(){return{Backspace:({editor:e})=>{let{$from:t,empty:n}=e.state.selection;if(!n||t.parentOffset>0)return!1;for(let n=t.depth-1;n>0;n--){if(t.node(n).type.name===this.name)return t.index(n)!==0||t.start(n+1)!==t.start()?!1:e.commands.lift(this.name);if(t.index(n)!==0)return!1}return!1}}},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=document.createElement(`aside`);i.className=`dw-callout`,i.setAttribute(`data-type`,`callout`);let a=document.createElement(`div`);a.className=`dw-callout__side`,a.contentEditable=`false`;let o=document.createElement(`button`);o.type=`button`,o.className=`dw-callout__emoji`;let s=document.createElement(`button`);s.type=`button`,s.className=`dw-callout__color`,a.append(o,s);let c=document.createElement(`div`);c.className=`dw-callout__body`,i.append(a,c);let l=e,u=e=>{let r=t();typeof r==`number`&&n.isEditable&&n.view.dispatch(n.state.tr.setNodeMarkup(r,void 0,{...l.attrs,...e}))};o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>{if(!n.isEditable)return;let e=zP(window.prompt(r?.blocks.calloutEmoji??`Emoji`,l.attrs.emoji)??``);e&&u({emoji:e})}),s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`click`,()=>{let e=PP.indexOf(l.attrs.color);u({color:PP[(e+1)%PP.length]})});let d=()=>{i.setAttribute(`data-color`,String(l.attrs.color)),o.textContent=String(l.attrs.emoji);let e=r?.blocks.calloutEmoji??`Emoji`;o.setAttribute(`aria-label`,e),o.title=e;let t=r?.blocks.calloutColor??`Colour`;s.setAttribute(`aria-label`,t),s.title=t};return d(),{dom:i,contentDOM:c,update:t=>t.type===e.type&&(l=t,d(),!0),stopEvent:e=>a.contains(e.target),ignoreMutation:e=>a.contains(e.target)}}}}),VP=10;function HP(e){let t=typeof e==`string`?parseFloat(e):typeof e==`number`?e:NaN;return Number.isFinite(t)&&t>0&&t<=100?Math.round(t*10)/10:null}function UP(e){let t=[];e.forEach(e=>t.push(HP(e.attrs.width)));let n=t.reduce((e,t)=>e+(t??0),0),r=t.filter(e=>e===null).length,i=r?Math.max(100-n,r*VP)/r:0,a=t.map(e=>e??i),o=a.reduce((e,t)=>e+t,0)||1;return a.map(e=>e*100/o)}function WP(e){let{$from:t}=e.state.selection;for(let e=t.depth;e>0;e--)if(t.node(e).type.name===`columns`)return e;return-1}function GP(e,t=null){let{schema:n}=e.state;return n.nodes.column.create({width:t},n.nodes.paragraph.create())}function KP(e){return e.childCount===1&&e.firstChild.type.name===`paragraph`&&e.firstChild.content.size===0}var qP=qp.create({name:`columns`,group:`block`,content:`column{2,5}`,defining:!0,isolating:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`div[data-type=columns]`}]},renderHTML({HTMLAttributes:e}){return[`div`,j(e,{"data-type":`columns`,class:`dw-columns`}),0]},addCommands(){return{insertColumns:(e=2)=>({editor:t,tr:n,dispatch:r})=>{let i=Math.min(Math.max(Math.round(e),2),5),a=t.schema.nodes.columns.create(null,Array.from({length:i},()=>GP(t)));if(!r)return!0;let o=n.selection.from;n.replaceSelectionWith(a);let s=-1;return n.doc.nodesBetween(o,Math.min(o+a.nodeSize+2,n.doc.content.size),(e,t)=>(s<0&&e.type.name===`columns`&&(s=t),s<0)),s>=0&&n.setSelection(T.create(n.doc,s+3)),n.scrollIntoView(),!0},addColumn:()=>({editor:e,tr:t,dispatch:n})=>{let r=WP(e);if(r<0)return!1;let{$from:i}=t.selection,a=i.node(r);if(a.childCount>=5)return!1;if(!n)return!0;let o=i.index(r),s=i.before(r),c=UP(a),l=100/(a.childCount+1),u=(100-l)/100,d=s+1;a.forEach((e,n,r)=>{t.setNodeMarkup(t.mapping.map(d),void 0,{...e.attrs,width:c[r]*u}),d+=e.nodeSize});let f=s+1;for(let e=0;e<=o;e++)f+=a.child(e).nodeSize;let p=t.mapping.map(f);return t.insert(p,GP(e,l)),t.setSelection(T.create(t.doc,p+2)),!0},unsetColumns:()=>({editor:e,tr:t,dispatch:n})=>{let r=WP(e);if(r<0)return!1;if(!n)return!0;let{$from:i}=t.selection,a=i.node(r),o=[];a.forEach(e=>{KP(e)||e.forEach(e=>o.push(e))}),o.length||o.push(e.schema.nodes.paragraph.create());let c=i.before(r);return t.replaceWith(c,c+a.nodeSize,s.from(o)),t.setSelection(T.near(t.doc.resolve(c+1))),!0}}},addKeyboardShortcuts(){return{Backspace:({editor:e})=>{let{$from:t,empty:n}=e.state.selection;if(!n||t.parentOffset>0)return!1;let r=WP(e);if(r<0||t.depth!==r+2)return!1;let i=t.node(r),a=t.node(r+1);if(!KP(a))return!1;if(i.childCount<=2)return e.commands.unsetColumns();let o=t.index(r),s=t.before(r+1),c=e.state.tr.delete(s,s+a.nodeSize),l=t.before(r),u=c.doc.nodeAt(l),d=UP(u),f=l+1;u.forEach((e,t,n)=>{c.setNodeMarkup(f,void 0,{...e.attrs,width:d[n]}),f+=e.nodeSize});let p=Math.max(o-1,0),m=l+1;for(let e=0;e<=p;e++)m+=c.doc.nodeAt(l).child(e).nodeSize;return c.setSelection(T.near(c.doc.resolve(m-1),-1)),e.view.dispatch(c.scrollIntoView()),!0},"Mod-Alt-ArrowRight":({editor:e})=>e.commands.addColumn()}}}),JP=qp.create({name:`column`,content:`block+`,isolating:!0,addOptions(){return{labels:null}},addAttributes(){return{width:{default:null,parseHTML:e=>HP(e.getAttribute(`data-width`)),renderHTML:e=>e.width==null?{}:{"data-width":String(HP(e.width))}}}},parseHTML(){return[{tag:`div[data-type=column]`}]},renderHTML({HTMLAttributes:e}){return[`div`,j(e,{"data-type":`column`,class:`dw-column`}),0]},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=document.createElement(`div`);i.className=`dw-column`,i.setAttribute(`data-type`,`column`);let a=document.createElement(`div`);a.className=`dw-column__body`;let o=document.createElement(`div`);o.className=`dw-column__resize`,o.contentEditable=`false`,o.setAttribute(`role`,`separator`),o.setAttribute(`aria-orientation`,`vertical`);let s=document.createElement(`button`);s.type=`button`,s.className=`dw-column__add`,s.contentEditable=`false`,s.textContent=`+`,i.append(a,o,s);let c=()=>{let e=t();if(typeof e!=`number`)return null;let r=n.state.doc.resolve(e),i=r.parent;return i.type.name===`columns`?{row:i,index:r.index(),rowPos:r.before()}:null},l=()=>{let e=c(),t=e?UP(e.row):[100],n=e?t[e.index]:100;i.style.flexGrow=String(n);let a=!e||e.index===e.row.childCount-1;o.hidden=a,s.hidden=!e||e.row.childCount>=5;let l=r?.blocks.resizeColumn??`Drag to resize`;o.title=l,o.setAttribute(`aria-label`,l);let u=r?.blocks.addColumn??`Add a column`;s.title=u,s.setAttribute(`aria-label`,u)};return l(),s.addEventListener(`mousedown`,e=>e.preventDefault()),s.addEventListener(`click`,()=>{let e=t();typeof e==`number`&&n.isEditable&&n.chain().setTextSelection(e+2).addColumn().focus().run()}),o.addEventListener(`pointerdown`,e=>{let t=c();if(!t||!n.isEditable||t.index>=t.row.childCount-1)return;e.preventDefault();let r=i.parentElement,a=i.nextElementSibling;if(!r||!a)return;let s=r.getBoundingClientRect().width||1,u=UP(t.row),d=u[t.index]+u[t.index+1],f=e.clientX,p=u[t.index],m=p;o.setPointerCapture(e.pointerId),i.classList.add(`is-resizing`);let h=e=>{m=Math.min(Math.max(p+(e.clientX-f)*100/s,VP),d-VP),i.style.flexGrow=String(m),a.style.flexGrow=String(d-m)},g=()=>{o.removeEventListener(`pointermove`,h),o.removeEventListener(`pointerup`,g),o.removeEventListener(`pointercancel`,g),i.classList.remove(`is-resizing`);let e=c();if(!e||Math.abs(m-p)<.5)return l();let t=UP(e.row);t[e.index]=m,t[e.index+1]=d-m;let r=n.state.tr,a=e.rowPos+1;e.row.forEach((e,n,i)=>{r.setNodeMarkup(a,void 0,{...e.attrs,width:Math.round(t[i]*10)/10}),a+=e.nodeSize}),n.view.dispatch(r)};o.addEventListener(`pointermove`,h),o.addEventListener(`pointerup`,g),o.addEventListener(`pointercancel`,g)}),{dom:i,contentDOM:a,update:t=>t.type===e.type&&(l(),!0),stopEvent:e=>o.contains(e.target)||s.contains(e.target),ignoreMutation:e=>o.contains(e.target)||s.contains(e.target)||e.type===`attributes`&&e.target===i}}}}),YP=e=>[e.x+e.w/2,e.y+e.h/2];function XP(e){if(!e.length)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.w),i=Math.max(i,a.y+a.h);return{x:t,y:n,w:r-t,h:i-n}}var ZP=(e,t)=>({x:e.x-t,y:e.y-t,w:e.w+2*t,h:e.h+2*t}),QP=(e,t)=>e.x<=t.x+t.w&&t.x<=e.x+e.w&&e.y<=t.y+t.h&&t.y<=e.y+e.h,$P=(e,t)=>t.x>=e.x&&t.y>=e.y&&t.x+t.w<=e.x+e.w&&t.y+t.h<=e.y+e.h;function eF(e,t){return{x:Math.min(e[0],t[0]),y:Math.min(e[1],t[1]),w:Math.abs(e[0]-t[0]),h:Math.abs(e[1]-t[1])}}function tF([e,t],[n,r],i){if(!i)return[e,t];let a=i*Math.PI/180,o=Math.cos(a),s=Math.sin(a);return[n+(e-n)*o-(t-r)*s,r+(e-n)*s+(t-r)*o]}function nF(e,t){if(!t)return e;let n=YP(e),r=[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>tF(e,n,t));return eF([Math.min(...r.map(e=>e[0])),Math.min(...r.map(e=>e[1]))],[Math.max(...r.map(e=>e[0])),Math.max(...r.map(e=>e[1]))])}function rF([e,t],[n,r],[i,a]){let o=i-n,s=a-r,c=o*o+s*s,l=c?Math.max(0,Math.min(1,((e-n)*o+(t-r)*s)/c)):0;return Math.hypot(e-(n+l*o),t-(r+l*s))}function iF(e,t){if(t.length===1)return Math.hypot(e[0]-t[0][0],e[1]-t[0][1]);let n=1/0;for(let r=1;re[1]-t[1]),r[0][0]}var oF={left:[-1,0],right:[1,0],top:[0,-1],bottom:[0,1]};function sF(e,t,n=!1){let[r,i]=YP(e),a=t[0]-r,o=t[1]-i;if(!a&&!o)return[r,i];let s=Math.max(e.w/2,.5),c=Math.max(e.h/2,.5),l=n?1/Math.sqrt(a*a/(s*s)+o*o/(c*c)):Math.min(Math.abs(s/(a||1e-9)),Math.abs(c/(o||1e-9)));return[r+a*l,i+o*l]}var cF=e=>[[`top`,[e.x+e.w/2,e.y]],[`right`,[e.x+e.w,e.y+e.h/2]],[`bottom`,[e.x+e.w/2,e.y+e.h]],[`left`,[e.x,e.y+e.h/2]]];function lF(e,t){let n=e=>{if(!e.id)return[e.x??0,e.y??0];let n=t(e.id);return n?e.pos?[n.box.x+n.box.w*e.pos[0],n.box.y+n.box.h*e.pos[1]]:null:[e.x??0,e.y??0]},r=e=>{let n=e.id?t(e.id):null;return n?YP(n.box):[e.x??0,e.y??0]},i=(e,i)=>{let a=n(e),o=e.id?t(e.id):null;if(a)return{at:a,side:o?aF(o.box,a):null};let s=sF(o.box,n(i)??r(i),o.ellipse);return{at:s,side:aF(o.box,s)}};return[i(e.source,e.target),i(e.target,e.source)]}var uF=e=>Math.round(e*100)/100,dF=e=>e.map((e,t)=>`${t?`L`:`M`}${uF(e[0])} ${uF(e[1])}`).join(` `),fF=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);function pF(e,t,n){let[r,i]=t.at,[a,o]=n.at,s=Math.hypot(a-r,o-i);if(e===`straight`||s<1)return{points:[t.at,n.at],d:dF([t.at,n.at]),mid:[(r+a)/2,(i+o)/2],startAngle:fF(n.at,t.at),endAngle:fF(t.at,n.at)};if(e===`curve`){let e=Math.min(s/2,160),c=t.side?oF[t.side]:mF(t.at,n.at),l=n.side?oF[n.side]:mF(n.at,t.at),u=[r+c[0]*e,i+c[1]*e],d=[a+l[0]*e,o+l[1]*e],f=[];for(let e=0;e<=24;e++)f.push(hF(t.at,u,d,n.at,e/24));return{points:f,d:`M${uF(r)} ${uF(i)} C${uF(u[0])} ${uF(u[1])} ${uF(d[0])} ${uF(d[1])} ${uF(a)} ${uF(o)}`,mid:hF(t.at,u,d,n.at,.5),startAngle:fF(u,t.at),endAngle:fF(d,n.at)}}let c=t.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`right`:`left`:o>i?`bottom`:`top`),l=n.side??(Math.abs(a-r)>Math.abs(o-i)?a>r?`left`:`right`:o>i?`top`:`bottom`),u=[r+oF[c][0]*24,i+oF[c][1]*24],d=[a+oF[l][0]*24,o+oF[l][1]*24],f=c===`left`||c===`right`,p=l===`left`||l===`right`,m;if(f&&p){let e=(u[0]+d[0])/2;m=[[e,u[1]],[e,d[1]]]}else if(!f&&!p){let e=(u[1]+d[1])/2;m=[[u[0],e],[d[0],e]]}else m=f?[[d[0],u[1]]]:[[u[0],d[1]]];let h=gF([t.at,u,...m,d,n.at]);return{points:h,d:dF(h),mid:_F(h),startAngle:fF(h[1]??n.at,t.at),endAngle:fF(h[h.length-2]??t.at,n.at)}}function mF(e,t){let n=Math.hypot(t[0]-e[0],t[1]-e[1])||1;return[(t[0]-e[0])/n,(t[1]-e[1])/n]}function hF(e,t,n,r,i){let a=1-i,o=a*a*a,s=3*a*a*i,c=3*a*i*i,l=i*i*i;return[o*e[0]+s*t[0]+c*n[0]+l*r[0],o*e[1]+s*t[1]+c*n[1]+l*r[1]]}function gF(e){let t=[];for(let n of e){let e=t[t.length-1];if(e&&Math.abs(e[0]-n[0])<.01&&Math.abs(e[1]-n[1])<.01)continue;let r=t[t.length-2];if(r&&e){let i=(e[0]-r[0])*(n[1]-r[1])-(e[1]-r[1])*(n[0]-r[0]);Math.abs(i)<.01&&t.pop()}t.push(n)}return t}function _F(e){let t=0;for(let n=1;n=n&&a>0)return[r[0]+(i[0]-r[0])*n/a,r[1]+(i[1]-r[1])*n/a];n-=a}return e[0]??[0,0]}function vF(e,t,n){let r=e=>[e.x,e.x+e.w/2,e.x+e.w],i=e=>[e.y,e.y+e.h/2,e.y+e.h],a={dx:0,ox:null,vx:0},o={dy:0,oy:null,vy:0},s=n+1,c=n+1;for(let n of t){for(let t of r(e))for(let e of r(n)){let r=Math.abs(e-t);rtypeof e==`string`&&SF.includes(e),wF=[`rect`,`roundrect`,`ellipse`,`diamond`,`triangle`],TF=[`straight`,`curve`,`elbow`],EF=[`none`,`arrow`,`triangle`,`circle`,`diamond`],DF=[`right`,`left`,`radial`],OF=`page`,kF=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:t,AF=(e,t=``)=>typeof e==`string`?e:t,jF=e=>e===!0,MF=(e,t)=>CF(e)?e:t,NF=(e,t,n)=>typeof e==`string`&&t.includes(e)?e:n;function PF(e){if(!e||typeof e!=`object`)return{x:0,y:0};let t=e,n={};return typeof t.id==`string`&&t.id&&(n.id=t.id),Array.isArray(t.pos)&&t.pos.length===2&&(n.pos=[kF(t.pos[0],.5),kF(t.pos[1],.5)]),n.id||(n.x=kF(t.x,0),n.y=kF(t.y,0)),n}function FF(e){let t={};if(!e||typeof e!=`object`)return t;for(let[n,r]of Object.entries(e)){if(!r||typeof r!=`object`)continue;let e=r;t[n]={text:AF(e.text),parent:AF(e.parent),pos:kF(e.pos,0)}}return t}function IF(e){let t={id:AF(e.id),index:kF(e.index,0),x:kF(e.x,0),y:kF(e.y,0),w:Math.max(0,kF(e.w,0)),h:Math.max(0,kF(e.h,0)),rotate:kF(e.rotate,0),group:AF(e.group)};switch(e.type){case`shape`:return{...t,type:`shape`,shape:NF(e.shape,wF,`rect`),stroke:MF(e.stroke,`ink`),fill:MF(e.fill,`none`),strokeWidth:kF(e.strokeWidth,2),strokeStyle:NF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),rough:jF(e.rough),text:AF(e.text),textColor:MF(e.textColor,`ink`),fontSize:kF(e.fontSize,18)};case`text`:return{...t,type:`text`,text:AF(e.text),color:MF(e.color,`ink`),fontSize:kF(e.fontSize,24),font:NF(e.font,[``,`serif`,`mono`],``),align:NF(e.align,[`left`,`center`,`right`],`left`),bold:jF(e.bold)};case`connector`:return{...t,type:`connector`,source:PF(e.source),target:PF(e.target),mode:NF(e.mode,TF,`curve`),stroke:MF(e.stroke,`ink`),strokeWidth:kF(e.strokeWidth,2),strokeStyle:NF(e.strokeStyle,[`solid`,`dash`,`none`],`solid`),startArrow:NF(e.startArrow,EF,`none`),endArrow:NF(e.endArrow,EF,`arrow`),label:AF(e.label),rough:jF(e.rough)};case`brush`:return{...t,type:`brush`,points:Array.isArray(e.points)?e.points.filter(e=>Array.isArray(e)&&e.length>=2).map(e=>[kF(e[0],0),kF(e[1],0),kF(e[2],.5)]):[],color:MF(e.color,`ink`),size:kF(e.size,4)};case`note`:return{...t,type:`note`,page:jF(e.page),background:MF(e.background,`paper`)};case`frame`:return{...t,type:`frame`,title:AF(e.title),background:MF(e.background,`none`)};case`image`:return{...t,type:`image`,src:AF(e.src),alt:AF(e.alt)};case`embed`:return{...t,type:`embed`,url:AF(e.url)};case`group`:return{...t,type:`group`,title:AF(e.title)};case`mindmap`:return{...t,type:`mindmap`,layout:NF(e.layout,DF,`right`),color:MF(e.color,`blue`),nodes:FF(e.nodes)};default:return null}}var LF=e=>![`connector`,`group`,`mindmap`].includes(e.type),RF=e=>[`shape`,`text`,`image`,`brush`].includes(e.type),zF=e=>![`connector`,`brush`,`group`].includes(e.type),BF=0;function VF(){return BF=(BF+1)%1296,Date.now().toString(36).slice(-6)+BF.toString(36).padStart(2,`0`)+Math.random().toString(36).slice(2,8)}var HF={shape:{shape:`rect`,stroke:`blue`,fill:`blue`,strokeWidth:2,strokeStyle:`solid`,rough:!1,textColor:`ink`},connector:{mode:`curve`,stroke:`gray`,strokeWidth:2,strokeStyle:`solid`,startArrow:`none`,endArrow:`arrow`},brush:{color:`ink`,size:4},text:{color:`ink`,fontSize:24,font:``},note:{background:`yellow`},frame:{background:`none`},mindmap:{layout:`right`,color:`blue`}};function UF(e){let t=structuredClone(HF);if(!e||typeof e!=`object`)return t;for(let n of Object.keys(t)){let r=e[n];if(!r||typeof r!=`object`)continue;let i=IF({...t[n],...r,type:n===`note`?`note`:n});if(i)for(let e of Object.keys(t[n])){let a=r[e];a!==void 0&&i[e]===a&&(t[n][e]=a)}}return t}var WF=[`👍`,`⭐`,`❤️`,`✅`,`❌`,`💡`,`❓`,`❗`,`🎉`,`🔥`,`📌`,`🚀`,`👀`,`🎯`,`⚠️`,`🙂`];function GF(e){return[{id:VF(),type:`text`,text:e,fontSize:64,x:0,y:0,w:0,h:0}]}var KF=[`kanban`,`swot`,`flow`,`brainstorm`,`retro`],qF=e=>[{type:`paragraph`,content:e?[{type:`text`,text:e}]:[]}],JF=(e,t,n,r,i,a=`none`)=>({id:VF(),type:`frame`,title:e,x:t,y:n,w:r,h:i,background:a}),YF=(e,t,n,r,i=220)=>({id:VF(),type:`note`,background:r,x:t,y:n,w:i,h:90,body:qF(e)}),XF=(e,t,n,r,i,a,o)=>({id:VF(),type:`shape`,shape:e,text:t,x:n,y:r,w:i,h:a,stroke:o,fill:o,strokeWidth:2}),ZF=(e,t,n=`elbow`)=>({id:VF(),type:`connector`,source:{id:e},target:{id:t},mode:n,stroke:`gray`,endArrow:`arrow`});function QF(e,t){switch(e){case`kanban`:return[[t.todo,`gray`],[t.doing,`blue`],[t.done,`green`]].flatMap(([e,t],n)=>[JF(e,n*300,0,280,520),YF(``,n*300+30,50,t),YF(``,n*300+30,170,t)]);case`swot`:return[[t.strengths,`green`],[t.weaknesses,`red`],[t.opportunities,`blue`],[t.threats,`orange`]].flatMap(([e,t],n)=>[XF(`roundrect`,e,n%2*380,Math.floor(n/2)*300,360,280,t)]);case`flow`:{let e=XF(`ellipse`,t.start,0,0,180,70,`green`),n=XF(`rect`,t.step,0,140,180,80,`blue`),r=XF(`diamond`,t.decision,-10,290,200,120,`orange`),i=XF(`rect`,t.step,280,310,180,80,`blue`),a=XF(`ellipse`,t.end,0,480,180,70,`red`);return[e,n,r,i,a,ZF(e.id,n.id),ZF(n.id,r.id),ZF(r.id,i.id),ZF(r.id,a.id)]}case`brainstorm`:{let e=VF(),n={[e]:{text:t.centralIdea,parent:``,pos:0}};for(let r=0;r<4;r++)n[VF()]={text:`${t.idea} ${r+1}`,parent:e,pos:r};return[{id:VF(),type:`mindmap`,layout:`radial`,color:`purple`,x:0,y:0,nodes:n}]}case`retro`:return[[t.wentWell,`green`],[t.toImprove,`orange`],[t.actions,`blue`]].flatMap(([e,t],n)=>[JF(e,n*300,0,280,420),YF(``,n*300+30,50,t)])}}var $F;function eI(){if($F!==void 0)return $F;try{$F=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{$F=null}return $F}var tI=`"Inter Variable", Inter, ui-sans-serif, system-ui, sans-serif`,nI=`"Source Serif 4 Variable", "Source Serif 4", Georgia, serif`,rI=`"JetBrains Mono Variable", "JetBrains Mono", ui-monospace, monospace`;function iI(e){return e===`serif`?nI:e===`mono`?rI:tI}function aI(e,t,n=tI,r=400){let i=eI();return i?(i.font=`${r} ${t}px ${n}`,i.measureText(e).width):e.length*t*.56}function oI(e,t,n,r=tI,i=400){let a=[];for(let o of e.split(` +`)){if(!o){a.push(``);continue}let e=``;for(let s of o.split(/(\s+)/)){let o=e+s;if(!e||aI(o,t,r,i)<=n)e=o;else for(a.push(e.trimEnd()),e=s.trimStart();e&&aI(e,t,r,i)>n;){let o=e.length-1;for(;o>1&&aI(e.slice(0,o),t,r,i)>n;)o--;a.push(e.slice(0,o)),e=e.slice(o)}}a.push(e)}return a}function sI(e,t){let n=t===0?18:15,r=t===0?600:400,i=oI(e||` `,n,260,tI,r),a=Math.max(...i.map(e=>aI(e,n,tI,r)),t===0?60:40);return{w:Math.ceil(a)+(t===0?32:24),h:i.length*Math.round(n*1.4)+(t===0?20:14)}}var cI=56,lI=14;function uI(e){let t=Object.entries(e).filter(([,t])=>!t.parent||!e[t.parent]);return t.sort((e,t)=>e[1].pos-t[1].pos||(e[0]n.parent===t&&e!==t).sort((e,t)=>e[1].pos-t[1].pos||(e[0]e)}function fI(e,t,n){let r=uI(e),i=new Map,a=[];if(!r)return{root:``,boxes:i,edges:a,bounds:{x:0,y:0,w:0,h:0}};let o=new Map,s=new Set,c=(t,r)=>{if(!(s.has(t)||r>50)){s.add(t),o.set(t,n(e[t].text,r));for(let n of dI(e,t))c(n,r+1)}};c(r,0);let l=t=>dI(e,t).filter(e=>o.has(e)),u=new Map,d=e=>{let t=u.get(e);if(t!==void 0)return t;let n=l(e),r=n.reduce((e,t)=>e+d(t),0)+lI*Math.max(0,n.length-1),i=Math.max(o.get(e).h,r);return u.set(e,i),i},f=(e,t,n,r,a,s)=>{let c=o.get(e),u=a===1?t:t-c.w;i.set(e,{id:e,x:u,y:n-c.h/2,w:c.w,h:c.h,depth:r,dir:a,parent:s}),p(e,l(e),a===1?u+c.w+cI:u-cI,n,r+1,a)},p=(e,t,n,r,i,a)=>{let o=r-(t.reduce((e,t)=>e+d(t),0)+lI*Math.max(0,t.length-1))/2;for(let r of t){let t=d(r);f(r,n,o+t/2,i,a,e),o+=t+lI}},m=o.get(r);i.set(r,{id:r,x:0,y:0,w:m.w,h:m.h,depth:0,dir:1,parent:``});let h=m.h/2,g=l(r);if(t===`right`)p(r,g,m.w+cI,h,1,1);else if(t===`left`)p(r,g,-56,h,1,-1);else{let e=Math.ceil(g.length/2);p(r,g.slice(0,e),m.w+cI,h,1,1),p(r,g.slice(e),-56,h,1,-1)}for(let e of i.values()){if(!e.parent)continue;let t=i.get(e.parent),n=e.dir===1?[t.x+t.w,t.y+t.h/2]:[t.x,t.y+t.h/2],r=e.dir===1?[e.x,e.y+e.h/2]:[e.x+e.w,e.y+e.h/2];a.push({from:n,to:r,child:e.id})}let _=1/0,v=1/0,y=-1/0,b=-1/0;for(let e of i.values())_=Math.min(_,e.x),v=Math.min(v,e.y),y=Math.max(y,e.x+e.w),b=Math.max(b,e.y+e.h);return{root:r,boxes:i,edges:a,bounds:{x:_,y:v,w:y-_,h:b-v}}}function pI(e,t,n,r){let i=e.boxes.get(n);if(!i)return null;if(r===`ArrowUp`||r===`ArrowDown`){let a=i.parent?dI(t,i.parent).filter(t=>e.boxes.get(t)?.dir===i.dir):[];return a[a.indexOf(n)+(r===`ArrowUp`?-1:1)]??null}let a=r===`ArrowRight`?1:-1;return i.parent?a===i.dir?dI(t,n)[0]??null:i.parent:dI(t,n).find(t=>e.boxes.get(t)?.dir===a)??null}function mI(e,t){let n=(e[0]+t[0])/2;return`M${e[0]} ${e[1]} C${n} ${e[1]} ${n} ${t[1]} ${t[0]} ${t[1]}`}function hI(e,t,n,r=e=>e){return e*r(.5-t*(.5-n))}function gI(e){return[-e[0],-e[1]]}function _I(e,t){return[e[0]+t[0],e[1]+t[1]]}function vI(e,t){return[e[0]-t[0],e[1]-t[1]]}function yI(e,t){return[e[0]*t,e[1]*t]}function bI(e,t){return[e[0]/t,e[1]/t]}function xI(e){return[e[1],-e[0]]}function SI(e,t){return e[0]*t[0]+e[1]*t[1]}function CI(e,t){return e[0]===t[0]&&e[1]===t[1]}function wI(e){return Math.hypot(e[0],e[1])}function TI(e){return e[0]*e[0]+e[1]*e[1]}function EI(e,t){return TI(vI(e,t))}function DI(e){return bI(e,wI(e))}function OI(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function kI(e,t,n){let r=Math.sin(n),i=Math.cos(n),a=e[0]-t[0],o=e[1]-t[1],s=a*i-o*r,c=a*r+o*i;return[s+t[0],c+t[1]]}function AI(e,t,n){return _I(e,yI(vI(t,e),n))}function jI(e,t,n){return _I(e,yI(t,n))}var{min:MI,PI:NI}=Math,PI=.275,FI=NI+1e-4;function II(e,t={}){let{size:n=16,smoothing:r=.5,thinning:i=.5,simulatePressure:a=!0,easing:o=e=>e,start:s={},end:c={},last:l=!1}=t,{cap:u=!0,easing:d=e=>e*(2-e)}=s,{cap:f=!0,easing:p=e=>--e*e*e+1}=c;if(e.length===0||n<=0)return[];let m=e[e.length-1].runningLength,h=s.taper===!1?0:s.taper===!0?Math.max(n,m):s.taper,g=c.taper===!1?0:c.taper===!0?Math.max(n,m):c.taper,_=(n*r)**2,v=[],y=[],b=e.slice(0,10).reduce((e,t)=>{let r=t.pressure;if(a){let i=MI(1,t.distance/n);r=MI(1,e+(MI(1,1-i)-e)*(i*PI))}return(e+r)/2},e[0].pressure),x=hI(n,i,e[e.length-1].pressure,o),S,C=e[0].vector,ee=e[0].point,te=ee,ne=ee,re=te,ie=!1;for(let t=0;t_)&&(v.push(ne),ee=ne),re=_I(s,ue),(t<=1||EI(te,re)>_)&&(y.push(re),te=re),b=r,C=c}let ae=e[0].point.slice(0,2),oe=e.length>1?e[e.length-1].point.slice(0,2):_I(e[0].point,[1,1]),se=[],ce=[];if(e.length===1){if(!(h||g)||l){let e=jI(ae,DI(xI(vI(ae,oe))),-(S||x)),t=[];for(let n=1/13,r=n;r<=1;r+=n)t.push(kI(e,ae,FI*2*r));return t}}else{if(!(h||g&&e.length===1)){if(u)for(let e=1/13,t=e;t<=1;t+=e){let e=kI(y[0],ae,FI*t);se.push(e)}else{let e=vI(v[0],y[0]),t=yI(e,.5),n=yI(e,.51);se.push(vI(ae,t),vI(ae,n),_I(ae,n),_I(ae,t))}}let t=xI(gI(e[e.length-1].vector));if(g||h&&e.length===1)ce.push(oe);else if(f){let e=jI(oe,t,x);for(let t=1/29,n=t;n<1;n+=t)ce.push(kI(e,oe,FI*3*n))}else ce.push(_I(oe,yI(t,x)),_I(oe,yI(t,x*.99)),vI(oe,yI(t,x*.99)),vI(oe,yI(t,x)))}return v.concat(ce,y.reverse(),se)}function LI(e,t={}){let{streamline:n=.5,size:r=16,last:i=!1}=t;if(e.length===0)return[];let a=.15+(1-n)*.85,o=Array.isArray(e[0])?e:e.map(({x:e,y:t,pressure:n=.5})=>[e,t,n]);if(o.length===2){let e=o[1];o=o.slice(0,-1);for(let t=1;t<5;t++)o.push(AI(o[0],e,t/4))}o.length===1&&(o=[...o,[..._I(o[0],[1,1]),...o[0].slice(2)]]);let s=[{point:[o[0][0],o[0][1]],pressure:o[0][2]>=0?o[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],c=!1,l=0,u=s[0],d=o.length-1;for(let e=1;e=0?o[e][2]:.5,vector:DI(vI(u.point,t)),distance:n,runningLength:l},s.push(u)}return s[0].vector=s[1]?.vector||[0,0],s}function RI(e,t={}){return II(LI(e,t),t)}function zI(e,t,n){if(e&&e.length){let[r,i]=t,a=Math.PI/180*n,o=Math.cos(a),s=Math.sin(a);for(let t of e){let[e,n]=t;t[0]=(e-r)*o-(n-i)*s+r,t[1]=(e-r)*s+(n-i)*o+i}}}function BI(e,t){return e[0]===t[0]&&e[1]===t[1]}function VI(e,t,n,r=1){let i=n,a=Math.max(t,.1),o=e[0]&&e[0][0]&&typeof e[0][0]==`number`?[e]:e,s=[0,0];if(i)for(let e of o)zI(e,s,i);let c=function(e,t,n){let r=[];for(let t of e){let e=[...t];BI(e[0],e[e.length-1])||e.push([e[0][0],e[0][1]]),e.length>2&&r.push(e)}let i=[];t=Math.max(t,.1);let a=[];for(let e of r)for(let t=0;te.ymint.ymin?1:e.xt.x?1:e.ymax===t.ymax?0:(e.ymax-t.ymax)/Math.abs(e.ymax-t.ymax))),!a.length)return i;let o=[],s=a[0].ymin,c=0;for(;o.length||a.length;){if(a.length){let e=-1;for(let t=0;ts);t++)e=t;a.splice(0,e+1).forEach((e=>{o.push({s,edge:e})}))}if(o=o.filter((e=>!(e.edge.ymax<=s))),o.sort(((e,t)=>e.edge.x===t.edge.x?0:(e.edge.x-t.edge.x)/Math.abs(e.edge.x-t.edge.x))),(n!==1||c%t==0)&&o.length>1)for(let e=0;e=o.length)break;let n=o[e].edge,r=o[t].edge;i.push([[Math.round(n.x),s],[Math.round(r.x),s]])}s+=n,o.forEach((e=>{e.edge.x=e.edge.x+n*e.edge.islope})),c++}return i}(o,a,r);if(i){for(let e of o)zI(e,s,-i);(function(e,t,n){let r=[];e.forEach((e=>r.push(...e))),zI(r,t,n)})(c,s,-i)}return c}function HI(e,t){let n=t.hachureAngle+90,r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=1;return t.roughness>=1&&(t.randomizer?.next()||Math.random())>.7&&(i=r),VI(e,r,n,i||1)}var UI=class{constructor(e){this.helper=e}fillPolygons(e,t){return this._fillPolygons(e,t)}_fillPolygons(e,t){let n=HI(e,t);return{type:`fillSketch`,ops:this.renderLines(n,t)}}renderLines(e,t){let n=[];for(let r of e)n.push(...this.helper.doubleLineOps(r[0][0],r[0][1],r[1][0],r[1][1],t));return n}};function WI(e){let t=e[0],n=e[1];return Math.sqrt((t[0]-n[0])**2+(t[1]-n[1])**2)}var GI=class extends UI{fillPolygons(e,t){let n=t.hachureGap;n<0&&(n=4*t.strokeWidth),n=Math.max(n,.1);let r=HI(e,Object.assign({},t,{hachureGap:n})),i=Math.PI/180*t.hachureAngle,a=[],o=.5*n*Math.cos(i),s=.5*n*Math.sin(i);for(let[e,t]of r)WI([e,t])&&a.push([[e[0]-o,e[1]+s],[...t]],[[e[0]+o,e[1]-s],[...t]]);return{type:`fillSketch`,ops:this.renderLines(a,t)}}},KI=class extends UI{fillPolygons(e,t){let n=this._fillPolygons(e,t),r=Object.assign({},t,{hachureAngle:t.hachureAngle+90}),i=this._fillPolygons(e,r);return n.ops=n.ops.concat(i.ops),n}},qI=class{constructor(e){this.helper=e}fillPolygons(e,t){let n=HI(e,t=Object.assign({},t,{hachureAngle:0}));return this.dotsOnLines(n,t)}dotsOnLines(e,t){let n=[],r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);let i=t.fillWeight;i<0&&(i=t.strokeWidth/2);let a=r/4;for(let o of e){let e=WI(o),s=e/r,c=Math.ceil(s)-1,l=e-c*r,u=(o[0][0]+o[1][0])/2-r/4,d=Math.min(o[0][1],o[1][1]);for(let e=0;e{let a=WI(e),o=Math.floor(a/(n+r)),s=(a+r-o*(n+r))/2,c=e[0],l=e[1];c[0]>l[0]&&(c=e[1],l=e[0]);let u=Math.atan((l[1]-c[1])/(l[0]-c[0]));for(let e=0;e{let i=WI(e),a=Math.round(i/(2*t)),o=e[0],s=e[1];o[0]>s[0]&&(o=e[1],s=e[0]);let c=Math.atan((s[1]-o[1])/(s[0]-o[0]));for(let e=0;er%2?e+n:e+t));a.push({key:`C`,data:e}),t=e[4],n=e[5];break}case`Q`:a.push({key:`Q`,data:[...s]}),t=s[2],n=s[3];break;case`q`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`Q`,data:e}),t=e[2],n=e[3];break}case`A`:a.push({key:`A`,data:[...s]}),t=s[5],n=s[6];break;case`a`:t+=s[5],n+=s[6],a.push({key:`A`,data:[s[0],s[1],s[2],s[3],s[4],t,n]});break;case`H`:a.push({key:`H`,data:[...s]}),t=s[0];break;case`h`:t+=s[0],a.push({key:`H`,data:[t]});break;case`V`:a.push({key:`V`,data:[...s]}),n=s[0];break;case`v`:n+=s[0],a.push({key:`V`,data:[n]});break;case`S`:a.push({key:`S`,data:[...s]}),t=s[2],n=s[3];break;case`s`:{let e=s.map(((e,r)=>r%2?e+n:e+t));a.push({key:`S`,data:e}),t=e[2],n=e[3];break}case`T`:a.push({key:`T`,data:[...s]}),t=s[0],n=s[1];break;case`t`:t+=s[0],n+=s[1],a.push({key:`T`,data:[t,n]});break;case`Z`:case`z`:a.push({key:`Z`,data:[]}),t=r,n=i}return a}function aL(e){let t=[],n=``,r=0,i=0,a=0,o=0,s=0,c=0;for(let{key:l,data:u}of e){switch(l){case`M`:t.push({key:`M`,data:[...u]}),[r,i]=u,[a,o]=u;break;case`C`:t.push({key:`C`,data:[...u]}),r=u[4],i=u[5],s=u[2],c=u[3];break;case`L`:t.push({key:`L`,data:[...u]}),[r,i]=u;break;case`H`:r=u[0],t.push({key:`L`,data:[r,i]});break;case`V`:i=u[0],t.push({key:`L`,data:[r,i]});break;case`S`:{let e=0,a=0;n===`C`||n===`S`?(e=r+(r-s),a=i+(i-c)):(e=r,a=i),t.push({key:`C`,data:[e,a,...u]}),s=u[0],c=u[1],r=u[2],i=u[3];break}case`T`:{let[e,a]=u,o=0,l=0;n===`Q`||n===`T`?(o=r+(r-s),l=i+(i-c)):(o=r,l=i);let d=r+2*(o-r)/3,f=i+2*(l-i)/3,p=e+2*(o-e)/3,m=a+2*(l-a)/3;t.push({key:`C`,data:[d,f,p,m,e,a]}),s=o,c=l,r=e,i=a;break}case`Q`:{let[e,n,a,o]=u,l=r+2*(e-r)/3,d=i+2*(n-i)/3,f=a+2*(e-a)/3,p=o+2*(n-o)/3;t.push({key:`C`,data:[l,d,f,p,a,o]}),s=e,c=n,r=a,i=o;break}case`A`:{let e=Math.abs(u[0]),n=Math.abs(u[1]),a=u[2],o=u[3],s=u[4],c=u[5],l=u[6];e===0||n===0?(t.push({key:`C`,data:[r,i,c,l,c,l]}),r=c,i=l):(r!==c||i!==l)&&(sL(r,i,c,l,e,n,a,o,s).forEach((function(e){t.push({key:`C`,data:e})})),r=c,i=l);break}case`Z`:t.push({key:`Z`,data:[]}),r=a,i=o}n=l}return t}function oL(e,t,n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function sL(e,t,n,r,i,a,o,s,c,l){let u=(d=o,Math.PI*d/180);var d;let f=[],p=0,m=0,h=0,g=0;if(l)[p,m,h,g]=l;else{[e,t]=oL(e,t,-u),[n,r]=oL(n,r,-u);let o=(e-n)/2,l=(t-r)/2,d=o*o/(i*i)+l*l/(a*a);d>1&&(d=Math.sqrt(d),i*=d,a*=d);let f=i*i,_=a*a,v=f*_-f*l*l-_*o*o,y=f*l*l+_*o*o,b=(s===c?-1:1)*Math.sqrt(Math.abs(v/y));h=b*i*l/a+(e+n)/2,g=b*-a*o/i+(t+r)/2,p=Math.asin(parseFloat(((t-g)/a).toFixed(9))),m=Math.asin(parseFloat(((r-g)/a).toFixed(9))),em&&(p-=2*Math.PI),!c&&m>p&&(m-=2*Math.PI)}let _=m-p;if(Math.abs(_)>120*Math.PI/180){let e=m,t=n,s=r;m=c&&m>p?p+120*Math.PI/180*1:p+120*Math.PI/180*-1,f=sL(n=h+i*Math.cos(m),r=g+a*Math.sin(m),t,s,i,a,o,0,c,[m,e,h,g])}_=m-p;let v=Math.cos(p),y=Math.sin(p),b=Math.cos(m),x=Math.sin(m),S=Math.tan(_/4),C=4/3*i*S,ee=4/3*a*S,te=[e,t],ne=[e+C*y,t-ee*v],re=[n+C*x,r-ee*b],ie=[n,r];if(ne[0]=2*te[0]-ne[0],ne[1]=2*te[1]-ne[1],l)return[ne,re,ie].concat(f);{f=[ne,re,ie].concat(f);let e=[];for(let t=0;t2){let i=[];for(let t=0;t2*Math.PI&&(p=0,m=2*Math.PI);let h=2*Math.PI/c.curveStepCount,g=Math.min(h/2,(m-p)/2),_=EL(g,l,u,d,f,p,m,1,c);if(!c.disableMultiStroke){let e=EL(g,l,u,d,f,p,m,1.5,c);_.push(...e)}return o&&(s?_.push(...xL(l,u,l+d*Math.cos(p),u+f*Math.sin(p),c),...xL(l,u,l+d*Math.cos(m),u+f*Math.sin(m),c)):_.push({op:`lineTo`,data:[l,u]},{op:`lineTo`,data:[l+d*Math.cos(p),u+f*Math.sin(p)]})),{type:`path`,ops:_}}function gL(e,t){let n=aL(iL(rL(e))),r=[],i=[0,0],a=[0,0];for(let{key:e,data:o}of n)switch(e){case`M`:a=[o[0],o[1]],i=[o[0],o[1]];break;case`L`:r.push(...xL(a[0],a[1],o[0],o[1],t)),a=[o[0],o[1]];break;case`C`:{let[e,n,i,s,c,l]=o;r.push(...DL(e,n,i,s,c,l,a,t)),a=[c,l];break}case`Z`:r.push(...xL(a[0],a[1],i[0],i[1],t)),a=[i[0],i[1]]}return{type:`path`,ops:r}}function _L(e,t){let n=[];for(let r of e)if(r.length){let e=t.maxRandomnessOffset||0,i=r.length;if(i>2){n.push({op:`move`,data:[r[0][0]+I(e,t),r[0][1]+I(e,t)]});for(let a=1;a500?.4:-.0016668*c+1.233334;let u=i.maxRandomnessOffset||0;u*u*100>s&&(u=c/10);let d=u/2,f=.2+.2*yL(i),p=i.bowing*i.maxRandomnessOffset*(r-t)/200,m=i.bowing*i.maxRandomnessOffset*(e-n)/200;p=I(p,i,l),m=I(m,i,l);let h=[],g=()=>I(d,i,l),_=()=>I(u,i,l),v=i.preserveVertices;return a&&(o?h.push({op:`move`,data:[e+(v?0:g()),t+(v?0:g())]}):h.push({op:`move`,data:[e+(v?0:I(u,i,l)),t+(v?0:I(u,i,l))]})),o?h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+g(),m+t+(r-t)*f+g(),p+e+2*(n-e)*f+g(),m+t+2*(r-t)*f+g(),n+(v?0:g()),r+(v?0:g())]}):h.push({op:`bcurveTo`,data:[p+e+(n-e)*f+_(),m+t+(r-t)*f+_(),p+e+2*(n-e)*f+_(),m+t+2*(r-t)*f+_(),n+(v?0:_()),r+(v?0:_())]}),h}function CL(e,t,n){let r=[];r.push([e[0][0]+I(t,n),e[0][1]+I(t,n)]),r.push([e[0][0]+I(t,n),e[0][1]+I(t,n)]);for(let i=1;i3){let a=[],o=1-n.curveTightness;i.push({op:`move`,data:[e[1][0],e[1][1]]});for(let t=1;t+21&&i.push(n)):i.push(n),i.push(e[t+3])}else{let r=.5,a=e[t+0],o=e[t+1],s=e[t+2],c=e[t+3],l=jL(a,o,r),u=jL(o,s,r),d=jL(s,c,r),f=jL(l,u,r),p=jL(u,d,r),m=jL(f,p,r);ML([a,l,f,m],0,n,i),ML([m,p,d,c],0,n,i)}var a,o;return i}function NL(e,t){return PL(e,0,e.length,t)}function PL(e,t,n,r,i){let a=i||[],o=e[t],s=e[n-1],c=0,l=1;for(let r=t+1;rc&&(c=t,l=r)}return Math.sqrt(c)>r?(PL(e,t,l+1,r,a),PL(e,l,n,r,a)):(a.length||a.push(o),a.push(s)),a}function FL(e,t=.15,n){let r=[],i=(e.length-1)/3;for(let n=0;n0?PL(r,0,r.length,n):r}var IL=`none`,LL=class{constructor(e){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:`#000`,strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:`hachure`,fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=e||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Math.floor(Math.random()*2**31)}_o(e){return e?Object.assign({},this.defaultOptions,e):this.defaultOptions}_d(e,t,n){return{shape:e,sets:t||[],options:n||this.defaultOptions}}line(e,t,n,r,i){let a=this._o(i);return this._d(`line`,[lL(e,t,n,r,a)],a)}rectangle(e,t,n,r,i){let a=this._o(i),o=[],s=dL(e,t,n,r,a);if(a.fill){let i=[[e,t],[e+n,t],[e+n,t+r],[e,t+r]];a.fillStyle===`solid`?o.push(_L([i],a)):o.push(vL([i],a))}return a.stroke!==IL&&o.push(s),this._d(`rectangle`,o,a)}ellipse(e,t,n,r,i){let a=this._o(i),o=[],s=pL(n,r,a),c=mL(e,t,a,s);if(a.fill){if(a.fillStyle===`solid`){let n=mL(e,t,a,s).opset;n.type=`fillPath`,o.push(n)}else o.push(vL([c.estimatedPoints],a))}return a.stroke!==IL&&o.push(c.opset),this._d(`ellipse`,o,a)}circle(e,t,n,r){let i=this.ellipse(e,t,n,n,r);return i.shape=`circle`,i}linearPath(e,t){let n=this._o(t);return this._d(`linearPath`,[uL(e,!1,n)],n)}arc(e,t,n,r,i,a,o=!1,s){let c=this._o(s),l=[],u=hL(e,t,n,r,i,a,o,!0,c);if(o&&c.fill){if(c.fillStyle===`solid`){let o=Object.assign({},c);o.disableMultiStroke=!0;let s=hL(e,t,n,r,i,a,!0,!1,o);s.type=`fillPath`,l.push(s)}else l.push(function(e,t,n,r,i,a,o){let s=e,c=t,l=Math.abs(n/2),u=Math.abs(r/2);l+=I(.01*l,o),u+=I(.01*u,o);let d=i,f=a;for(;d<0;)d+=2*Math.PI,f+=2*Math.PI;f-d>2*Math.PI&&(d=0,f=2*Math.PI);let p=(f-d)/o.curveStepCount,m=[];for(let e=d;e<=f;e+=p)m.push([s+l*Math.cos(e),c+u*Math.sin(e)]);return m.push([s+l*Math.cos(f),c+u*Math.sin(f)]),m.push([s,c]),vL([m],o)}(e,t,n,r,i,a,c))}return c.stroke!==IL&&l.push(u),this._d(`arc`,l,c)}curve(e,t){let n=this._o(t),r=[],i=fL(e,n);if(n.fill&&n.fill!==IL&&e.length>=3){if(n.fillStyle===`solid`){let t=fL(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else{let t=FL(function(e,t=0){let n=e.length;if(n<3)throw Error(`A curve must have at least three points.`);let r=[];if(n===3)r.push(OL(e[0]),OL(e[1]),OL(e[2]),OL(e[2]));else{let n=[];n.push(e[0],e[0]);for(let t=1;t{s.length>=4&&a.push(...FL(s,t)),s=[]},l=()=>{c(),a.length&&(i.push(a),a=[])};for(let{key:e,data:t}of r)switch(e){case`M`:l(),o=[t[0],t[1]],a.push(o);break;case`L`:c(),a.push([t[0],t[1]]);break;case`C`:if(!s.length){let e=a.length?a[a.length-1]:o;s.push([e[0],e[1]])}s.push([t[0],t[1]]),s.push([t[2],t[3]]),s.push([t[4],t[5]]);break;case`Z`:c(),a.push([o[0],o[1]])}if(l(),!n)return i;let u=[];for(let e of i){let t=NL(e,n);t.length&&u.push(t)}return u}(e,1,o?4-4*(n.simplification||1):(1+n.roughness)/2),c=gL(e,n);if(i){if(n.fillStyle===`solid`){if(s.length===1){let t=gL(e,Object.assign(Object.assign({},n),{disableMultiStroke:!0,roughness:n.roughness?n.roughness+n.fillShapeRoughnessGain:0}));r.push({type:`fillPath`,ops:this._mergedShape(t.ops)})}else r.push(_L(s,n))}else r.push(vL(s,n))}return a&&(o?s.forEach((e=>{r.push(uL(e,!1,n))})):r.push(c)),this._d(`path`,r,n)}opsToPath(e,t){let n=``;for(let r of e.ops){let e=typeof t==`number`&&t>=0?r.data.map((e=>+e.toFixed(t))):r.data;switch(r.op){case`move`:n+=`M${e[0]} ${e[1]} `;break;case`bcurveTo`:n+=`C${e[0]} ${e[1]}, ${e[2]} ${e[3]}, ${e[4]} ${e[5]} `;break;case`lineTo`:n+=`L${e[0]} ${e[1]} `}}return n.trim()}toPaths(e){let t=e.sets||[],n=e.options||this.defaultOptions,r=[];for(let e of t){let t=null;switch(e.type){case`path`:t={d:this.opsToPath(e),stroke:n.stroke,strokeWidth:n.strokeWidth,fill:IL};break;case`fillPath`:t={d:this.opsToPath(e),stroke:IL,strokeWidth:0,fill:n.fill||IL};break;case`fillSketch`:t=this.fillSketch(e,n)}t&&r.push(t)}return r}fillSketch(e,t){let n=t.fillWeight;return n<0&&(n=t.strokeWidth/2),{d:this.opsToPath(e),stroke:t.fill||IL,strokeWidth:n,fill:IL}}_mergedShape(e){return e.filter(((e,t)=>t===0||e.op!==`move`))}},RL=class{constructor(e,t){this.canvas=e,this.ctx=this.canvas.getContext(`2d`),this.gen=new LL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.ctx,i=e.options.fixedDecimalPlaceDigits;for(let a of t)switch(a.type){case`path`:r.save(),r.strokeStyle=n.stroke===`none`?`transparent`:n.stroke,r.lineWidth=n.strokeWidth,n.strokeLineDash&&r.setLineDash(n.strokeLineDash),n.strokeLineDashOffset&&(r.lineDashOffset=n.strokeLineDashOffset),this._drawToContext(r,a,i),r.restore();break;case`fillPath`:{r.save(),r.fillStyle=n.fill||``;let t=e.shape===`curve`||e.shape===`polygon`||e.shape===`path`?`evenodd`:`nonzero`;this._drawToContext(r,a,i,t),r.restore();break}case`fillSketch`:this.fillSketch(r,a,n)}}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2),e.save(),n.fillLineDash&&e.setLineDash(n.fillLineDash),n.fillLineDashOffset&&(e.lineDashOffset=n.fillLineDashOffset),e.strokeStyle=n.fill||``,e.lineWidth=r,this._drawToContext(e,t,n.fixedDecimalPlaceDigits),e.restore()}_drawToContext(e,t,n,r=`nonzero`){e.beginPath();for(let r of t.ops){let t=typeof n==`number`&&n>=0?r.data.map((e=>+e.toFixed(n))):r.data;switch(r.op){case`move`:e.moveTo(t[0],t[1]);break;case`bcurveTo`:e.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5]);break;case`lineTo`:e.lineTo(t[0],t[1])}}t.type===`fillPath`?e.fill(r):e.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a),a}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a),a}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a),a}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i),i}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n),n}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n),n}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c),c}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n),n}path(e,t){let n=this.gen.path(e,t);return this.draw(n),n}},zL=`http://www.w3.org/2000/svg`,BL=class{constructor(e,t){this.svg=e,this.gen=new LL(t)}draw(e){let t=e.sets||[],n=e.options||this.getDefaultOptions(),r=this.svg.ownerDocument||window.document,i=r.createElementNS(zL,`g`),a=e.options.fixedDecimalPlaceDigits;for(let o of t){let t=null;switch(o.type){case`path`:t=r.createElementNS(zL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,n.stroke),t.setAttribute(`stroke-width`,n.strokeWidth+``),t.setAttribute(`fill`,`none`),n.strokeLineDash&&t.setAttribute(`stroke-dasharray`,n.strokeLineDash.join(` `).trim()),n.strokeLineDashOffset&&t.setAttribute(`stroke-dashoffset`,`${n.strokeLineDashOffset}`);break;case`fillPath`:t=r.createElementNS(zL,`path`),t.setAttribute(`d`,this.opsToPath(o,a)),t.setAttribute(`stroke`,`none`),t.setAttribute(`stroke-width`,`0`),t.setAttribute(`fill`,n.fill||``),e.shape!==`curve`&&e.shape!==`polygon`||t.setAttribute(`fill-rule`,`evenodd`);break;case`fillSketch`:t=this.fillSketch(r,o,n)}t&&i.appendChild(t)}return i}fillSketch(e,t,n){let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let i=e.createElementNS(zL,`path`);return i.setAttribute(`d`,this.opsToPath(t,n.fixedDecimalPlaceDigits)),i.setAttribute(`stroke`,n.fill||``),i.setAttribute(`stroke-width`,r+``),i.setAttribute(`fill`,`none`),n.fillLineDash&&i.setAttribute(`stroke-dasharray`,n.fillLineDash.join(` `).trim()),n.fillLineDashOffset&&i.setAttribute(`stroke-dashoffset`,`${n.fillLineDashOffset}`),i}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(e,t){return this.gen.opsToPath(e,t)}line(e,t,n,r,i){let a=this.gen.line(e,t,n,r,i);return this.draw(a)}rectangle(e,t,n,r,i){let a=this.gen.rectangle(e,t,n,r,i);return this.draw(a)}ellipse(e,t,n,r,i){let a=this.gen.ellipse(e,t,n,r,i);return this.draw(a)}circle(e,t,n,r){let i=this.gen.circle(e,t,n,r);return this.draw(i)}linearPath(e,t){let n=this.gen.linearPath(e,t);return this.draw(n)}polygon(e,t){let n=this.gen.polygon(e,t);return this.draw(n)}arc(e,t,n,r,i,a,o=!1,s){let c=this.gen.arc(e,t,n,r,i,a,o,s);return this.draw(c)}curve(e,t){let n=this.gen.curve(e,t);return this.draw(n)}path(e,t){let n=this.gen.path(e,t);return this.draw(n)}},VL={canvas:(e,t)=>new RL(e,t),svg:(e,t)=>new BL(e,t),generator:e=>new LL(e),newSeed:()=>LL.newSeed()},HL=(e,t)=>e===`none`?`none`:e===`ink`?t===`fill`?`var(--dw-surface-sunken)`:`var(--dw-ink)`:e===`paper`?t===`fill`?`var(--dw-surface-raised)`:`var(--dw-surface)`:t===`fill`?`color-mix(in srgb, var(--dw-c-${e}) 22%, var(--dw-surface))`:`var(--dw-c-${e})`,UL=e=>e.replace(/&/g,`&`).replace(//g,`>`).replace(/"/g,`"`),WL=e=>Math.round(e*100)/100,GL=`#000001`,KL=`#000002`;function qL(e,t){return e===`dash`?`stroke-dasharray:${WL(t*4)} ${WL(t*3)};`:``}function JL(e){let t=2166136261;for(let n of e)t=Math.imul(t^n.charCodeAt(0),16777619);return(t>>>0)%2**31||1}function YL(e,t,n){switch(e){case`diamond`:return[[t/2,0],[t,n/2],[t/2,n],[0,n/2]];case`triangle`:return[[t/2,0],[t,n],[0,n]];case`rect`:return[[0,0],[t,0],[t,n],[0,n]];default:return null}}function XL(e,t){let n=Math.min(16,e*.15,t*.15);return`M${WL(n)} 0 H${WL(e-n)} Q${WL(e)} 0 ${WL(e)} ${WL(n)} V${WL(t-n)} Q${WL(e)} ${WL(t)} ${WL(e-n)} ${WL(t)} H${WL(n)} Q0 ${WL(t)} 0 ${WL(t-n)} V${WL(n)} Q0 0 ${WL(n)} 0 Z`}function ZL(e,t){let{w:n,h:r}=e,i=e.strokeStyle===`none`?`none`:t(e.stroke,`line`),a=t(e.fill,`fill`),o=e.strokeStyle===`none`?0:e.strokeWidth;if(e.rough){let t=VL.generator(),s={seed:JL(e.id),roughness:1.2,bowing:1,strokeWidth:Math.max(o,1),stroke:i===`none`?`none`:GL,fill:a===`none`?void 0:KL,fillStyle:`hachure`,hachureGap:8,fillWeight:1.4,disableMultiStroke:o===0},c=YL(e.shape,n,r),l=e.shape===`ellipse`?t.ellipse(n/2,r/2,n,r,s):e.shape===`roundrect`?t.path(XL(n,r),s):t.polygon(c,s);return t.toPaths(l).map(t=>{if(t.fill===KL)return``;let n=t.stroke===KL,r=n?a.replace(`22%`,`60%`):i;return r===`none`||t.stroke===`none`?``:``}).join(``)}let s=`fill:${a};stroke:${i};stroke-width:${WL(o)};stroke-linejoin:round;${qL(e.strokeStyle,o)}`;return e.shape===`ellipse`?``:e.shape===`roundrect`?``:``}function QL(e,t,n,r,i){if(e===`none`)return``;let a=6+r*2.5,o=(e,r)=>{let i=Math.cos(n),a=Math.sin(n);return`${WL(t[0]+e*i-r*a)},${WL(t[1]+e*a+r*i)}`};switch(e){case`arrow`:return``;case`triangle`:return``;case`circle`:{let[e,t]=o(-a*.45,0).split(`,`).map(Number);return``}case`diamond`:return``}}function $L(e,t,n){let r=e.strokeStyle===`none`?n(`gray`,`line`):n(e.stroke,`line`),i=e.strokeWidth,a;if(e.rough){let n=VL.generator();a=n.toPaths(n.path(t.d,{seed:JL(e.id),roughness:1,strokeWidth:i,stroke:`#000`})).map(e=>``).join(``)}else a=``;let o=t.points[t.points.length-1];return a+QL(e.startArrow,t.points[0],t.startAngle,i,r)+QL(e.endArrow,o,t.endAngle,i,r)}function eR(e,t){let n=RI(e,{size:t,thinning:.55,smoothing:.5,streamline:.4,simulatePressure:e.every(e=>e[2]===.5),last:!0});if(!n.length)return``;let r=(e,t)=>(e+t)/2,i=`M${WL(n[0][0])} ${WL(n[0][1])} Q`;for(let e=0;e`}function nR(e){let t=[];for(let n of e.toArray())if(n instanceof px)for(let e of n.toDelta()){if(typeof e.insert!=`string`)continue;let n={type:`text`,text:e.insert};e.attributes&&(n.marks=Object.entries(e.attributes).map(([e,t])=>({type:e,attrs:t&&typeof t==`object`?t:{}}))),t.push(n)}else if(n instanceof cx){let e={type:n.nodeName},r=n.getAttributes();Object.keys(r).length&&(e.attrs=r),n.length&&(e.content=nR(n)),t.push(e)}return t}function rR(e,t,n=0){if(n>100)return;let r=0;for(;r{let r=``,i=!1;for(let a of e)a.type===`text`?(r+=a.text??``,i=!0):a.type===`hardBreak`?(t.push(r),r=``):a.content?.length&&a.content.some(e=>e.type!==`text`&&e.type!==`hardBreak`)?(i&&t.push(r),r=``,i=!1,n(a.content)):(i&&t.push(r),t.push((a.content??[]).map(e=>e.text??``).join(``)),r=``,i=!1);i&&t.push(r)};return n(e),t}var aR=`docwell-canvas`,oR=e=>e.getMap(`surface`);function sR(e){let t={};for(let[n,r]of e.entries())r instanceof zb?t[n]=r.toJSON():r instanceof hb||(t[n]=r);return IF(t)}function cR(e,t){return(e.type===`frame`?0:1)-(t.type===`frame`?0:1)||e.index-t.index||(e.idt.id))}function lR(){return IF({id:OF,type:`note`,page:!0,background:`paper`,x:0,y:0,w:760,h:400,index:0})}var uR=class{doc;map;undo;cache=null;byId=new Map;listeners=new Set;observer=e=>{this.cache=null;let t=new Set;for(let n of e){if(n.target===this.map){t=null;break}let e=n.target;for(;e&&e.parent!==this.map;)e=e.parent;let r=e&&e._item?.parentSub;r&&t.add(r)}for(let e of this.listeners)e(t)};constructor(e,t={}){this.doc=e,this.map=oR(e),this.map.observeDeep(this.observer),this.undo=t.undo===!1?null:new Uy(this.map,{trackedOrigins:new Set([aR]),captureTimeout:400})}destroy(){this.map.unobserveDeep(this.observer),this.undo?.destroy(),this.listeners.clear()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}elements(){if(this.cache)return this.cache;let e=[];for(let[t,n]of this.map.entries()){let r=n instanceof zb?sR(n):null;r&&e.push({...r,id:t})}return e.some(e=>e.type===`note`&&e.page)||e.push(lR()),e.sort(cR),this.cache=e,this.byId=new Map(e.map(e=>[e.id,e])),e}get(e){return this.elements(),this.byId.get(e)}get isEmpty(){return this.map.size===0}body(e){let t=this.map.get(e);if(!(t instanceof zb))return null;let n=t.get(`body`);return n instanceof ox?n:null}nodes(e){let t=this.map.get(e)?.get(`nodes`);return t instanceof zb?t:null}transact(e){this.doc.transact(e,aR)}nextIndex(){let e=0;for(let t of this.elements())t.type!==`frame`&&(e=Math.max(e,t.index));return e+1}ensure(e){let t=this.map.get(e);if(t instanceof zb)return t;if(e!==`page`)return null;let n=this.get(e),r=new zb;this.map.set(e,r);for(let[e,t]of Object.entries(n))e!==`id`&&r.set(e,t);return r}add(e,t){let n=e.id||VF();return this.transact(()=>{let r=new zb;this.map.set(n,r);let{nodes:i,...a}=e;for(let[e,t]of Object.entries(a))e!==`id`&&t!==void 0&&r.set(e,t);if(`index`in a||r.set(`index`,e.type===`frame`?-this.nextIndex():this.nextIndex()),e.type===`note`&&!e.page){let e=new ox;r.set(`body`,e),rR(e,t?.length?t:[{type:`paragraph`}])}if(e.type===`mindmap`){let e=new zb;r.set(`nodes`,e);let t=i&&Object.keys(i).length?i:{[VF()]:{text:``,parent:``,pos:0}};for(let[n,r]of Object.entries(t))e.set(n,dR(r))}}),n}update(e,t){this.updateMany([[e,t]])}updateMany(e){e.length&&this.transact(()=>{for(let[t,n]of e){let e=this.ensure(t);if(e)for(let[t,r]of Object.entries(n))t!==`id`&&t!==`type`&&t!==`body`&&t!==`nodes`&&(r===void 0?e.delete(t):fR(e.get(t),r)||e.set(t,r))}})}remove(e){let t=this.elements(),n=new Set;for(let r of e){n.add(r);for(let e of t)e.group===r&&n.add(e.id)}n.delete(OF);for(let e of t)e.type===`note`&&e.page&&n.delete(e.id);n.size&&this.transact(()=>{for(let e of t)if(!(e.type!==`connector`||n.has(e.id)))for(let t of[`source`,`target`]){let r=e[t];if(r.id&&n.has(r.id)){let n=this.endPoint(r);this.map.get(e.id)?.set(t,{x:n[0],y:n[1]})}}for(let e of n)this.map.delete(e);let e=this.elements();for(let t of e.filter(e=>e.type===`group`)){let n=e.filter(e=>e.group===t.id);if(n.length<2){for(let e of n)this.map.get(e.id)?.delete(`group`);this.map.delete(t.id)}}})}endPoint(e){let t=e.id?this.get(e.id):void 0;if(!t)return[e.x??0,e.y??0];let[n,r]=e.pos??[.5,.5];return[t.x+t.w*n,t.y+t.h*r]}reorder(e,t){let n=this.elements().filter(e=>e.type!==`frame`),r=new Set(e),i=n.filter(e=>r.has(e.id));if(!i.length)return;let a=n.filter(e=>!r.has(e.id)),o;if(t===`front`)o=[...a,...i];else if(t===`back`)o=[...i,...a];else{o=[...n];let e=t===`forward`?1:-1,a=e=>o.indexOf(e),s=e===1?[...i].reverse():i;for(let t of s){let n=a(t),i=n+e;i<0||i>=o.length||r.has(o[i].id)||([o[n],o[i]]=[o[i],o[n]])}}this.updateMany(o.map((e,t)=>[e.id,{index:t+1}]).filter(([e,t])=>this.get(e)?.index!==t.index))}groupOf(e){let t=e.filter(e=>{let t=this.get(e);return t&&t.type!==`group`&&!(t.type===`note`&&t.page)});if(t.length<2)return null;let n=VF();return this.transact(()=>{let e=new zb;this.map.set(n,e),e.set(`type`,`group`),e.set(`index`,this.nextIndex());for(let e of t)this.ensure(e)?.set(`group`,n)}),n}ungroup(e){let t=this.elements().filter(t=>t.group===e).map(e=>e.id);return this.transact(()=>{for(let e of t)this.map.get(e)?.delete(`group`);this.map.delete(e)}),t}addNode(e,t,n,r=``){let i=VF();return this.transact(()=>this.nodes(e)?.set(i,dR({text:r,parent:t,pos:n}))),i}updateNode(e,t,n){this.transact(()=>{let r=this.nodes(e)?.get(t);if(r)for(let[e,t]of Object.entries(n))r.get(e)!==t&&r.set(e,t)})}removeNode(e,t){let n=this.get(e);if(n?.type!==`mindmap`)return;if(t===Object.entries(n.nodes).find(([,e])=>!e.parent)?.[0]){this.remove([e]);return}let r=new Set([t]),i=!0;for(;i;){i=!1;for(let[e,t]of Object.entries(n.nodes))!r.has(e)&&r.has(t.parent)&&(r.add(e),i=!0)}this.transact(()=>{let t=this.nodes(e);for(let e of r)t?.delete(e)})}toJSON(e){let t=this.elements(),n;if(e){n=new Set(e);for(let e of t)n.has(e.group)&&n.add(e.id)}else n=new Set(t.map(e=>e.id));return t.filter(e=>n.has(e.id)).map(e=>{let t={...e,id:e.id,type:e.type},n=e.type===`note`&&!e.page?this.body(e.id):null;return n&&(t.body=nR(n)),t})}insertJSON(e,t=0,n=0){let r=e.filter(e=>e&&typeof e==`object`&&!(e.type===`note`&&e.page)),i=new Map(r.map(e=>[String(e.id),VF()])),a=[],o=this.nextIndex();return this.transact(()=>{for(let e of r){let r=IF(e);if(!r)continue;let s=i.get(String(e.id)),c={...r};if(delete c.id,c.x=r.x+t,c.y=r.y+n,c.index=r.type===`frame`?-o++:o++,c.group=r.group&&i.has(r.group)?i.get(r.group):void 0,r.type===`connector`)for(let e of[`source`,`target`]){let a=r[e];if(a.id&&i.has(a.id))c[e]={id:i.get(a.id),...a.pos?{pos:a.pos}:{}};else if(a.id){let r=this.endPoint(a);c[e]={x:r[0]+t,y:r[1]+n}}else c[e]={x:(a.x??0)+t,y:(a.y??0)+n}}for(let e of Object.keys(c))(c[e]===void 0||c[e]===``)&&delete c[e];this.add({...c,id:s,type:r.type},Array.isArray(e.body)?e.body:void 0),a.push(s)}}),a}load(e){this.transact(()=>{for(let e of[...this.map.keys()])this.map.delete(e);for(let t of e){let e=IF(t);if(!e||!t.id)continue;let n={...e},r=String(t.id);delete n.id;for(let e of Object.keys(n))n[e]===``&&delete n[e];this.add({...n,id:r,type:e.type},Array.isArray(t.body)?t.body:void 0)}})}};function dR(e){let t=new zb;return t.set(`text`,e.text),t.set(`parent`,e.parent),t.set(`pos`,e.pos),t}function fR(e,t){return e===t?!0:typeof e!=`object`||typeof t!=`object`||!e||!t?!1:JSON.stringify(e)===JSON.stringify(t)}var pR=(e,t=18)=>``,mR={rect:``,roundrect:``,ellipse:``,diamond:``,triangle:``,straight:``,curve:``,elbow:``,none:``,arrow:``,triangleEnd:``,circle:``,diamondEnd:``,solid:``,dash:``,noLine:``,right:``,left:``,radial:``},hR=e=>``;function gR(e){return e===`none`?`background:transparent`:e===`ink`?`background:var(--dw-ink)`:e===`paper`?`background:var(--dw-surface)`:`background:var(--dw-c-${e})`}var _R=class{v;bar;zoomBox;props;zoomLabel;pop=null;popFor=``;fileInput;lastProps=``;closePop=e=>{this.pop&&!this.pop.contains(e.target)&&!e.target.closest?.(`[data-pop]`)&&this.hidePop()};constructor(e){this.v=e;let t=e.root;this.bar=this.div(`dw-cv-ui dw-cv-toolbar`),this.bar.setAttribute(`role`,`toolbar`),this.bar.setAttribute(`aria-label`,e.labels.toolbar),this.zoomBox=this.div(`dw-cv-ui dw-cv-zoom`),this.props=this.div(`dw-cv-ui dw-cv-props`),this.props.setAttribute(`role`,`toolbar`),this.zoomLabel=document.createElement(`button`),this.fileInput=document.createElement(`input`),this.fileInput.type=`file`,this.fileInput.accept=`image/*`,this.fileInput.multiple=!0,this.fileInput.hidden=!0,this.fileInput.addEventListener(`change`,()=>{let t=[...this.fileInput.files??[]];this.fileInput.value=``,t.length&&e.addImages(t)}),t.append(this.bar,this.zoomBox,this.props,this.fileInput),document.addEventListener(`pointerdown`,this.closePop,!0),this.buildZoom(),this.refresh()}destroy(){document.removeEventListener(`pointerdown`,this.closePop,!0)}div(e){let t=document.createElement(`div`);return t.className=e,t}button(e,t,n,r={}){let i=document.createElement(`button`);return i.type=`button`,i.className=`dw-cv-btn${r.cls?` ${r.cls}`:``}`,i.innerHTML=e,i.title=t,i.setAttribute(`aria-label`,t),r.active!==void 0&&i.setAttribute(`aria-pressed`,String(r.active)),r.pop&&(i.dataset.pop=r.pop),i.addEventListener(`pointerdown`,e=>e.stopPropagation()),i.addEventListener(`click`,e=>{e.stopPropagation(),n()}),i}buildBar(){let e=this.v,t=e.labels;if(this.bar.replaceChildren(),this.bar.hidden=e.isPresenting,!e.editable){this.bar.append(this.button(pR(`cursor`),t.select,()=>e.setTool(`select`),{active:e.tool===`select`}),this.button(pR(`hand`),t.hand,()=>e.setTool(`hand`),{active:e.tool===`hand`}),this.sep(),this.button(pR(`present`),t.present,()=>e.present()));return}let n=(t,n,r)=>this.button(pR(n),r,()=>e.setTool(t),{active:e.tool===t}),r=this.button(hR(e.shapeKind),t.shape,()=>{e.setTool(`shape`),this.togglePop(`shape`,r,()=>this.shapePop())},{active:e.tool===`shape`,pop:`shape`}),i=this.button(pR(`pen`),t.pen,()=>{e.setTool(`pen`),this.togglePop(`pen`,i,()=>this.penPop())},{active:e.tool===`pen`,pop:`pen`}),a=this.button(pR(`connector`),t.connector,()=>{e.setTool(`connector`),this.togglePop(`connector`,a,()=>this.connectorPop())},{active:e.tool===`connector`,pop:`connector`}),o=this.button(pR(`sticker`),t.library,()=>this.togglePop(`library`,o,()=>this.libraryPop()),{pop:`library`});this.bar.append(n(`select`,`cursor`,t.select),n(`hand`,`hand`,t.hand),this.sep(),n(`note`,`note`,t.note),n(`text`,`type`,t.text),r,a,i,n(`eraser`,`eraser`,t.eraser),n(`frame`,`frame`,t.frame),n(`mindmap`,`mindmap`,t.mindmap),this.button(pR(`image`),t.image,()=>this.pickImage()),this.button(pR(`link`),t.link,()=>void e.addLink()),o,this.sep(),this.button(pR(`present`),t.present,()=>e.present()))}sep(){return this.div(`dw-cv-sep`)}pickImage(){this.v.editable&&this.v.opts.files?.upload&&this.fileInput.click()}togglePop(e,t,n){if(this.pop&&this.popFor===e)return this.hidePop();this.hidePop();let r=n();r.classList.add(`dw-cv-ui`,`dw-cv-pop`),r.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.v.root.append(r),this.pop=r,this.popFor=e;let i=this.v.root.getBoundingClientRect(),a=t.getBoundingClientRect(),o=r.offsetWidth,s=r.offsetHeight,c=a.left-i.left+a.width/2-o/2;c=Math.max(8,Math.min(i.width-o-8,c));let l=a.top-i.top-s-8;l<8&&(l=a.bottom-i.top+8),r.style.left=`${c}px`,r.style.top=`${l}px`}hidePop(){this.pop?.remove(),this.pop=null,this.popFor=``}row(...e){let t=this.div(`dw-cv-row`);return t.append(...e),t}colorRow(e,t,n,r){let i=this.div(`dw-cv-row dw-cv-colors`);i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,r);let a=this.v.labels,o=[`ink`,...xF,...n?[`paper`,`none`]:[]];for(let n of o){let r=n===`ink`?a.colorInk:n===`paper`?a.colorPaper:n===`none`?a.colorNone:a.colors[n]??n,o=this.button(``,r,()=>{t(n),this.lastProps=``,this.refresh()},{active:n===e});i.append(o)}return i}shapePop(){let e=this.v,t=e.labels,n=this.div(``);return n.append(this.row(...wF.map(n=>this.button(hR(n),t[n],()=>{e.setShapeKind(n),this.hidePop()},{active:e.shapeKind===n}))),this.row(this.button(`${t.general}`,t.general,()=>{e.setStyle(`shape`,{rough:!1}),this.hidePop()},{active:!e.styles.shape.rough}),this.button(`${t.scribbled}`,t.scribbled,()=>{e.setStyle(`shape`,{rough:!0}),this.hidePop()},{active:e.styles.shape.rough}))),n}penPop(){let e=this.v,t=this.div(``);return t.append(this.colorRow(e.styles.brush.color,t=>e.setStyle(`brush`,{color:t}),!1,e.labels.stroke),this.row(...[2,4,8,14].map(t=>this.button(``,`${e.labels.thickness} ${t}`,()=>{e.setStyle(`brush`,{size:t}),this.hidePop()},{active:e.styles.brush.size===t})))),t}connectorPop(){let e=this.v,t=this.div(``);return t.append(this.row(...TF.map(t=>this.button(hR(t),e.labels[t],()=>{e.setStyle(`connector`,{mode:t}),this.hidePop()},{active:e.styles.connector.mode===t})))),t}libraryPop(){let e=this.v,t=e.labels,n=this.div(`dw-cv-library`),r=this.div(`dw-cv-poptitle`);r.textContent=t.stickers;let i=this.div(`dw-cv-stickers`);for(let t of WF)i.append(this.button(`${t}`,t,()=>{e.insertSticker(t),this.hidePop()}));let a=this.div(`dw-cv-poptitle`);a.textContent=t.templates;let o=this.div(`dw-cv-templates`),s={kanban:t.templateKanban,swot:t.templateSwot,flow:t.templateFlow,brainstorm:t.templateBrainstorm,retro:t.templateRetro};for(let t of KF){let n=this.button(`${s[t]}`,s[t],()=>{e.insertTemplate(t),this.hidePop()},{cls:`dw-cv-wide`});o.append(n)}return n.append(r,i,a,o),n}buildZoom(){let e=this.v,t=e.labels;this.zoomLabel.type=`button`,this.zoomLabel.className=`dw-cv-btn dw-cv-zoomlabel`,this.zoomLabel.title=t.zoomReset,this.zoomLabel.addEventListener(`pointerdown`,e=>e.stopPropagation()),this.zoomLabel.addEventListener(`click`,()=>e.zoomAt(1)),this.zoomBox.append(this.button(pR(`zoom-out`),t.zoomOut,()=>e.zoomBy(.8)),this.zoomLabel,this.button(pR(`zoom-in`),t.zoomIn,()=>e.zoomBy(1.25)),this.button(pR(`fit`),t.zoomFit,()=>e.fit()))}zoomChanged(){this.zoomLabel.textContent=`${Math.round(this.v.zoom*100)}%`}refresh(){this.buildBar();let e=(this.v.editable||this.v.opts.onComment)&&!this.v.editing&&!this.v.isPresenting?this.v.selection():[],t=JSON.stringify([e,this.v.activeNode,this.v.styles.shape.rough]);t!==this.lastProps&&(this.lastProps=t,this.buildProps(e)),this.place()}place(){let e=this.props;if(e.hidden)return;let t=this.v.selectionScreenBox();if(!t){e.hidden=!0;return}let n=this.v.root.getBoundingClientRect(),r=e.offsetWidth,i=e.offsetHeight,a=t.x+t.w/2-r/2;a=Math.max(8,Math.min(n.width-r-8,a));let o=t.y-i-40;o<8&&(o=Math.min(n.height-i-64,t.y+t.h+16)),e.style.left=`${a}px`,e.style.top=`${Math.max(8,o)}px`}buildProps(e){let t=this.props;if(t.replaceChildren(),!e.length){t.hidden=!0;return}t.hidden=!1;let n=this.v,r=n.labels,i=n.opts.onComment,a=()=>this.button(pR(`comment`),r.comment,()=>{let t=e[0].id;i?.({id:t,text:n.elementText(t).slice(0,500)})});if(!n.editable){i&&e.length===1?t.append(a()):t.hidden=!0;return}let o=new Set(e.map(e=>e.type)).size===1?e[0]:null,s=[],c=(e,t,n,r)=>{let i=this.button(t,n,()=>this.togglePop(e,i,r),{pop:e});s.push(i)},l=(e,t,r,i,a)=>c(e,``,t,()=>{let e=this.div(``);return e.append(this.colorRow(r,e=>n.restyle({[i]:e}),a,t)),e}),u=(e,t,r,i,a,o,s,l=e=>e)=>c(e,a(r),t,()=>{let e=this.div(``);return e.append(this.row(...i.map(e=>this.button(a(e),s(e),()=>{n.restyle({[o]:l(e)}),this.hidePop(),this.lastProps=``,this.refresh()},{active:e===r})))),e}),d=(e,t,n,r)=>s.push(this.button(e,t,r,{active:n}));if(o?.type===`shape`)u(`kind`,r.shape,o.shape,wF,hR,`shape`,e=>r[e]),l(`fill`,r.fill,o.fill,`fill`,!0),l(`stroke`,r.stroke,o.stroke,`stroke`,!0),u(`style`,r.lineStyle,o.strokeStyle,[`solid`,`dash`,`none`],e=>hR(e===`none`?`noLine`:e),`strokeStyle`,e=>e===`none`?r.noLine:r[e]),u(`width`,r.thickness,String(o.strokeWidth),[`1`,`2`,`4`,`6`],e=>``,`strokeWidth`,e=>`${r.thickness} ${e}`,Number),d(`${r.scribbled}`,r.scribbled,o.rough,()=>{n.restyle({rough:!o.rough}),this.lastProps=``,this.refresh()}),l(`textColor`,r.textColor,o.textColor,`textColor`,!1);else if(o?.type===`connector`){u(`mode`,r.connector,o.mode,TF,hR,`mode`,e=>r[e]),l(`stroke`,r.stroke,o.stroke,`stroke`,!1),u(`style`,r.lineStyle,o.strokeStyle===`none`?`solid`:o.strokeStyle,[`solid`,`dash`],hR,`strokeStyle`,e=>r[e]);let e=e=>hR(e===`triangle`?`triangleEnd`:e===`diamond`?`diamondEnd`:e);u(`start`,r.startArrow,o.startArrow,EF,t=>`${e(t)}`,`startArrow`,e=>e),u(`end`,r.endArrow,o.endArrow,EF,e,`endArrow`,e=>e)}else o?.type===`brush`?l(`color`,r.stroke,o.color,`color`,!1):o?.type===`text`?(l(`color`,r.textColor,o.color,`color`,!1),u(`size`,r.fontSize,String(o.fontSize),[`16`,`24`,`32`,`48`,`64`],e=>`${e}`,`fontSize`,e=>`${r.fontSize} ${e}`,Number),u(`font`,r.font,o.font||`sans`,[`sans`,`serif`,`mono`],e=>`Aa`,`font`,e=>r[e],e=>e===`sans`?``:e),u(`align`,r.alignLeft,o.align,[`left`,`center`,`right`],e=>pR(`align-${e}`),`align`,e=>r[e===`left`?`alignLeft`:e===`center`?`alignCenter`:`alignRight`]),d(pR(`bold`),r.bold,o.bold,()=>{n.restyle({bold:!o.bold}),this.lastProps=``,this.refresh()})):o?.type===`note`||o?.type===`frame`?l(`bg`,r.background,o.background,`background`,!0):o?.type===`mindmap`?(u(`layout`,r.layout,o.layout,DF,e=>hR(e),`layout`,e=>r[e===`right`?`layoutRight`:e===`left`?`layoutLeft`:`layoutRadial`]),l(`color`,r.stroke,o.color,`color`,!1),n.activeNode?.map===o.id&&s.push(this.button(`+ ${r.addChild}`,r.addChild,()=>n.mindmapAdd(`child`),{cls:`dw-cv-wide`}))):o?.type===`embed`&&e.length===1&&s.push(this.button(pR(`open`),r.openLink,()=>window.open(o.url,`_blank`,`noopener,noreferrer`)));t.append(...s),i&&e.length===1&&t.append(a()),s.length&&t.append(this.sep());let f=e.filter(e=>e.type===`group`);e.length>1&&!f.length&&t.append(this.button(pR(`group`),r.group,()=>n.group())),f.length&&t.append(this.button(pR(`layers`),r.ungroup,()=>n.ungroup()));let p=e.every(e=>e.type===`note`&&e.page);t.append(this.button(pR(`arrow-up`),r.bringFront,()=>n.reorder(`front`)),this.button(pR(`send-back`),r.sendBack,()=>n.reorder(`back`))),p||t.append(this.button(pR(`copy`),r.duplicate,()=>n.duplicate()),this.button(pR(`trash`),r.delete,()=>n.deleteSelection(),{cls:`dw-cv-danger`}))}toast(e){let t=this.div(`dw-cv-ui dw-cv-toast`);t.setAttribute(`role`,`status`),t.textContent=e,this.v.root.append(t),setTimeout(()=>t.remove(),2600)}presentBar(){let e=this.v,t=e.labels,n=this.div(`dw-cv-ui dw-cv-presentbar`),r=this.div(`dw-cv-step`);return r.setAttribute(`aria-live`,`polite`),n.append(this.button(pR(`chevron-left`),t.presentPrevious,()=>e.presentStep(-1)),r,this.button(pR(`chevron-right`),t.presentNext,()=>e.presentStep(1)),this.button(pR(`close`),t.presentExit,()=>e.stopPresenting())),e.root.append(n),this.hidePop(),this.refresh(),n}presentStep(e,t){let n=this.v.root.querySelector(`.dw-cv-step`);n&&(n.textContent=this.v.labels.presentStep.replace(`{n}`,String(e+1)).replace(`{total}`,String(t)))}};function vR(e){let t=getComputedStyle(e),n=(e,n)=>t.getPropertyValue(e).trim()||n,r=n(`--dw-surface`,`#ffffff`),i=e=>{let t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!t)return null;let n=t[1].length===3?[...t[1]].map(e=>e+e).join(``):t[1];return[0,2,4].map(e=>parseInt(n.slice(e,e+2),16))},a=(e,t,n)=>{let r=i(e),a=i(t);return!r||!a?e:`#${r.map((e,t)=>Math.round(e*n+a[t]*(1-n)).toString(16).padStart(2,`0`)).join(``)}`};return(e,t)=>{if(e===`none`)return`none`;if(e===`ink`)return t===`fill`?n(`--dw-surface-sunken`,`#f3f3f1`):n(`--dw-ink`,`#1d1f1e`);if(e===`paper`)return t===`fill`?n(`--dw-surface-raised`,`#ffffff`):r;let i=n(`--dw-c-${e}`,`#888888`);return t===`fill`?a(i,r,.22):i}}function yR(e){let t=[],n=e=>(e.content??[]).map(e=>e.type===`text`?e.text??``:e.type===`hardBreak`?` +`:n(e)).join(``),r=(e,i)=>{for(let a of e)if(a.type===`heading`){let e=Number(a.attrs?.level)||1;t.push({text:n(a),size:[0,26,21,18,16,16,16][e]??16,weight:650})}else if(a.type===`paragraph`)t.push({text:i+n(a),size:15,weight:400});else if(a.type===`listItem`||a.type===`taskItem`){let e=a.type===`taskItem`?a.attrs?.checked?`☑ `:`☐ `:`• `,[i,...o]=a.content??[];i&&t.push({text:e+n(i),size:15,weight:400}),r(o,` `)}else a.type===`codeBlock`?t.push({text:n(a),size:13,weight:400}):a.content?.length&&r(a.content,i)};return r(e,``),t}function bR(e,t,n,r,i,a,o=400,s=`start`){let c=Math.round(r*1.35);return n.map((n,l)=>`${UL(n)}`).join(``)}async function xR(e){if(e.startsWith(`data:`))return e;try{let t=await fetch(e,{credentials:`include`});if(!t.ok)return null;let n=await t.blob();return await new Promise(e=>{let t=new FileReader;t.onload=()=>e(typeof t.result==`string`?t.result:null),t.onerror=()=>e(null),t.readAsDataURL(n)})}catch{return null}}async function SR(e){let t=vR(e.root),n=e.elements.filter(e=>e.type!==`group`),r=ZP(XP(n.map(t=>e.boxOf(t)))??{x:0,y:0,w:400,h:300},32),i=t(`ink`,`line`),a=[];for(let r of n){let n=e.boxOf(r),o=r.rotate?` rotate(${r.rotate} ${n.w/2} ${n.h/2})`:``,s=e=>`${e}`;switch(r.type){case`shape`:{let e=oI(r.text,r.fontSize,Math.max(20,n.w-16)),i=Math.round(r.fontSize*1.35),o=n.h/2-e.length*i/2-r.fontSize*.25;a.push(s(ZL(r,t)+(r.text?bR(n.w/2,o,e,r.fontSize,t(r.textColor,`line`),tI,400,`middle`):``)));break}case`text`:{let e=iI(r.font),i=r.w?oI(r.text,r.fontSize,r.w,e):r.text.split(` +`),o=r.align===`center`?n.w/2:r.align===`right`?n.w:0,c=r.align===`center`?`middle`:r.align===`right`?`end`:`start`;a.push(s(bR(o,0,i,r.fontSize,t(r.color,`line`),e,r.bold?650:400,c)));break}case`connector`:{let n=e.routeOf(r);if(a.push($L(r,n,t)),r.label){let e=Math.min(240,r.label.length*8+16);a.push(``+bR(n.mid[0],n.mid[1]-12+3,[r.label],13,i,tI,400,`middle`))}break}case`brush`:a.push(s(tR(r,t)));break;case`frame`:a.push(s(``+bR(4,-24,[r.title],13,t(`gray`,`line`),tI,600)));break;case`note`:{let o=e.noteBody(r),c=o?yR(nR(o)):[],l=18,u=``;if(r.page&&e.pageTitle){let t=oI(e.pageTitle,26,n.w-48,tI,650);u+=bR(24,l-4,t,26,i,tI,650),l+=t.length*35+8}for(let e of c){let t=oI(e.text,e.size,n.w-48,tI,e.weight);if(u+=bR(24,l,t,e.size,i,tI,e.weight),l+=t.length*Math.round(e.size*1.35)+8,l>n.h-12)break}a.push(s(u));break}case`image`:{let i=await xR(e.resolve(r.src));a.push(s(i?``:``));break}case`embed`:a.push(s(``+bR(16,16,oI(r.url,13,n.w-32),13,t(`blue`,`line`),tI)));break;case`mindmap`:{let n=e.layoutOf(r),o=t(r.color,`line`),s=t(r.color,`fill`),c=n.edges.map(e=>``).join(``);for(let e of n.boxes.values()){let n=e.depth===0?18:15,a=e.depth===0?600:400,l=e.depth===0?o:e.depth===1?s:t(`paper`,`line`),u=e.depth===0?t(`paper`,`line`):i;c+=``;let d=oI(r.nodes[e.id]?.text||` `,n,260,tI,a);c+=bR(e.x+e.w/2,e.y+(e.h-d.length*Math.round(n*1.4))/2-2,d,n,u,tI,a,`middle`)}a.push(`${c}`);break}}}return{svg:`${a.join(``)}`,box:r}}async function CR(e,t){let{svg:n,box:r}=await SR(t),i=new Blob([n],{type:`image/svg+xml`});if(e===`svg`)return i;let a=Math.min(2,8192/Math.max(r.w,r.h,1)),o=URL.createObjectURL(i);try{let e=await new Promise((e,t)=>{let n=new Image;n.onload=()=>e(n),n.onerror=()=>t(Error(`could not draw the canvas`)),n.src=o}),t=document.createElement(`canvas`);t.width=Math.ceil(r.w*a),t.height=Math.ceil(r.h*a);let n=t.getContext(`2d`);if(!n)throw Error(`could not draw the canvas`);return n.drawImage(e,0,0,t.width,t.height),await new Promise((e,n)=>t.toBlob(t=>t?e(t):n(Error(`could not draw the canvas`)),`image/png`))}finally{URL.revokeObjectURL(o)}}var wR=.1,TR=4,ER=`http://www.w3.org/2000/svg`,DR=e=>e instanceof HTMLElement&&(e.isContentEditable||e.tagName===`INPUT`||e.tagName===`TEXTAREA`),OR=class{opts;store;labels;root;styles;editable;tool=`select`;shapeKind;selected=new Set;activeNode=null;editing=null;entered=null;world;overlay;ui;view={x:0,y:0,zoom:1};rendered=new Map;measured=new Map;layouts=new Map;routes=new Map;previews=new Map;drag=null;guides=[];marquee=null;hover=null;raf=0;spaceDown=!1;pointers=new Map;pinch=null;presenting=null;comments=[];activeComment=``;resize=typeof ResizeObserver>`u`?null:new ResizeObserver(e=>this.onResize(e));unsub;cleanups=[];saveTimer;constructor(e,t){this.opts=t,this.labels=t.labels??bF,this.editable=t.editable,this.styles=UF(t.styles),this.shapeKind=this.styles.shape.shape,this.store=new uR(t.doc,{undo:t.undo!==!1}),this.root=document.createElement(`div`),this.root.className=`dw-cv`,this.root.tabIndex=0,this.root.setAttribute(`role`,`application`),this.root.dataset.testid=`edgeless-canvas`,this.world=document.createElement(`div`),this.world.className=`dw-cv-world`,this.overlay=document.createElementNS(ER,`svg`),this.overlay.classList.add(`dw-cv-overlay`),this.root.append(this.world,this.overlay),e.append(this.root),this.ui=new _R(this),this.root.classList.toggle(`dw-cv-readonly`,!this.editable),this.unsub=this.store.onChange(()=>this.schedule()),this.listen(),this.render(),this.restoreView()||this.fit(void 0,!1),this.applyView()}destroy(){cancelAnimationFrame(this.raf),clearTimeout(this.saveTimer),this.saveView(),this.unsub(),this.resize?.disconnect();for(let e of this.cleanups)e();for(let e of this.rendered.values())e.note?.destroy();this.rendered.clear(),this.ui.destroy(),this.store.destroy(),this.root.remove()}setEditable(e){if(e!==this.editable){this.editable=e,this.root.classList.toggle(`dw-cv-readonly`,!e),e||(this.stopEditing(),this.tool=`select`);for(let t of this.rendered.values())t.note?.setEditable(e);this.ui.refresh()}}get(e){return this.store.get(e)}elements(){return this.store.elements()}boxOf(e){switch(e.type){case`note`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:e.w,h:t?.h??e.h}}case`text`:{let t=this.measured.get(e.id);return{x:e.x,y:e.y,w:t?.w??e.w,h:t?.h??e.h}}case`group`:return XP(this.elements().filter(t=>t.group===e.id).map(e=>this.outerBox(e)))??{x:e.x,y:e.y,w:0,h:0};case`mindmap`:{let t=this.layoutOf(e);return{x:e.x+t.bounds.x,y:e.y+t.bounds.y,w:t.bounds.w,h:t.bounds.h}}case`connector`:{let t=this.routeOf(e),n=t.points.map(e=>e[0]),r=t.points.map(e=>e[1]);return eF([Math.min(...n),Math.min(...r)],[Math.max(...n),Math.max(...r)])}default:return{x:e.x,y:e.y,w:e.w,h:e.h}}}outerBox(e){let t=this.boxOf(e);return e.rotate?nF(t,e.rotate):t}layoutOf(e){let t=this.layouts.get(e.id),n=JSON.stringify([e.layout,e.nodes]);return t&&t.key===n||(t=fI(e.nodes,e.layout,sI),t.key=n,this.layouts.set(e.id,t)),t}routeOf(e){let t=lF(e,e=>{let t=this.get(e);return!t||t.type===`connector`?null:{box:this.outerBox(t),ellipse:t.type===`shape`&&t.shape===`ellipse`}});return pF(e.mode,t[0],t[1])}selection(){return[...this.selected].map(e=>this.get(e)).filter(e=>!!e)}expanded(e){let t=new Set,n=this.elements();for(let r of e){t.add(r);for(let e of n)e.group===r&&t.add(e.id)}return[...t]}schedule(){this.raf||=requestAnimationFrame(()=>{this.raf=0,this.render()})}render(){let e=this.elements(),t=new Set,n=null;for(let r of e){t.add(r.id);let e=this.rendered.get(r.id);e&&e.type!==r.type&&(e.note?.destroy(),e.el.remove(),e=void 0),e||(e={el:document.createElement(`div`),key:``,type:r.type},e.el.className=`dw-cv-el dw-cv-${r.type}`,e.el.dataset.id=r.id,this.rendered.set(r.id,e),(r.type===`note`||r.type===`text`)&&this.resize?.observe(e.el));let i=this.keyOf(r);e.key===i||this.editing?.id===r.id&&this.stopEditingFn&&r.type!==`note`||(this.draw(e,r),e.key=i),e.el.classList.toggle(`dw-cv-selected`,this.selected.has(r.id)),e.el.classList.toggle(`dw-cv-editing`,this.editing?.id===r.id);let a=n?n.nextElementSibling:this.world.firstElementChild;a!==e.el&&this.world.insertBefore(e.el,a),n=e.el}for(let[e,n]of this.rendered)t.has(e)||(n.note?.destroy(),this.resize?.unobserve(n.el),n.el.remove(),this.rendered.delete(e),this.measured.delete(e),this.selected.delete(e));this.editing&&!t.has(this.editing.id)&&(this.editing=null),this.drawOverlay(),this.ui.refresh()}keyOf(e){if(e.type===`connector`){let t=this.routeOf(e);return this.routes.set(e.id,t),JSON.stringify(e)+t.d}return e.type===`note`&&e.page?JSON.stringify(e)+(this.opts.pageTitle?.()??``):JSON.stringify(e)}place(e,t,n=0,r=!1){e.style.transform=`translate(${t.x}px, ${t.y}px)${n?` rotate(${n}deg)`:``}`,e.style.width=r?``:`${t.w}px`,e.style.height=r?``:`${t.h}px`}draw(e,t){let n=e.el,r=this.editing?.id===t.id;switch(t.type){case`shape`:{this.place(n,t,t.rotate);let e=r?n.querySelector(`.dw-cv-label`):null;n.innerHTML=`${ZL(t,HL)}`;let i=e??document.createElement(`div`);i.className=`dw-cv-label`,e||(i.textContent=t.text),i.style.color=HL(t.textColor,`line`),i.style.fontSize=`${t.fontSize}px`,n.append(i);return}case`text`:{n.style.transform=`translate(${t.x}px, ${t.y}px)${t.rotate?` rotate(${t.rotate}deg)`:``}`,n.style.width=t.w?`${t.w}px`:``,n.style.height=``;let e=n.querySelector(`.dw-cv-textbody`);e||(e=document.createElement(`div`),e.className=`dw-cv-textbody`,n.append(e)),r||(e.textContent=t.text),e.dataset.placeholder=this.labels.textPlaceholder,Object.assign(e.style,{color:HL(t.color,`line`),fontSize:`${t.fontSize}px`,fontFamily:iI(t.font),textAlign:t.align,fontWeight:t.bold?`650`:``,whiteSpace:t.w?`pre-wrap`:`pre`});return}case`connector`:{let e=this.routes.get(t.id)??this.routeOf(t),i=this.boxOf(t),a=24+t.strokeWidth*3,o={x:i.x-a,y:i.y-a,w:i.w+a*2,h:i.h+a*2};this.place(n,o);let s=``,c=t.label||r;n.innerHTML=`${$L(t,e,HL)}${s}`+(c?`
${UL(t.label)}
`:``);return}case`brush`:this.place(n,t,t.rotate),n.innerHTML=`${tR(t,HL).replace(``;return;case`note`:this.drawNote(e,t);return;case`frame`:{this.place(n,t);let e=r?n.querySelector(`.dw-cv-frametitle`):null;n.innerHTML=``;let i=e??document.createElement(`div`);i.className=`dw-cv-frametitle`,e||(i.textContent=t.title||this.labels.frameTitle),n.append(i);return}case`image`:{this.place(n,t,t.rotate);let e=this.opts.files?.resolve(t.src)??t.src,r=n.querySelector(`img`);r||(r=document.createElement(`img`),r.draggable=!1,n.replaceChildren(r)),r.getAttribute(`src`)!==e&&(r.src=e),r.alt=t.alt;return}case`embed`:this.drawEmbed(n,t);return;case`group`:n.style.display=`none`;return;case`mindmap`:this.drawMindmap(n,t);return}}drawNote(e,t){let n=e.el;if(n.style.transform=`translate(${t.x}px, ${t.y}px)`,n.style.width=`${t.w}px`,n.style.height=``,n.style.setProperty(`--dw-cv-note-bg`,HL(t.background,`fill`)),n.classList.toggle(`dw-cv-pagenote`,t.page),!e.note){let r=document.createElement(`div`);r.className=`dw-cv-notehead`;let i=document.createElement(`div`);i.className=`dw-cv-notebody`,n.replaceChildren(r,i);let a=t.page?this.opts.doc.getXmlFragment(`default`):this.store.body(t.id);if(a)try{e.note=this.opts.notes.mount(i,{id:t.id,page:t.page,fragment:a,doc:this.opts.doc,editable:this.editable})}catch(e){this.opts.onError?.(e)}}let r=n.querySelector(`.dw-cv-notehead`);r&&(r.textContent=t.page?this.opts.pageTitle?.()||this.labels.pageNote:``)}drawEmbed(e,t){this.place(e,t);let n=this.opts.embedSource?.(t.url)??null;if(n){if(e.querySelector(`iframe`)?.getAttribute(`src`)===n.src)return;let r=document.createElement(`iframe`);r.src=n.src,r.title=t.url,r.allow=`fullscreen; picture-in-picture; encrypted-media`,r.referrerPolicy=`strict-origin-when-cross-origin`,r.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`),e.replaceChildren(r);return}let r=this.previews.get(t.url);r===void 0&&this.opts.links&&(this.previews.set(t.url,`loading`),this.opts.links.preview(t.url).then(e=>this.previews.set(t.url,e)).catch(()=>this.previews.set(t.url,null)).finally(()=>{let e=this.rendered.get(t.id);e&&(e.key=``),this.schedule()}),r=`loading`);let i=r&&r!==`loading`?r:null,a=t.url;try{a=new URL(t.url).hostname}catch{}let o=i?.image?``:``;e.innerHTML=`${o}${UL(i?.title||a)}${i?.description?`${UL(i.description)}`:``}${UL(i?.site||a)}`}drawMindmap(e,t){let n=this.layoutOf(t),r=n.bounds;this.place(e,{x:t.x+r.x,y:t.y+r.y,w:r.w,h:r.h});let i=HL(t.color,`line`),a=HL(t.color,`fill`),o=n.edges.map(e=>``).join(``),s=this.editing?.id===t.id?this.editing.node:void 0,c=s?e.querySelector(`[data-node="${s}"]`):null,l=[...n.boxes.values()].map(e=>{let n=e.depth===0?`dw-cv-node dw-cv-root`:`dw-cv-node`,o=this.activeNode?.map===t.id&&this.activeNode.node===e.id?` dw-cv-active`:``,s=`left:${e.x-r.x}px;top:${e.y-r.y}px;width:${e.w}px;height:${e.h}px;${e.depth===0?`background:${i};color:var(--dw-surface)`:e.depth===1?`background:${a};border-color:${i}`:`border-color:${i}`}`;return`
${UL(t.nodes[e.id]?.text??``)}
`});e.innerHTML=`${o}${l.join(``)}`,c&&s&&e.querySelector(`[data-node="${s}"]`)?.replaceWith(c)}onResize(e){let t=!1;for(let n of e){let e=n.target,r=e.dataset.id;if(!r)continue;let i={w:e.offsetWidth,h:e.offsetHeight},a=this.measured.get(r);a&&a.w===i.w&&a.h===i.h||(this.measured.set(r,i),t=!0)}if(t){for(let e of this.rendered.values())e.type===`connector`&&(e.key=``);this.schedule()}}toScreen([e,t]){return[e*this.view.zoom+this.view.x,t*this.view.zoom+this.view.y]}toWorld(e,t){let n=this.root.getBoundingClientRect();return[(e-n.left-this.view.x)/this.view.zoom,(t-n.top-this.view.y)/this.view.zoom]}get zoom(){return this.view.zoom}selectionScreenBox(){let e=XP(this.selection().map(e=>this.outerBox(e)));if(!e)return null;let[t,n]=this.toScreen([e.x,e.y]);return{x:t,y:n,w:e.w*this.view.zoom,h:e.h*this.view.zoom}}drawOverlay(){let e=[],t=this.view.zoom,n=(e,t)=>{let n=YP(e);return[[e.x,e.y],[e.x+e.w,e.y],[e.x+e.w,e.y+e.h],[e.x,e.y+e.h]].map(e=>this.toScreen(tF(e,n,t)).join(`,`)).join(` `)};if(this.entered){let t=this.get(this.entered);t&&e.push(``)}if(this.hover&&this.hover!==this.editing?.id){let t=this.get(this.hover);t&&e.push(``)}let r=this.presenting?[]:this.selection();for(let t of r)if(t.type===`connector`){let n=this.routes.get(t.id)??this.routeOf(t);e.push(``)}else e.push(``);if(this.editable&&!this.presenting&&r.length&&!this.editing){let i=r.length===1?r[0]:null;if(i?.type===`connector`){let t=this.routes.get(i.id)??this.routeOf(i);for(let[n,r]of[[`source`,t.points[0]],[`target`,t.points[t.points.length-1]]]){let[t,i]=this.toScreen(r);e.push(``)}}else if(r.some(LF)&&i?.type!==`mindmap`){let a=i?i.rotate:0,o=i?this.boxOf(i):XP(r.map(e=>this.outerBox(e)));r.length>1&&e.push(``);let s=YP(o),c=[[`nw`,[o.x,o.y]],[`n`,[o.x+o.w/2,o.y]],[`ne`,[o.x+o.w,o.y]],[`e`,[o.x+o.w,o.y+o.h/2]],[`se`,[o.x+o.w,o.y+o.h]],[`s`,[o.x+o.w/2,o.y+o.h]],[`sw`,[o.x,o.y+o.h]],[`w`,[o.x,o.y+o.h/2]]],l=i?.type===`note`;for(let[n,r]of c){if(l&&n!==`e`&&n!==`w`||o.w*t<24&&(n===`n`||n===`s`)||o.h*t<24&&(n===`e`||n===`w`))continue;let[i,c]=this.toScreen(tF(r,s,a));e.push(``)}if(i&&RF(i)){let[n,r]=this.toScreen(tF([o.x+o.w/2,o.y-28/t],s,a));e.push(``)}}}if(this.presenting||this.drawComments(e,n),this.marquee){let[n,r]=this.toScreen([this.marquee.x,this.marquee.y]);e.push(``)}for(let t of this.guides){let n=this.toScreen(t.axis===`x`?[t.value,t.from]:[t.from,t.value]),r=this.toScreen(t.axis===`x`?[t.value,t.to]:[t.to,t.value]);e.push(``)}this.overlay.innerHTML=e.join(``),this.ui.place()}applyView(){let{x:e,y:t,zoom:n}=this.view;this.world.style.transform=`translate(${e}px, ${t}px) scale(${n})`;let r=24*n;this.root.style.backgroundSize=`${r}px ${r}px`,this.root.style.backgroundPosition=`${e}px ${t}px`,this.root.style.setProperty(`--dw-cv-zoom`,String(n)),this.drawOverlay(),this.ui.zoomChanged(),clearTimeout(this.saveTimer),this.saveTimer=setTimeout(()=>this.saveView(),500)}saveView(){if(this.opts.viewKey)try{localStorage.setItem(this.opts.viewKey,JSON.stringify(this.view))}catch{}}restoreView(){if(!this.opts.viewKey)return!1;try{let e=JSON.parse(localStorage.getItem(this.opts.viewKey)??`null`);if(e&&[e.x,e.y,e.zoom].every(e=>typeof e==`number`&&Number.isFinite(e))&&e.zoom>0)return this.view={x:e.x,y:e.y,zoom:Math.min(TR,Math.max(wR,e.zoom))},!0}catch{}return!1}zoomAt(e,t){let n=Math.min(TR,Math.max(wR,e)),r=this.root.getBoundingClientRect(),[i,a]=t??[r.width/2,r.height/2],o=(i-this.view.x)/this.view.zoom,s=(a-this.view.y)/this.view.zoom;this.view={zoom:n,x:i-o*n,y:a-s*n},this.applyView()}zoomBy(e){this.zoomAt(this.view.zoom*e)}fit(e,t=!0,n=48){let r=e??XP(this.elements().map(e=>this.outerBox(e))),i=this.root.getBoundingClientRect(),a=i.width||800,o=i.height||600;if(!r)this.view={x:a/2,y:o/3,zoom:1};else{let t=Math.min(TR,Math.max(wR,Math.min((a-n*2)/Math.max(r.w,1),(o-n*2)/Math.max(r.h,1),e?TR:1)));this.view={zoom:t,x:a/2-(r.x+r.w/2)*t,y:o/2-(r.y+r.h/2)*t},!e&&r.h*t>o&&(this.view.y=n-r.y*t)}t&&this.applyView()}animateTo(e){let t={...this.view},n=performance.now(),r=i=>{let a=Math.min(1,(i-n)/350),o=1-(1-a)**3;this.view={x:t.x+(e.x-t.x)*o,y:t.y+(e.y-t.y)*o,zoom:t.zoom+(e.zoom-t.zoom)*o},this.applyView(),a<1&&requestAnimationFrame(r)};requestAnimationFrame(r)}setTool(e){(this.editable||e===`select`||e===`hand`)&&(this.stopEditing(),this.tool=e,e!==`select`&&this.clearSelection(),this.root.dataset.tool=e,this.ui.refresh())}setShapeKind(e){this.shapeKind=e,this.setStyle(`shape`,{shape:e}),this.setTool(`shape`)}setStyle(e,t){this.styles={...this.styles,[e]:{...this.styles[e],...t}},this.opts.onStyles?.(this.styles)}restyle(e){let t=[];for(let n of this.selection()){let r=Object.fromEntries(Object.entries(e).filter(([e])=>e in n));if(!Object.keys(r).length)continue;t.push([n.id,r]);let i=n.type;if(i in this.styles){let e=Object.fromEntries(Object.entries(r).filter(([e])=>e in this.styles[i]));Object.keys(e).length&&!(n.type===`note`&&n.page)&&this.setStyle(i,e)}}this.store.updateMany(t)}select(e,t=!1){t||this.selected.clear();for(let t of e)this.selected.add(t);this.activeNode&&!this.selected.has(this.activeNode.map)&&(this.activeNode=null),this.refreshSelection()}clearSelection(){(this.selected.size||this.activeNode||this.entered)&&(this.selected.clear(),this.activeNode=null,this.entered=null,this.refreshSelection())}refreshSelection(){for(let[e,t]of this.rendered)t.el.classList.toggle(`dw-cv-selected`,this.selected.has(e)),t.type===`mindmap`&&(t.key=``);this.schedule(),this.drawOverlay(),this.ui.refresh()}pick(e){let t=this.get(e);return t?.group&&this.entered!==t.group&&this.get(t.group)?t.group:e}hit(e){if(!(e instanceof Element)||!this.world.contains(e))return null;let t=e.closest(`[data-id]`);if(!t?.dataset.id)return null;let n=e.closest(`[data-node]`)?.dataset.node;return{id:t.dataset.id,node:n}}connectableAt(e,t,n){for(let r of document.elementsFromPoint(e,t)){let e=this.hit(r);if(!e||n.has(e.id))continue;let t=this.get(e.id);if(t&&zF(t))return t}return null}listen(){let e=(e,t,n,r)=>{e.addEventListener(t,n,r),this.cleanups.push(()=>e.removeEventListener(t,n,r))};e(this.root,`pointerdown`,e=>this.onDown(e)),e(this.root,`pointermove`,e=>this.onMove(e)),e(this.root,`pointerup`,e=>this.onUp(e)),e(this.root,`pointercancel`,e=>this.onUp(e)),e(this.root,`dblclick`,e=>this.onDouble(e)),e(this.root,`wheel`,e=>this.onWheel(e),{passive:!1}),e(this.root,`keydown`,e=>this.onKey(e)),e(this.root,`keyup`,e=>{e.key===` `&&(this.spaceDown=!1,this.root.classList.remove(`dw-cv-panning`))}),e(document,`copy`,e=>this.onCopy(e,!1)),e(document,`cut`,e=>this.onCopy(e,!0)),e(document,`paste`,e=>this.onPaste(e)),e(this.root,`dragover`,e=>{this.editable&&e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()}),e(this.root,`drop`,e=>{let t=[...e.dataTransfer?.files??[]].filter(e=>e.type.startsWith(`image/`));this.editable&&t.length&&(e.preventDefault(),this.addImages(t,this.toWorld(e.clientX,e.clientY)))}),e(document,`fullscreenchange`,()=>{!document.fullscreenElement&&this.presenting&&this.stopPresenting()}),e(this.root,`click`,e=>{e.target.closest?.(`a.dw-cv-card`)&&this.editable&&e.preventDefault()})}inEditor(e){if(!(e instanceof Element))return!1;if(e.closest(`.dw-cv-ui`))return!0;if(this.editing){let t=this.rendered.get(this.editing.id);if(t&&t.el.contains(e)&&(e.closest(`[contenteditable=true]`)||e.closest(`.dw-cv-notebody`)||e.closest(`iframe`)))return!0}return!(this.editable||!e.closest(`.dw-cv-notebody, a.dw-cv-card`))}onDown(e){let t=e.target instanceof Element?e.target.closest(`[data-comment]`):null;if(t?.dataset.comment){e.preventDefault(),this.opts.onCommentSelect?.(t.dataset.comment);return}if(this.inEditor(e.target)||e.button===2)return;if(e.preventDefault(),this.root.focus({preventScroll:!0}),this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pointers.size===2){this.cancelDrag();let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect();this.pinch={dist:Math.hypot(e[0]-t[0],e[1]-t[1]),mid:[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],zoom:this.view.zoom,vx:this.view.x,vy:this.view.y};return}if(this.pointers.size>2)return;this.editing&&this.stopEditing();let n=this.toWorld(e.clientX,e.clientY),r=e.pointerType===`touch`,i=()=>{this.drag={kind:`pan`,sx:e.clientX,sy:e.clientY,vx:this.view.x,vy:this.view.y},this.root.classList.add(`dw-cv-panning`)};if(this.root.setPointerCapture?.(e.pointerId),e.button===1||this.tool===`hand`||this.spaceDown||this.presenting)return e.preventDefault(),i();let a=e.target;if(!this.editable){let e=this.opts.onComment&&this.tool===`select`?this.hit(a):null;if(e){let t=this.pick(e.id);this.select([t]);return}return i()}switch(this.tool){case`pen`:{let t=document.createElementNS(ER,`svg`);t.classList.add(`dw-cv-temp`),this.world.append(t),this.drag={kind:`pen`,points:[[n[0],n[1],e.pressure||.5]],temp:t};return}case`eraser`:this.drag={kind:`erase`,hits:new Set},this.erase(e);return;case`shape`:case`frame`:this.drag={kind:`create`,type:this.tool,start:n,id:null};return;case`connector`:{let t=this.connectableAt(e.clientX,e.clientY,new Set),r=t?this.endOn(t,n):{x:n[0],y:n[1]},i=this.store.add({type:`connector`,...this.styles.connector,source:r,target:{x:n[0],y:n[1]}});this.drag={kind:`end`,id:i,side:`target`};return}case`note`:this.addNote(n);return;case`text`:this.addText(n);return;case`mindmap`:this.addMindmap(n);return}let o=a.dataset?.handle,s=a.dataset?.end;if(s){let e=this.selection()[0];e?.type===`connector`&&(this.store.undo?.stopCapturing(),this.drag={kind:`end`,id:e.id,side:s});return}if(o===`rotate`){let e=this.selection()[0],t=YP(this.boxOf(e));this.store.undo?.stopCapturing(),this.drag={kind:`rotate`,id:e.id,c:t,a0:Math.atan2(n[1]-t[1],n[0]-t[0]),r0:e.rotate};return}if(o){let e=this.selection(),t=e.length===1?e[0]:null,n=new Map(this.expanded(this.selected).map(e=>[e,this.get(e)]));for(let[e,t]of n){let r=this.measured.get(e);t.type===`text`&&r&&n.set(e,{...t,w:r.w,h:r.h}),t.type===`note`&&r&&n.set(e,{...t,h:r.h})}this.store.undo?.stopCapturing(),this.drag={kind:`resize`,handle:o,box:t?this.boxOf(t):XP(e.map(e=>this.outerBox(e))),deg:t?t.rotate:0,orig:n,keep:e.some(e=>e.type===`image`||e.type===`text`||e.type===`brush`)||e.length>1};return}let c=this.hit(a);if(c){let t=this.pick(c.id),r=this.get(t);if(r?.type===`mindmap`&&c.node){this.activeNode={map:t,node:c.node};let e=this.rendered.get(t);e&&(e.key=``)}else r?.type!==`mindmap`&&(this.activeNode=null);e.shiftKey?(this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.refreshSelection()):this.selected.has(t)?this.refreshSelection():this.select([t]),this.startMove(n,t)}else{if(r)return i();this.entered=null,this.drag={kind:`marquee`,start:n,add:e.shiftKey,base:e.shiftKey?new Set(this.selected):new Set},e.shiftKey||this.clearSelection()}}startMove(e,t){let n=this.expanded(this.selected);for(let e of[...n]){let t=this.get(e);if(t?.type===`frame`)for(let e of this.elements())e.type!==`frame`&&!n.includes(e.id)&&$P(t,this.outerBox(e))&&n.push(...this.expanded([e.id]))}let r=[...new Set(n)].filter(e=>this.get(e)?.type!==`group`),i=new Map(r.map(e=>[e,this.get(e)])),a=XP(r.map(e=>this.outerBox(this.get(e))))??{x:e[0],y:e[1],w:0,h:0};this.store.undo?.stopCapturing(),this.drag={kind:`move`,start:e,ids:r,orig:i,box:a,moved:!1,clickId:t}}endOn(e,t){let n=this.outerBox(e),r=yF(n,t,14/this.view.zoom);return r?{id:e.id,pos:[(r[0]-n.x)/Math.max(n.w,1),(r[1]-n.y)/Math.max(n.h,1)]}:{id:e.id}}onMove(e){if(this.pointers.has(e.pointerId)&&this.pointers.set(e.pointerId,[e.clientX,e.clientY]),this.pinch&&this.pointers.size>=2){let[e,t]=[...this.pointers.values()],n=this.root.getBoundingClientRect(),r=Math.hypot(e[0]-t[0],e[1]-t[1]),i=[(e[0]+t[0])/2-n.left,(e[1]+t[1])/2-n.top],a=this.pinch,o=Math.min(TR,Math.max(wR,a.zoom*r/Math.max(a.dist,1))),s=(a.mid[0]-a.vx)/a.zoom,c=(a.mid[1]-a.vy)/a.zoom;this.view={zoom:o,x:i[0]-s*o,y:i[1]-c*o},this.applyView();return}let t=this.drag,n=this.toWorld(e.clientX,e.clientY);if(t)switch(t.kind){case`pan`:this.view={...this.view,x:t.vx+e.clientX-t.sx,y:t.vy+e.clientY-t.sy},this.applyView();return;case`move`:{let r=n[0]-t.start[0],i=n[1]-t.start[1];if(!t.moved&&Math.hypot(r,i)*this.view.zoom<3)return;if(t.moved=!0,e.altKey)this.guides=[];else{let e=new Set(t.ids),n=this.visibleBoxes().filter(([t])=>!e.has(t)).map(([,e])=>e),a=vF({...t.box,x:t.box.x+r,y:t.box.y+i},n,6/this.view.zoom);r+=a.dx,i+=a.dy,this.guides=a.guides}let a=[];for(let[e,n]of t.orig)if(n.type===`connector`){let t={};for(let e of[`source`,`target`]){let a=n[e];a.id||(t[e]={x:(a.x??0)+r,y:(a.y??0)+i})}Object.keys(t).length&&a.push([e,t])}else a.push([e,{x:n.x+r,y:n.y+i}]);this.store.updateMany(a);return}case`marquee`:{this.marquee=eF(t.start,n);let e=new Set(t.base),r=this.marquee;for(let t of this.elements()){if(t.group&&this.get(t.group))continue;let n=this.outerBox(t);(t.type===`frame`?$P(r,n):QP(r,n))&&e.add(t.id)}for(let t of this.elements().filter(e=>e.type===`group`))QP(r,this.boxOf(t))&&e.add(t.id);this.selected.clear();for(let t of e)this.selected.add(t);this.refreshSelection();return}case`resize`:this.doResize(t,n,e.shiftKey);return;case`rotate`:{let r=t.r0+(Math.atan2(n[1]-t.c[1],n[0]-t.c[0])-t.a0)*180/Math.PI;e.shiftKey&&(r=Math.round(r/15)*15),r=(r%360+360)%360,this.store.update(t.id,{rotate:Math.round(r*10)/10});return}case`create`:{let r=eF(t.start,n);if(!t.id&&r.w*this.view.zoom<4&&r.h*this.view.zoom<4)return;e.shiftKey&&(r.w=r.h=Math.max(r.w,r.h)),t.id?this.store.update(t.id,{...r}):t.id=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...r}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...r});return}case`end`:{let r=this.get(t.id);if(r?.type!==`connector`)return;let i=r[t.side===`source`?`target`:`source`],a=new Set([t.id]),o=this.connectableAt(e.clientX,e.clientY,a);this.hover=o?.id??null;let s=o&&o.id!==i.id?this.endOn(o,n):{x:n[0],y:n[1]};this.store.update(t.id,{[t.side]:s});return}case`pen`:t.points.push([n[0],n[1],e.pressure||.5]),t.temp.innerHTML=``;return;case`erase`:this.erase(e);return}else if(this.editable&&this.tool===`connector`){let t=this.connectableAt(e.clientX,e.clientY,new Set);(t?.id??null)!==this.hover&&(this.hover=t?.id??null,this.drawOverlay())}}erase(e){let t=this.drag;if(t?.kind!==`erase`)return;let n=this.toWorld(e.clientX,e.clientY),r=6/this.view.zoom;for(let n of document.elementsFromPoint(e.clientX,e.clientY)){let e=this.hit(n);if(!e)continue;let r=this.get(e.id);r&&r.type!==`note`&&r.type!==`frame`&&(t.hits.add(r.id),this.rendered.get(r.id)?.el.classList.add(`dw-cv-erasing`))}for(let e of this.elements())e.type!==`brush`||t.hits.has(e.id)||iF(n,e.points.map(t=>[t[0]+e.x,t[1]+e.y]))<=r+e.size/2&&(t.hits.add(e.id),this.rendered.get(e.id)?.el.classList.add(`dw-cv-erasing`))}doResize(e,t,n){let r=e.box,i=YP(r),a=tF(t,i,-e.deg),o=r.x,s=r.y,c=r.x+r.w,l=r.y+r.h;e.handle.includes(`w`)&&(o=a[0]),e.handle.includes(`e`)&&(c=a[0]),e.handle.includes(`n`)&&(s=a[1]),e.handle.includes(`s`)&&(l=a[1]);let u=8/this.view.zoom;c-o[e[0]*m,e[1]*h,e[2]??.5])}]);break;case`mindmap`:case`group`:v.push([t,{x:e,y:i}]);break;default:v.push([t,{x:e,y:i,w:n.w*m,h:n.h*h}])}}this.store.updateMany(v)}visibleBoxes(){let e=this.root.getBoundingClientRect(),t=eF(this.toWorld(e.left,e.top),this.toWorld(e.right,e.bottom)),n=[];for(let e of this.elements()){if(e.type===`connector`||e.type===`group`)continue;let r=this.outerBox(e);if(QP(t,r)&&n.push([e.id,r]),n.length>300)break}return n}onUp(e){if(this.pointers.delete(e.pointerId),this.pinch){this.pointers.size<2&&(this.pinch=null);return}let t=this.drag;if(this.drag=null,this.root.classList.remove(`dw-cv-panning`),this.guides=[],this.marquee=null,this.hover=null,!t)return;let n=this.toWorld(e.clientX,e.clientY);switch(t.kind){case`create`:{let e=t.id;if(!e){let r=t.type===`frame`?{w:800,h:600}:{w:140,h:100},i={x:n[0]-r.w/2,y:n[1]-r.h/2,...r};e=t.type===`shape`?this.store.add({type:`shape`,...this.styles.shape,shape:this.shapeKind,...i}):this.store.add({type:`frame`,...this.styles.frame,title:this.frameName(),...i})}this.tool=`select`,this.root.dataset.tool=`select`,this.select([e]);break}case`end`:{let e=this.get(t.id);if(e?.type===`connector`){let n=this.routeOf(e),r=n.points[0],i=n.points[n.points.length-1];Math.hypot(r[0]-i[0],r[1]-i[1])*this.view.zoom<8&&this.tool===`connector`?this.store.remove([t.id]):this.tool===`connector`&&this.select([t.id])}break}case`pen`:{t.temp.remove(),t.points.length<2&&t.points.push([t.points[0][0]+.5,t.points[0][1]+.5,.5]);let e=t.points.map(e=>e[0]),n=t.points.map(e=>e[1]),r=this.styles.brush.size,i=Math.min(...e)-r,a=Math.min(...n)-r,o=Math.max(...e)+r-i,s=Math.max(...n)+r-a;this.store.add({type:`brush`,...this.styles.brush,x:i,y:a,w:o,h:s,points:t.points.map(e=>[Math.round((e[0]-i)*10)/10,Math.round((e[1]-a)*10)/10,Math.round((e[2]??.5)*100)/100])});break}case`erase`:for(let e of t.hits)this.rendered.get(e)?.el.classList.remove(`dw-cv-erasing`);t.hits.size&&this.store.remove(t.hits)}this.drawOverlay(),this.ui.refresh()}cancelDrag(){let e=this.drag;e?.kind===`pen`&&e.temp.remove(),this.drag=null,this.marquee=null,this.guides=[]}onDouble(e){if(this.inEditor(e.target)||!this.editable||this.tool!==`select`)return;let t=this.hit(e.target);if(!t){this.addText(this.toWorld(e.clientX,e.clientY));return}let n=this.get(t.id);n&&(n.group&&this.entered!==n.group&&this.get(n.group)?(this.entered=n.group,this.select([n.id])):(n.type!==`frame`||e.target.closest(`.dw-cv-frametitle`))&&this.startEdit(n.id,t.node))}onWheel(e){if(this.presenting||e.target instanceof Element&&e.target.closest(`.dw-cv-ui`))return;e.preventDefault();let t=this.root.getBoundingClientRect();if(e.ctrlKey||e.metaKey){this.zoomAt(this.view.zoom*Math.exp(-e.deltaY*.01),[e.clientX-t.left,e.clientY-t.top]);return}let n=e.deltaMode===1?16:1,r=e.shiftKey&&!e.deltaX?e.deltaY:e.deltaX,i=e.shiftKey&&!e.deltaX?0:e.deltaY;this.view={...this.view,x:this.view.x-r*n,y:this.view.y-i*n},this.applyView()}onKey(e){if(this.presenting){this.presentKey(e);return}if(DR(e.target)||this.inEditor(e.target))return;let t=e.ctrlKey||e.metaKey,n=e.key.toLowerCase();if(e.key===` `&&!t){this.spaceDown=!0,this.root.classList.add(`dw-cv-panning`),e.preventDefault();return}if(t&&(n===`=`||n===`+`))return e.preventDefault(),this.zoomBy(1.25);if(t&&n===`-`)return e.preventDefault(),this.zoomBy(.8);if(e.altKey&&!t&&(e.code===`Digit0`||e.code===`Digit1`||e.code===`Digit2`)){if(e.preventDefault(),e.code===`Digit0`)return this.zoomAt(1);if(e.code===`Digit1`)return this.fit();let t=XP(this.selection().map(e=>this.outerBox(e)));return this.fit(t??void 0)}if(e.key===`Escape`){this.entered?(this.select([this.entered]),this.entered=null):this.selected.size?this.clearSelection():this.setTool(`select`);return}if(!this.editable){!t&&n===`h`&&this.setTool(`hand`),!t&&n===`v`&&this.setTool(`select`);return}if(this.activeNode&&this.mindmapKey(e))return;if(t&&n===`z`){e.preventDefault(),e.shiftKey?this.store.undo?.redo():this.store.undo?.undo();return}if(t&&n===`y`){e.preventDefault(),this.store.undo?.redo();return}if(t&&n===`a`){e.preventDefault(),this.select(this.elements().filter(e=>!e.group||!this.get(e.group)).map(e=>e.id));return}if(t&&n===`d`){e.preventDefault(),this.duplicate();return}if(t&&n===`g`){e.preventDefault(),e.shiftKey?this.ungroup():this.group();return}if((e.key===`Delete`||e.key===`Backspace`)&&this.selected.size){e.preventDefault(),this.deleteSelection();return}if(e.key===`Enter`&&this.selected.size===1){e.preventDefault();let t=[...this.selected][0];this.startEdit(t);return}if(e.key.startsWith(`Arrow`)&&this.selected.size){e.preventDefault();let t=e.shiftKey?10:1,n=e.key===`ArrowLeft`?-t:e.key===`ArrowRight`?t:0,r=e.key===`ArrowUp`?-t:e.key===`ArrowDown`?t:0;this.nudge(n,r);return}if(t||e.altKey)return;let r={v:`select`,h:`hand`,n:`note`,t:`text`,s:`shape`,c:`connector`,p:`pen`,e:`eraser`,f:`frame`,m:`mindmap`};r[n]?(e.preventDefault(),this.setTool(r[n])):n===`i`?this.ui.pickImage():n===`l`&&this.addLink()}nudge(e,t){let n=this.expanded(this.selected),r=[];for(let i of n){let n=this.get(i);if(n&&n.type!==`group`){if(n.type===`connector`){let a={};for(let r of[`source`,`target`]){let i=n[r];i.id||(a[r]={x:(i.x??0)+e,y:(i.y??0)+t})}r.push([i,a])}else r.push([i,{x:n.x+e,y:n.y+t}])}}this.store.updateMany(r)}startEdit(e,t){if(!this.editable)return;let n=this.get(e),r=this.rendered.get(e);if(n&&r){if(n.type===`group`)this.entered=e;else if(n.type===`mindmap`){let i=t??(this.activeNode?.map===e?this.activeNode.node:uI(n.nodes));if(!i)return;this.activeNode={map:e,node:i},this.editing={id:e,node:i},this.draw(r,n);let a=r.el.querySelector(`[data-node="${i}"]`);a&&this.editText(a,n.nodes[i]?.text??``,!0,t=>this.store.updateNode(e,i,{text:t}))}else if(n.type!==`image`&&n.type!==`brush`)switch(this.select([e]),this.editing={id:e,node:t},r.el.classList.add(`dw-cv-editing`),this.drawOverlay(),this.ui.refresh(),n.type){case`note`:r.note?.focus();return;case`embed`:return;case`text`:{let t=r.el.querySelector(`.dw-cv-textbody`);t&&this.editText(t,n.text,!1,t=>t.trim()?this.store.update(e,{text:t}):this.store.remove([e]));return}case`shape`:{let t=r.el.querySelector(`.dw-cv-label`);t&&this.editText(t,n.text,!1,t=>this.store.update(e,{text:t}));return}case`frame`:{let t=r.el.querySelector(`.dw-cv-frametitle`);t&&this.editText(t,n.title,!0,t=>this.store.update(e,{title:t}));return}case`connector`:{this.draw(r,n);let t=r.el.querySelector(`.dw-cv-clabel`);t&&this.editText(t,n.label,!0,t=>this.store.update(e,{label:t}));return}}}}editText(e,t,n,r){e.contentEditable=`true`,e.spellcheck=!0,e.textContent=t,e.classList.add(`dw-cv-typing`);let i=!1,a=n=>{if(i)return;i=!0,this.stopEditingFn=null,e.contentEditable=`false`,e.classList.remove(`dw-cv-typing`),e.removeEventListener(`keydown`,o),e.removeEventListener(`blur`,s),e.removeEventListener(`paste`,c);let a=(e.innerText??e.textContent??``).replace(/\n$/,``),l=this.editing?.id;if(this.editing=null,(n&&a!==t||n&&!a.trim())&&r(a),l){let e=this.rendered.get(l);e&&(e.key=``)}this.schedule(),this.ui.refresh()},o=e=>{e.stopPropagation(),e.key===`Escape`||e.key===`Enter`&&(n||e.ctrlKey||e.metaKey)&&!e.shiftKey?(e.preventDefault(),a(!0),this.root.focus({preventScroll:!0})):e.key===`Tab`&&this.activeNode&&(e.preventDefault(),a(!0),this.mindmapAdd(`child`))},s=()=>a(!0),c=e=>{e.preventDefault(),e.stopPropagation(),document.execCommand(`insertText`,!1,e.clipboardData?.getData(`text/plain`)??``)};e.addEventListener(`keydown`,o),e.addEventListener(`blur`,s),e.addEventListener(`paste`,c),this.stopEditingFn=()=>a(!0),e.focus({preventScroll:!0});let l=document.createRange();l.selectNodeContents(e);let u=getSelection();u?.removeAllRanges(),u?.addRange(l)}stopEditingFn=null;stopEditing(){let e=this.stopEditingFn;if(this.stopEditingFn=null,e?.(),this.editing){let e=this.rendered.get(this.editing.id);e?.el.classList.remove(`dw-cv-editing`),e?.note&&document.activeElement&&e.el.contains(document.activeElement)&&document.activeElement.blur(),this.editing=null,this.drawOverlay(),this.ui.refresh()}}frameName(){let e=this.elements().filter(e=>e.type===`frame`).length+1;return`${this.labels.frameTitle} ${e}`}addNote(e){let t=this.store.add({type:`note`,...this.styles.note,x:e[0]-24,y:e[1]-24,w:320,h:120});this.setTool(`select`),this.select([t]),this.render(),this.startEdit(t)}addText(e){let t=this.store.add({type:`text`,...this.styles.text,x:e[0],y:e[1]-this.styles.text.fontSize*.7,w:0,h:0,text:``});this.setTool(`select`),this.render(),this.startEdit(t)}addMindmap(e){let t=`r${Date.now().toString(36)}`,n=this.store.add({type:`mindmap`,...this.styles.mindmap,x:e[0],y:e[1],nodes:{[t]:{text:this.labels.centralIdea,parent:``,pos:0}}});this.setTool(`select`),this.select([n]),this.activeNode={map:n,node:t},this.render(),this.startEdit(n,t)}viewCentre(){let e=this.root.getBoundingClientRect();return this.toWorld(e.left+e.width/2,e.top+e.height/2)}async addImages(e,t){let n=this.opts.files?.upload;if(!n)return;let[r,i]=t??this.viewCentre(),a=[];for(let t of e)try{let e=await n.call(this.opts.files,t),o=await kR(this.opts.files?.resolve(e.url)??e.url),s=Math.min(1,480/Math.max(o.w,1)),c=o.w*s,l=o.h*s;a.push(this.store.add({type:`image`,src:e.url,alt:e.name,x:r-c/2,y:i-l/2,w:c,h:l})),r+=24,i+=24}catch(e){this.opts.onError?.(e)}a.length&&this.select(a)}async addLink(e,t){let n=(e??window.prompt(this.labels.linkPrompt,`https://`))?.trim();if(!n||!/^https?:\/\//i.test(n))return;let[r,i]=t??this.viewCentre(),a=this.opts.embedSource?.(n),o=a?560:380,s=a?a.ratio===`video`?315:420:120,c=this.store.add({type:`embed`,url:n,x:r-o/2,y:i-s/2,w:o,h:s});this.setTool(`select`),this.select([c])}insertElements(e){let t=XP(e.map(e=>({x:Number(e.x)||0,y:Number(e.y)||0,w:Number(e.w)||0,h:Number(e.h)||0})))??{x:0,y:0,w:0,h:0},[n,r]=this.viewCentre(),i=this.store.insertJSON(e,n-(t.x+t.w/2),r-(t.y+t.h/2));this.setTool(`select`),this.select(i.filter(e=>!i.includes(this.get(e)?.group??``)))}insertSticker(e){this.insertElements(GF(e))}insertTemplate(e){this.insertElements(QF(e,this.labels))}deleteSelection(){let e=[...this.selected];this.clearSelection(),this.store.remove(e)}duplicate(){let e=this.store.toJSON(this.selected);if(!e.length)return;let t=this.store.insertJSON(e,24,24);this.select(t.filter(e=>!this.get(e)?.group||!t.includes(this.get(e).group)))}group(){let e=this.store.groupOf([...this.selected]);e&&this.select([e])}ungroup(){let e=this.selection().filter(e=>e.type===`group`),t=e.flatMap(e=>this.store.ungroup(e.id));e.length&&this.select(t)}reorder(e){this.store.reorder(this.expanded(this.selected),e)}mindmapAdd(e){let t=this.activeNode,n=t?this.get(t.map):void 0;if(!t||n?.type!==`mindmap`)return;let r=n.nodes[t.node];if(!r)return;let i=e===`child`||!r.parent?t.node:r.parent,a=dI(n.nodes,i),o;if(e===`sibling`&&r.parent){let e=a.indexOf(t.node),r=n.nodes[a[e]]?.pos??0;o=(r+(a[e+1]?n.nodes[a[e+1]]?.pos??r+2:r+2))/2}else o=a.length?Math.max(...a.map(e=>n.nodes[e]?.pos??0))+1:0;let s=this.store.addNode(t.map,i,o,``);this.activeNode={map:t.map,node:s},this.render(),this.startEdit(t.map,s)}mindmapKey(e){let t=this.activeNode,n=this.get(t.map);if(n?.type!==`mindmap`||!this.selected.has(t.map))return!1;if(e.key===`Tab`)return e.preventDefault(),this.mindmapAdd(`child`),!0;if(e.key===`Enter`)return e.preventDefault(),this.mindmapAdd(`sibling`),!0;if(e.key===`F2`)return e.preventDefault(),this.startEdit(t.map,t.node),!0;if(e.key===`Delete`||e.key===`Backspace`){e.preventDefault();let r=n.nodes[t.node]?.parent;return this.store.removeNode(t.map,t.node),this.activeNode=r?{map:t.map,node:r}:null,this.schedule(),!0}if(e.key.startsWith(`Arrow`)&&!e.shiftKey){e.preventDefault();let r=pI(this.layoutOf(n),n.nodes,t.node,e.key);if(r){this.activeNode={map:t.map,node:r};let e=this.rendered.get(t.map);e&&(e.key=``),this.schedule()}return!0}return!1}owns(){let e=document.activeElement;return!!e&&(e===this.root||this.root.contains(e)&&!DR(e)&&!this.inEditor(e))}onCopy(e,t){if(!this.owns()||!this.selected.size||getSelection()?.toString())return;let n=this.store.toJSON(this.selected);e.clipboardData?.setData(`text/plain`,`docwell-canvas:${JSON.stringify(n)}`),e.preventDefault(),t&&this.editable&&this.deleteSelection()}onPaste(e){if(!this.editable||!this.owns())return;let t=[...e.clipboardData?.files??[]].filter(e=>e.type.startsWith(`image/`));if(t.length){e.preventDefault(),this.addImages(t);return}let n=e.clipboardData?.getData(`text/plain`)??``;if(!n)return;if(e.preventDefault(),n.startsWith(`docwell-canvas:`)){try{let e=JSON.parse(n.slice(15));Array.isArray(e)&&this.insertElements(e)}catch{}return}if(/^https?:\/\/\S+$/i.test(n.trim())){this.addLink(n.trim());return}let[r,i]=this.viewCentre(),a=this.store.add({type:`text`,...this.styles.text,x:r,y:i,w:n.length>60?480:0,h:0,text:n});this.select([a])}setComments(e,t=``){this.comments=e;let n=t!==this.activeComment;this.activeComment=t;let r=t?e.find(e=>e.comment===t):void 0;n&&r&&this.reveal(r.element),this.drawOverlay()}reveal(e){let t=this.get(e);if(!t)return;let n=this.outerBox(t),r=this.root.getBoundingClientRect(),[i,a]=this.toScreen([n.x,n.y]),[o,s]=this.toScreen([n.x+n.w,n.y+n.h]);if(i>=0&&a>=0&&o<=r.width&&s<=r.height)return;let c={...this.view};if(n.w*c.zoome.comment===this.activeComment);o&&e.push(``);let[s,c]=this.toScreen([a.x+a.w,a.y]),l=(o??i[0]).comment;e.push(`${UL(this.labels.comment)}${i.length}`)}}async exportImage(e,t=!1){let n=t&&this.selected.size?new Set(this.expanded(this.selected)):null,r=this.elements().filter(e=>!n||n.has(e.id));return CR(e,{root:this.root,elements:r,boxOf:e=>this.boxOf(e),routeOf:e=>this.routes.get(e.id)??this.routeOf(e),layoutOf:e=>this.layoutOf(e),noteBody:e=>e.page?this.opts.doc.getXmlFragment(`default`):this.store.body(e.id),pageTitle:this.opts.pageTitle?.()??``,resolve:e=>this.opts.files?.resolve(e)??e})}frames(){return this.elements().filter(e=>e.type===`frame`).sort((e,t)=>t.index-e.index)}present(){let e=this.frames().map(e=>e.id);if(!e.length){this.ui.toast(this.labels.presentNoFrames);return}this.stopEditing(),this.clearSelection();let t=this.ui.presentBar();this.presenting={frames:e,at:0,bar:t},this.root.classList.add(`dw-cv-presenting`),this.root.requestFullscreen?.().catch(()=>{}),requestAnimationFrame(()=>this.goTo(0))}goTo(e){let t=this.presenting;if(!t)return;t.at=Math.max(0,Math.min(t.frames.length-1,e));let n=this.get(t.frames[t.at]);if(n){let e={...this.view};this.fit(this.boxOf(n),!1,24);let t={...this.view};this.view=e,this.animateTo(t)}this.ui.presentStep(t.at,t.frames.length)}presentStep(e){this.presenting&&this.goTo(this.presenting.at+e)}stopPresenting(){let e=this.presenting;e&&(this.presenting=null,e.bar.remove(),this.root.classList.remove(`dw-cv-presenting`),document.fullscreenElement===this.root&&document.exitFullscreen().catch(()=>{}),this.drawOverlay())}get isPresenting(){return!!this.presenting}presentKey(e){[`ArrowRight`,`ArrowDown`,`PageDown`,` `,`Enter`].includes(e.key)?(e.preventDefault(),this.presentStep(1)):[`ArrowLeft`,`ArrowUp`,`PageUp`,`Backspace`].includes(e.key)?(e.preventDefault(),this.presentStep(-1)):e.key===`Escape`&&(e.preventDefault(),this.stopPresenting())}};function kR(e){return new Promise(t=>{let n=new Image;n.onload=()=>t({w:n.naturalWidth||320,h:n.naturalHeight||240}),n.onerror=()=>t({w:320,h:240}),n.src=e})}var AR={database:`Database`,untitled:`Untitled database`,untitledRow:`Untitled`,newRow:`New record`,addColumn:`Add property`,columnName:`Property name`,search:`Search records`,filter:`Filter`,sort:`Sort`,group:`Group`,properties:`Properties`,more:`More`,addView:`Add view`,viewName:`View name`,renameView:`Rename view`,duplicateView:`Duplicate view`,deleteView:`Delete view`,layout:`Layout`,viewTable:`Table`,viewKanban:`Kanban`,viewCalendar:`Calendar`,viewList:`List`,viewGallery:`Gallery`,viewTimeline:`Timeline`,viewChart:`Chart`,chartType:`Chart type`,chartBar:`Bars`,chartLine:`Line`,chartDonut:`Donut`,chartX:`Show records by`,chartMeasure:`Measure`,chartCount:`Count of records`,chartSum:`Sum of`,chartAvg:`Average of`,chartValue:`Number property`,noChartAxis:`Add a select, checkbox, member or date property to chart records by.`,noChartData:`Nothing to chart: no record has a value here.`,endColumn:`End date property`,sameDay:`Same day as the start`,scaleDay:`Days`,scaleWeek:`Weeks`,scaleMonth:`Months`,earlier:`Earlier`,later:`Later`,noStartColumn:`Add a date property to place records on the timeline.`,dragEnd:`Drag to change the end date`,cover:`Card cover`,noCover:`No cover`,noValue:`No value`,checked:`Checked`,unchecked:`Unchecked`,noRows:`No records`,noMatches:`No records match`,rename:`Rename`,type:`Type`,hide:`Hide in view`,show:`Show in view`,sortAscending:`Sort ascending`,sortDescending:`Sort descending`,filterBy:`Filter by this property`,insertLeft:`Insert left`,insertRight:`Insert right`,moveLeft:`Move left`,moveRight:`Move right`,duplicate:`Duplicate`,deleteColumn:`Delete property`,typeTitle:`Title`,typeText:`Text`,typeNumber:`Number`,typeCheckbox:`Checkbox`,typeSelect:`Select`,typeMultiSelect:`Multi-select`,typeDate:`Date`,typeProgress:`Progress`,typeLink:`Link`,typeAttachment:`Attachment`,typeMember:`Member`,typeCreatedTime:`Created time`,typeCreatedBy:`Created by`,typeRelation:`Relation`,typeRollup:`Rollup`,typeFormula:`Formula`,editFormula:`Edit formula`,formulaHelp:`Write an expression. prop("Name") reads a property; + - * / and comparisons work on numbers, + joins text. Functions: if, round, min, max, concat, length, contains, empty, today, dateAdd, dateBetween, year, month, day.`,formulaInsert:`Insert a property`,formulaPreview:`First record`,formulaError:`Error`,formulaSave:`Save formula`,linkedCount:`{n} linked`,rollupDays:`{n} days`,relationTo:`Related database`,relationPick:`Choose a database`,relationThisPage:`On this page`,relationOtherPage:`On another page…`,relationSearchPage:`Find a page`,relationNoDatabases:`No databases on that page`,relationMissing:`The related database is not available.`,relationTwoWay:`Two-way`,relationOneWay:`Links kept here`,relationMirror:`Show the links of “{n}”`,relationShowOn:`Show on “{n}” too`,relationBackReadOnly:`Change these links on the page that holds the related database.`,linkRecord:`Link a record`,searchRecords:`Search records`,noRecords:`No records`,openRelated:`Open record`,rollupSettings:`Rollup`,rollupRelation:`Relation`,rollupProperty:`Property`,rollupFn:`Calculate`,rollupRecords:`Records`,rollupNeedsRelation:`Add a relation property first.`,fnShowOriginal:`Show values`,fnCount:`Count records`,fnCountValues:`Count values`,fnCountUnique:`Count unique values`,fnCountEmpty:`Count empty`,fnCountNotEmpty:`Count not empty`,fnPercentNotEmpty:`Percent not empty`,fnSum:`Sum`,fnAverage:`Average`,fnMedian:`Median`,fnMin:`Min`,fnMax:`Max`,fnRange:`Range`,fnEarliest:`Earliest date`,fnLatest:`Latest date`,fnChecked:`Checked`,fnPercentChecked:`Percent checked`,openFullPage:`Open as full page`,backToPage:`Back to the page`,recordNotFound:`This record is not in the database any more.`,opContains:`contains`,opNotContains:`does not contain`,opIs:`is`,opIsNot:`is not`,opIsEmpty:`is empty`,opIsNotEmpty:`is not empty`,opGt:`is greater than`,opLt:`is less than`,opGte:`is at least`,opLte:`is at most`,opBefore:`is before`,opAfter:`is after`,opChecked:`is checked`,opUnchecked:`is not checked`,addFilter:`Add filter`,matchAll:`Every filter matches`,matchAny:`Any filter matches`,remove:`Remove`,value:`Value`,noFilters:`No filters yet`,addSort:`Add sort`,ascending:`Ascending`,descending:`Descending`,noSorts:`No sorts yet`,groupBy:`Group by`,noGrouping:`No grouping`,showAll:`Show all`,hideAll:`Hide all`,dateColumn:`Date property`,today:`Today`,previousMonth:`Previous month`,nextMonth:`Next month`,noDateColumn:`Add a date property to place records on the calendar.`,noDate:`No date ({n})`,noGroupColumn:`Add a select, checkbox or member property to sort cards into columns.`,openRow:`Open`,copyLink:`Copy link to record`,deleteRow:`Delete record`,duplicateRow:`Duplicate record`,insertAbove:`Insert above`,insertBelow:`Insert below`,deleteRows:`Delete`,selected:`{n} selected`,selectRow:`Select record`,dragRow:`Drag to move`,close:`Close`,expand:`Full width`,collapse:`Narrow`,previousRow:`Previous record`,nextRow:`Next record`,bodyPlaceholder:`Write about this record…`,bodyReadOnly:`This record has no notes.`,searchOptions:`Find or create a choice`,createOption:`Create “{n}”`,optionColor:`Colour`,deleteOption:`Delete choice`,renameOption:`Rename choice`,groupMenu:`Group options`,newGroup:`New group`,newGroupPlaceholder:`Name the group`,deleteGroupConfirm:`Delete the choice “{n}”? Its cards move to No value.`,searchPeople:`Find a person`,noPeople:`Nobody found`,upload:`Upload a file`,linkPlaceholder:`Paste a link`,clear:`Clear`,exportCsv:`Export as CSV`,importCsv:`Import CSV`,imported:`Added {n} records`,copyNotice:`Copied {n} cells`,readOnly:`Only people who can edit the page can change this database.`,resize:`Drag to change the width`,groupAsDatabase:`Group as database`,done:`Done`},jR={title:`typeTitle`,text:`typeText`,number:`typeNumber`,checkbox:`typeCheckbox`,select:`typeSelect`,multiSelect:`typeMultiSelect`,date:`typeDate`,progress:`typeProgress`,link:`typeLink`,attachment:`typeAttachment`,member:`typeMember`,createdTime:`typeCreatedTime`,createdBy:`typeCreatedBy`,relation:`typeRelation`,rollup:`typeRollup`,formula:`typeFormula`},MR=(e,t)=>e[jR[t]],NR={contains:`opContains`,notContains:`opNotContains`,is:`opIs`,isNot:`opIsNot`,isEmpty:`opIsEmpty`,isNotEmpty:`opIsNotEmpty`,gt:`opGt`,lt:`opLt`,gte:`opGte`,lte:`opLte`,before:`opBefore`,after:`opAfter`,checked:`opChecked`,unchecked:`opUnchecked`},PR=(e,t)=>e[NR[t]],FR={table:`viewTable`,kanban:`viewKanban`,calendar:`viewCalendar`,list:`viewList`,gallery:`viewGallery`,timeline:`viewTimeline`,chart:`viewChart`},IR=(e,t)=>e[FR[t]],LR=(e,t)=>e.replace(`{n}`,String(t)),{colors:RR,...zR}=bF,BR={slashMenu:`Insert block`,noMatches:`No matching blocks`,slash:{text:{label:`Text`,description:`Plain paragraph`},h1:{label:`Heading 1`,description:`Big section heading`},h2:{label:`Heading 2`,description:`Medium section heading`},h3:{label:`Heading 3`,description:`Small section heading`},otherHeadings:{label:`Other headings`,description:`Headings 4 to 6`},h4:{label:`Heading 4`,description:`A heading below level 3`},h5:{label:`Heading 5`,description:`A heading below level 4`},h6:{label:`Heading 6`,description:`The smallest heading`},bullet:{label:`Bulleted list`,description:`A simple list`},ordered:{label:`Numbered list`,description:`A list with numbers`},todo:{label:`To-do list`,description:`Tasks to tick off (or type [])`},callout:{label:`Callout`,description:`Set a note apart with an emoji and colour`},columns:{label:`Columns`,description:`Put blocks side by side`},columns2:{label:`2 columns`,description:`Two blocks side by side`},columns3:{label:`3 columns`,description:`Three blocks side by side`},columns4:{label:`4 columns`,description:`Four blocks side by side`},columns5:{label:`5 columns`,description:`Five blocks side by side`},table:{label:`Table`,description:`Rows and columns`},quote:{label:`Quote`,description:`Set text apart as a quote`},code:{label:`Code block`,description:`Monospaced code`},divider:{label:`Divider`,description:`A line between sections`},image:{label:`Image`,description:`Upload a picture`},file:{label:`File`,description:`Attach a file to download`},math:{label:`Math block`,description:`A formula on its own line (LaTeX)`},mathInline:{label:`Inline math`,description:`A formula inside the text (LaTeX)`},mermaid:{label:`Mermaid diagram`,description:`Flowcharts and sequences from text`},drawio:{label:`Draw.io diagram`,description:`Draw a diagram with diagrams.net`},excalidraw:{label:`Excalidraw drawing`,description:`Sketch by hand`},toc:{label:`Table of contents`,description:`The page's headings, kept up to date`},pageLink:{label:`Link to page`,description:`Link another page (or type [[)`},toggle:{label:`Toggle`,description:`A heading that hides the blocks under it`},embed:{label:`Embed`,description:`A video, design or document from YouTube, Figma and more`},linkCard:{label:`Link card`,description:`A link with its page's title and picture`},syncedPage:{label:`Synced page`,description:`Show another page here, always up to date`},database:{label:`Database`,description:`Records in a table, board or calendar`},newPage:{label:`New page`,description:`Make a page and link it here`},today:{label:`Today`,description:`Insert today's date`},tomorrow:{label:`Tomorrow`,description:`Insert tomorrow's date`},yesterday:{label:`Yesterday`,description:`Insert yesterday's date`},now:{label:`Now`,description:`Insert the date and time`},video:{label:`Video`,description:`Upload a video that plays on the page`},audio:{label:`Audio`,description:`Upload a recording that plays on the page`},pageBreak:{label:`Page break`,description:`Start a new page when printing`},footnote:{label:`Footnote`,description:`A numbered note at the end of the page`},tabs:{label:`Tabs`,description:`Content on several tabs`},status:{label:`Status`,description:`A coloured badge in the text`},emoji:{label:`Emoji`,description:`Pick an emoji (or type :)`},subpages:{label:`Subpages`,description:`List this page's subpages`},syncedBlock:{label:`Synced block`,description:`Show a block of another page, always up to date`}},format:{bold:`Bold`,italic:`Italic`,strike:`Strikethrough`,code:`Inline code`,link:`Link`,linkPrompt:`Link address (leave empty to remove the link)`,comment:`Comment`,underline:`Underline`,color:`Colour`,textColor:`Text colour`,highlight:`Highlight`,noColor:`Default`,align:`Align`,alignLeft:`Align left`,alignCenter:`Align centre`,alignRight:`Align right`,math:`Inline math`,linkedPage:`Make a linked page`},colors:{gray:`Grey`,red:`Red`,orange:`Orange`,yellow:`Yellow`,green:`Green`,teal:`Teal`,blue:`Blue`,purple:`Purple`,pink:`Pink`},table:{toolbar:`Table`,dragRow:`Drag to move the row`,dragColumn:`Drag to move the column`,moveRowUp:`Move row up`,moveRowDown:`Move row down`,moveColumnLeft:`Move column left`,moveColumnRight:`Move column right`,addRowBefore:`Add row above`,addRowAfter:`Add row below`,addColumnBefore:`Add column left`,addColumnAfter:`Add column right`,deleteRow:`Delete row`,deleteColumn:`Delete column`,toggleHeaderRow:`Header row`,mergeCells:`Merge cells`,splitCell:`Split cell`,deleteTable:`Delete table`},blockMenu:{open:`Drag to move, click for actions`,turnInto:`Turn into`,moveUp:`Move up`,moveDown:`Move down`,duplicate:`Duplicate`,copy:`Copy`,delete:`Delete`,showLineNumbers:`Show line numbers`,hideLineNumbers:`Hide line numbers`,showPages:`Show pages`,showAsFile:`Show as file`},mentions:`Mention someone`,noPeople:`Nobody found`,pageLinks:`Link to a page`,noPages:`No pages found`,blocks:{edit:`Edit`,done:`Done`,cancel:`Cancel`,save:`Save`,remove:`Remove`,saving:`Saving…`,latex:`LaTeX formula`,mermaid:`Mermaid diagram source`,mermaidError:`This diagram has an error:`,emptyDrawio:`Empty diagram. Click to draw.`,emptyExcalidraw:`Empty drawing. Click to sketch.`,loadFailed:`The editor could not be loaded.`,toc:`Contents`,tocEmpty:`Add headings to the page to fill the table of contents.`,expand:`Show contents`,collapse:`Hide contents`,embed:`Embedded content`,embedUrl:`Address of the video, design or document`,embedInvalid:`This address can't be embedded.`,syncedPage:`Synced page`,syncedOpen:`Open`,syncedFold:`Fold`,syncedUnfold:`Unfold`,syncedLoading:`Loading the page…`,syncedDenied:`You can't open this page.`,syncedSelf:`A page can't show itself.`,linkUrl:`Address of the page to link`,copyBlockLink:`Copy link to this block`,calloutEmoji:`Change emoji`,calloutColor:`Change colour`,resizeColumn:`Drag to resize the columns`,addColumn:`Add a column`,pdfLoading:`Loading PDF…`,pdfPage:`Page {n}`,transcribe:`Transcribe`,transcribeHint:`Add a summary and the transcript below, with AI`,transcribing:`Transcribing…`,transcribeFailed:`The recording could not be transcribed.`,syncedBlock:`Synced block`,syncedBlockUrl:`Link to the block (copy it from the block's ⋮⋮ menu)`,syncedBlockInvalid:`That isn't a link to a block of a page.`,syncedBlockMissing:`This block is no longer on its page.`,pageBreak:`Page break`,status:`Status`,statusDefault:`To do`,statusText:`Status text`,statusColor:`Status colour`,footnotes:`Footnotes`,footnote:`Footnote {n}`,footnoteText:`Footnote text`,footnoteBack:`Back to the text`,tabName:`Tab {n}`,addTab:`Add a tab`,renameTab:`Tab name`,deleteTab:`Delete tab`,subpages:`Subpages`,subpagesEmpty:`This page has no subpages yet.`,subpagesLoading:`Loading subpages…`,emoji:`Emoji`,noEmoji:`No emoji found`},suggest:{mode:`Suggesting`,hint:`Your edits show as suggestions until someone accepts them`,one:`1 suggestion`,count:`{n} suggestions`,accept:`Accept`,reject:`Reject`,acceptAll:`Accept all`,rejectAll:`Reject all`,adds:`Adds`,removes:`Removes`},find:{find:`Find in page`,replace:`Replace with`,previous:`Previous match`,next:`Next match`,replaceOne:`Replace`,replaceAll:`Replace all`,matchCase:`Match case`,close:`Close`,count:`{current} of {total}`,none:`No matches`},ai:{button:`Ask AI`,rewrite:`Improve writing`,summarize:`Summarise`,translate:`Translate`,continue:`Continue writing`,shorter:`Make shorter`,longer:`Make longer`,fix:`Fix spelling and grammar`,custom:`Ask AI to…`,customPlaceholder:`Tell AI what to do with the selection`,language:`Language`,run:`Go`,working:`Writing…`,replace:`Replace selection`,insertBelow:`Insert below`,discard:`Discard`,stop:`Stop`,retry:`Try again`,failed:`AI could not finish this.`},dates:{today:`Today`,tomorrow:`Tomorrow`,yesterday:`Yesterday`,nextWeek:`Next week`,remindWord:`remind`,remindMe:`Remind me`,reminderAt:`Reminder at 9:00 on the day`,someoneElse:`Someone else set a reminder on this date.`,edit:`Change date`,openJournal:`Open journal`},database:AR,edgeless:zR},VR=[`title`,`text`,`number`,`checkbox`,`select`,`multiSelect`,`date`,`progress`,`link`,`attachment`,`member`,`createdTime`,`createdBy`,`relation`,`rollup`,`formula`],HR=VR.filter(e=>e!==`title`),UR=[`table`,`kanban`,`calendar`,`list`,`gallery`,`timeline`,`chart`],WR=[`bar`,`line`,`donut`],GR=[`count`,`sum`,`avg`],KR=[`day`,`week`,`month`];function qR(){let e=new Uint8Array(6);return crypto.getRandomValues(e),[...e].map(e=>e.toString(36).padStart(2,`0`)).join(``).slice(0,10)}function JR(e,t,n){let r=n.find(e=>QR.includes(e.type)),i=n.find(e=>e.type===`date`||e.type===`createdTime`),a=n.filter(e=>e.type===`date`);return{id:qR(),name:t,type:e,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:e===`kanban`?r?.id??null:null,dateColumn:e===`calendar`||e===`timeline`?i?.id??null:null,cover:e===`gallery`?n.find(e=>e.type===`attachment`)?.id??null:null,endColumn:e===`timeline`?a.find(e=>e.id!==i?.id)?.id??null:null,scale:`week`,chart:{type:`bar`,x:e===`chart`?n.find(e=>YR.includes(e.type))?.id??null:null,op:`count`,y:null},widths:{}}}var YR=[`select`,`multiSelect`,`checkbox`,`member`,`createdBy`,`date`,`createdTime`],XR=[`number`,`progress`,`rollup`,`formula`];function ZR(e,t){let n=nz(e)?e:{};return{type:WR.includes(String(n.type))?n.type:`bar`,x:typeof n.x==`string`&&t.has(n.x)?n.x:null,op:GR.includes(String(n.op))?n.op:`count`,y:typeof n.y==`string`&&t.has(n.y)?n.y:null}}var QR=[`select`,`multiSelect`,`checkbox`,`member`,`createdBy`];function $R(e){let t=nz(e)?e:{},n=(Array.isArray(t.columns)?t.columns:[]).flatMap(e=>{if(!nz(e)||typeof e.id!=`string`||!e.id)return[];let t=VR.includes(String(e.type))?e.type:`text`,n={id:e.id,name:typeof e.name==`string`?e.name:``,type:t};Array.isArray(e.options)&&(n.options=e.options.flatMap(ez));let r=t===`relation`?Pz(e.relation):void 0;r&&(n.relation=r);let i=t===`rollup`?Fz(e.rollup):void 0;return i&&(n.rollup=i),t===`formula`&&(n.formula=typeof e.formula==`string`?e.formula:``),[n]});n.some(e=>e.type===`title`)||n.unshift({id:qR(),name:``,type:`title`});let r=(Array.isArray(t.rows)?t.rows:[]).flatMap(e=>{if(!nz(e)||typeof e.id!=`string`||!e.id)return[];let t={id:e.id,cells:nz(e.cells)?{...e.cells}:{},createdAt:typeof e.createdAt==`number`?e.createdAt:0,createdBy:tz(e.createdBy)};return Array.isArray(e.body)&&e.body.length&&(t.body=e.body,t.hasBody=!0),[t]}),i=new Set(n.map(e=>e.id)),a=(Array.isArray(t.views)?t.views:[]).flatMap(e=>{if(!nz(e)||typeof e.id!=`string`||!e.id)return[];let t=UR.includes(String(e.type))?e.type:`table`;return[{id:e.id,name:typeof e.name==`string`?e.name:``,type:t,hidden:Array.isArray(e.hidden)?e.hidden.filter(e=>typeof e==`string`):[],filters:Array.isArray(e.filters)?e.filters.filter(e=>nz(e)&&typeof e.column==`string`&&typeof e.op==`string`):[],filterMode:e.filterMode===`or`?`or`:`and`,sorts:Array.isArray(e.sorts)?e.sorts.flatMap(e=>nz(e)&&typeof e.column==`string`?[{column:e.column,desc:!!e.desc}]:[]):[],groupBy:typeof e.groupBy==`string`&&i.has(e.groupBy)?e.groupBy:null,dateColumn:typeof e.dateColumn==`string`&&i.has(e.dateColumn)?e.dateColumn:null,cover:typeof e.cover==`string`&&i.has(e.cover)?e.cover:null,endColumn:typeof e.endColumn==`string`&&i.has(e.endColumn)?e.endColumn:null,scale:KR.includes(String(e.scale))?e.scale:`week`,chart:ZR(e.chart,i),widths:nz(e.widths)?Object.fromEntries(Object.entries(e.widths).filter(e=>typeof e[1]==`number`)):{}}]});return{title:typeof t.title==`string`?t.title:``,columns:n,rows:r,views:a}}function ez(e){return!nz(e)||typeof e.id!=`string`?[]:[{id:e.id,name:typeof e.name==`string`?e.name:``,color:FP(e.color)?e.color:`gray`}]}function tz(e){return nz(e)&&typeof e.id==`string`?{id:e.id,name:typeof e.name==`string`?e.name:``}:null}function nz(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rz(e){return e.columns.find(e=>e.type===`title`)??e.columns[0]}function iz(e,t){return t.type===`createdTime`?e.createdAt||null:t.type===`createdBy`?e.createdBy?[e.createdBy]:[]:t.type===`rollup`||t.type===`formula`?e.computed?.[t.id]?.value??null:t.type===`relation`&&t.relation?.back?e.computed?.[t.id]?.value??[]:e.cells[t.id]}function az(e){return e==null||e===``||e===!1||Array.isArray(e)&&e.length===0}function oz(e){return typeof e==`number`&&e>0?sz(new Date(e)):typeof e==`string`&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):``}function sz(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function cz(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e.trim().replace(`,`,`.`));return Number.isFinite(t)?t:null}return null}function lz(e){return Array.isArray(e)?e:[]}function uz(e,t){let n=iz(e,t);switch(t.type){case`title`:case`text`:case`link`:return typeof n==`string`?n:``;case`number`:case`progress`:{let e=cz(n);return e===null?``:String(e)}case`checkbox`:return n===!0?`true`:`false`;case`select`:return t.options?.find(e=>e.id===n)?.name??``;case`multiSelect`:return lz(n).map(e=>t.options?.find(t=>t.id===e)?.name).filter(e=>!!e).join(`, `);case`date`:case`createdTime`:return oz(n);case`attachment`:return lz(n).map(e=>e?.name??``).join(`, `);case`member`:case`createdBy`:return lz(n).map(e=>e?.name??``).join(`, `);case`relation`:case`rollup`:case`formula`:return e.computed?.[t.id]?.text??``}}function dz(e){switch(e){case`number`:case`progress`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`isEmpty`,`isNotEmpty`];case`checkbox`:return[`checked`,`unchecked`];case`select`:return[`is`,`isNot`,`isEmpty`,`isNotEmpty`];case`multiSelect`:case`member`:case`createdBy`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`date`:case`createdTime`:return[`is`,`before`,`after`,`isEmpty`,`isNotEmpty`];case`attachment`:return[`isEmpty`,`isNotEmpty`];case`relation`:return[`contains`,`notContains`,`isEmpty`,`isNotEmpty`];case`rollup`:case`formula`:return[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`,`contains`,`isEmpty`,`isNotEmpty`];default:return[`contains`,`notContains`,`is`,`isNot`,`isEmpty`,`isNotEmpty`]}}var fz=e=>![`isEmpty`,`isNotEmpty`,`checked`,`unchecked`].includes(e);function pz(e,t,n){let r=iz(e,t);if(t.type===`relation`){let e=Lz(r).length===0;if(n.op===`isEmpty`)return e;if(n.op===`isNotEmpty`)return!e}if(n.op===`isEmpty`)return az(r)||uz(e,t)===``;if(n.op===`isNotEmpty`)return!(az(r)||uz(e,t)===``);if(n.op===`checked`)return r===!0;if(n.op===`unchecked`)return r!==!0;if(n.value===void 0||n.value===null||n.value===``)return!0;switch((t.type===`rollup`||t.type===`formula`)&&(typeof r==`number`||r===null)&&[`is`,`isNot`,`gt`,`lt`,`gte`,`lte`].includes(n.op)?`number`:t.type){case`number`:case`progress`:{let e=cz(r),t=cz(n.value);return t===null?!0:e===null?n.op===`isNot`:{is:e===t,isNot:e!==t,gt:e>t,lt:e=t,lte:e<=t}[n.op]}case`select`:return n.op===`is`?r===n.value:r!==n.value;case`multiSelect`:{let e=lz(r).includes(String(n.value));return n.op===`notContains`?!e:e}case`member`:case`createdBy`:{let e=String(n.value).toLowerCase(),t=lz(r).some(t=>t?.id===n.value||t?.name?.toLowerCase().includes(e));return n.op===`notContains`?!t:t}case`date`:case`createdTime`:{let e=oz(r),t=oz(n.value);return e?n.op===`before`?et:e===t:!1}default:{let r=uz(e,t).toLowerCase(),i=String(n.value).toLowerCase();switch(n.op){case`contains`:return r.includes(i);case`notContains`:return!r.includes(i);case`is`:return r===i;case`isNot`:return r!==i;default:return!0}}}}function mz(e,t,n){let r=uz(e,n)===``&&n.type!==`checkbox`,i=uz(t,n)===``&&n.type!==`checkbox`;if(r||i)return r===i?0:r?1:-1;switch(n.type){case`number`:case`progress`:return(cz(iz(e,n))??0)-(cz(iz(t,n))??0);case`checkbox`:return Number(iz(e,n)===!0)-Number(iz(t,n)===!0);case`createdTime`:return e.createdAt-t.createdAt;case`rollup`:case`formula`:{let r=iz(e,n),i=iz(t,n);return typeof r==`number`&&typeof i==`number`?r-i:typeof r==`boolean`&&typeof i==`boolean`?Number(r)-Number(i):uz(e,n).localeCompare(uz(t,n),void 0,{numeric:!0,sensitivity:`base`})}case`select`:{let r=e=>n.options?.findIndex(t=>t.id===iz(e,n))??-1;return r(e)-r(t)}default:return uz(e,n).localeCompare(uz(t,n),void 0,{numeric:!0,sensitivity:`base`})}}function hz(e,t,n=``){let r=new Map(e.columns.map(e=>[e.id,e])),i=t.filters.flatMap(e=>{let t=r.get(e.column);return t?[{f:e,col:t}]:[]}),a=n.trim().toLowerCase(),o=e.rows.filter(n=>{if(i.length){let e=({f:e,col:t})=>pz(n,t,e);if(t.filterMode===`or`?!i.some(e):!i.every(e))return!1}return!a||e.columns.some(e=>uz(n,e).toLowerCase().includes(a))}),s=t.sorts.flatMap(e=>{let t=r.get(e.column);return t?[{col:t,desc:e.desc}]:[]});return s.length&&(o=o.map((e,t)=>({r:e,i:t})).sort((e,t)=>{for(let n of s){let r=mz(e.r,t.r,n.col);if(r!==0){let i=uz(e.r,n.col)===``||uz(t.r,n.col)===``;return n.desc&&!(i&&n.col.type!==`checkbox`)?-r:r}}return e.i-t.i}).map(e=>e.r)),o}function gz(e,t){return e.columns.filter(e=>e.type===`title`||!t.hidden.includes(e.id))}function _z(e,t,n,r,i){let a=new Map,o=(e,t,n)=>(a.has(e)||a.set(e,{key:e,label:t,color:n,rows:[]}),a.get(e));if(t.type===`checkbox`)o(`false`,i),o(`true`,r);else{o(``,n);for(let e of t.options??[])o(e.id,e.name,e.color)}for(let n of e)for(let e of yz(n,t))(a.get(e)??o(e,vz(n,t,e)||e)).rows.push(n);return[...a.values()]}function vz(e,t,n){return lz(iz(e,t)).find(e=>e?.id===n)?.name??``}function yz(e,t){let n=iz(e,t);switch(t.type){case`checkbox`:return[n===!0?`true`:`false`];case`select`:return[typeof n==`string`&&t.options?.some(e=>e.id===n)?n:``];case`multiSelect`:{let e=lz(n).filter(e=>t.options?.some(t=>t.id===e));return e.length?e:[``]}case`member`:case`createdBy`:{let e=lz(n).flatMap(e=>e?.id?[e.id]:[]);return e.length?e:[``]}default:return[``]}}function bz(e,t,n,r,i=[]){let a=iz(e,t);switch(t.type){case`checkbox`:return r===`true`;case`select`:return r||null;case`multiSelect`:{let e=lz(a).filter(e=>e!==n&&e!==r);return r?[...e,r]:e}case`member`:{let e=lz(a).filter(e=>e?.id!==n&&e?.id!==r),t=i.find(e=>e.id===r)??lz(a).find(e=>e?.id===r);return r&&t?[...e,t]:e}default:return a}}function xz(e){let t=PP.filter(e=>e!==`gray`);return t[e.length%t.length]}function Sz(e,t,n,r){if(t.type===n)return{value:e,options:r};let i=uz({id:``,cells:{[t.id]:e},createdAt:0,createdBy:null},t),a=e=>{let t=e.trim();if(!t)return null;let n=r.find(e=>e.name.toLowerCase()===t.toLowerCase());return n||(n={id:qR(),name:t,color:xz(r)},r=[...r,n]),n.id};switch(n){case`title`:case`text`:case`link`:return{value:i||null,options:r};case`number`:return{value:cz(i),options:r};case`progress`:{let e=cz(i);return{value:e===null?null:Math.max(0,Math.min(100,Math.round(e))),options:r}}case`checkbox`:return{value:[`true`,`yes`,`1`,`x`,`✓`,`done`].includes(i.trim().toLowerCase()),options:r};case`select`:return{value:a(i.split(`,`)[0]??``),options:r};case`multiSelect`:{let e=i.split(`,`).flatMap(e=>{let t=a(e);return t?[t]:[]});return{value:[...new Set(e)],options:r}}case`date`:return{value:oz(i)||null,options:r};case`member`:return{value:t.type===`member`||t.type===`createdBy`?e:[],options:r};default:return{value:null,options:r}}}function Cz(e,t,n=1){let r=(new Date(e,t,1).getDay()-n+7)%7,i=new Date(e,t,1-r),a=new Date(e,t+1,0).getDate(),o=Math.ceil((r+a)/7);return Array.from({length:o*7},(e,t)=>sz(new Date(i.getFullYear(),i.getMonth(),i.getDate()+t)))}function wz(e){if(!Array.isArray(e))return``;for(let t of e)if(t&&typeof t.src==`string`&&t.src&&(typeof t.mime==`string`?t.mime.startsWith(`image/`):/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(t.name??t.src)))return t.src;return``}function Tz(e,t){return Math.round((Date.UTC(+t.slice(0,4),t.slice(5,7)-1,+t.slice(8,10))-Date.UTC(+e.slice(0,4),e.slice(5,7)-1,+e.slice(8,10)))/864e5)}function Ez(e,t){return new Date(Date.UTC(+e.slice(0,4),e.slice(5,7)-1,+e.slice(8,10)+t)).toISOString().slice(0,10)}function Dz(e,t,n){let r=oz(iz(e,t));if(!r)return null;let i=n?oz(iz(e,n)):``;return{from:r,to:i&&i>=r?i:r}}var Oz={day:{px:44,days:28,step:7},week:{px:20,days:70,step:28},month:{px:6,days:240,step:90}};function kz(e,t){let n=Ez(e,-(t===`day`?3:t===`week`?14:30));return Ez(n,-((new Date(`${n}T12:00:00Z`).getUTCDay()+6)%7))}function Az(e,t,n,r,i,a){let o=e.columns.find(e=>e.id===t.x&&YR.includes(e.type));if(!o)return null;let s=t.op===`count`?void 0:e.columns.find(e=>e.id===t.y&&XR.includes(e.type)),c=e=>{if(!s)return e.length;let n=e.flatMap(e=>{let t=cz(iz(e,s));return t===null?[]:[t]}),r=n.reduce((e,t)=>e+t,0),i=t.op===`avg`?n.length?r/n.length:0:r;return Math.round(i*100)/100};if(o.type===`date`||o.type===`createdTime`){let e=new Map;for(let t of n){let n=oz(iz(t,o));n&&e.set(n.slice(0,7),[...e.get(n.slice(0,7))??[],t])}return[...e.keys()].sort().map(t=>{let n=e.get(t);return{key:t,label:t,value:c(n),count:n.length}})}return _z(n,o,r,i,a).filter(e=>e.rows.length||e.key!==``&&o.type!==`member`&&o.type!==`createdBy`).map(e=>({key:e.key,label:e.label,color:e.color,value:c(e.rows),count:e.rows.length}))}function jz(e){if(e<=0)return 1;let t=10**Math.floor(Math.log10(e));for(let n of[1,2,5,10])if(n*t>=e)return n*t;return 10*t}var Mz=e=>e.type===`relation`&&!!e.relation?.back,Nz=[`showOriginal`,`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`,`sum`,`average`,`median`,`min`,`max`,`range`,`earliest`,`latest`,`checked`,`percentChecked`];function Pz(e){if(!nz(e)||typeof e.database!=`string`||!e.database)return;let t={page:typeof e.page==`string`?e.page:``,database:e.database};return typeof e.back==`string`&&e.back&&(t.back=e.back),t}function Fz(e){if(!nz(e)||typeof e.relation!=`string`)return;let t=Nz.includes(String(e.fn))?e.fn:`count`;return{relation:e.relation,property:typeof e.property==`string`?e.property:``,fn:t}}function Iz(e){let t=[`count`,`countValues`,`countUnique`,`countEmpty`,`countNotEmpty`,`percentNotEmpty`];switch(e){case`number`:case`progress`:return[`sum`,`average`,`median`,`min`,`max`,`range`,...t,`showOriginal`];case`date`:case`createdTime`:return[`earliest`,`latest`,`range`,...t,`showOriginal`];case`checkbox`:return[`checked`,`percentChecked`,`count`,`showOriginal`];default:return[`showOriginal`,...t]}}var Lz=e=>lz(e).filter(e=>typeof e==`string`&&!!e);function Rz(e,t,n){let r=t.relation?.back;return r?n?n.rows.filter(t=>Lz(t.cells[r]).includes(e.id)).map(e=>e.id):[]:Lz(e.cells[t.id])}var zz=e=>String(Number.isInteger(e)?e:Math.round(e*100)/100),Bz=(e,t)=>Math.round((Date.parse(t)-Date.parse(e))/864e5);function Vz(e,t,n,r){let i=t.map(e=>n?iz(e,n):e.id),a=t.map(e=>n?uz(e,n):``),o=a.filter((e,t)=>n?.type===`checkbox`?i[t]===!0:e!==``),s=n?i.map(cz).filter(e=>e!==null):[],c=n?i.map(oz).filter(Boolean).sort():[],l=e=>({text:e===null?``:zz(e),value:e});switch(e){case`count`:return l(t.length);case`countValues`:return l(o.length);case`countUnique`:return l(new Set(o).size);case`countEmpty`:return l(t.length-o.length);case`countNotEmpty`:return l(o.length);case`percentNotEmpty`:return t.length?{text:`${zz(o.length/t.length*100)}%`,value:o.length/t.length*100}:l(null);case`sum`:return l(s.length?s.reduce((e,t)=>e+t,0):null);case`average`:return l(s.length?s.reduce((e,t)=>e+t,0)/s.length:null);case`median`:{if(!s.length)return l(null);let e=[...s].sort((e,t)=>e-t),t=Math.floor(e.length/2);return l(e.length%2?e[t]:(e[t-1]+e[t])/2)}case`min`:return l(s.length?Math.min(...s):null);case`max`:return l(s.length?Math.max(...s):null);case`range`:if(n&&(n.type===`date`||n.type===`createdTime`)){if(!c.length)return l(null);let e=Bz(c[0],c[c.length-1]);return{text:r.rollupDays.replace(`{n}`,String(e)),value:e}}return l(s.length?Math.max(...s)-Math.min(...s):null);case`earliest`:return{text:c[0]??``,value:c[0]??null};case`latest`:return{text:c[c.length-1]??``,value:c[c.length-1]??null};case`checked`:return l(i.filter(e=>e===!0).length);case`percentChecked`:return t.length?{text:`${zz(i.filter(e=>e===!0).length/t.length*100)}%`,value:i.filter(e=>e===!0).length/t.length*100}:l(null);case`showOriginal`:{let e=a.filter(Boolean);return{text:e.join(`, `),value:e}}}}function Hz(e,t,n){let r=e.columns.filter(e=>e.type===`relation`&&e.relation),i=e.columns.filter(e=>e.type===`rollup`&&e.rollup);if(!r.length&&!i.length)return e;let a=new Map;for(let e of r)a.set(e.id,t(e.relation));let o=e.rows.map(e=>{let t={};for(let i of r){let r=a.get(i.id),o=Rz(e,i,r);if(!r){t[i.id]={text:o.length?n.linkedCount.replace(`{n}`,String(o.length)):``,value:o};continue}let s=r.columns.find(e=>e.type===`title`),c=new Map(r.rows.map(e=>[e.id,e])),l=o.flatMap(e=>{let t=c.get(e);return t?[{id:e,title:s?uz(t,s):``}]:[]});t[i.id]={text:l.map(e=>e.title).join(`, `),value:o,links:l}}for(let o of i){let i=o.rollup,s=r.find(e=>e.id===i.relation),c=s?a.get(s.id):null;if(!s||!c){t[o.id]={text:``,value:null};continue}let l=new Map(c.rows.map(e=>[e.id,e])),u=Rz(e,s,c).flatMap(e=>{let t=l.get(e);return t?[t]:[]}),d=i.property?c.columns.find(e=>e.id===i.property)??null:c.columns.find(e=>e.type===`title`)??null;t[o.id]=Vz(i.fn,u,d,n)}return{...e,computed:t}});return{...e,rows:o}}var Uz=class extends Error{},Wz=2e3,Gz=64;function Kz(e){let t=[],n=0;for(;n=e.length)throw new Uz(`Text starting at ${n+1} has no closing quote`);t.push({t:`str`,v:r,at:n}),n=i+1;continue}if(/[A-Za-z_]/.test(r)){let r=/^[A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(n));t.push({t:`id`,v:r[0],at:n}),n+=r[0].length;continue}let i=e.slice(n,n+2);if([`<=`,`>=`,`==`,`!=`,`&&`,`||`].includes(i))t.push({t:`op`,v:i,at:n}),n+=2;else if(`+-*/%<>(),!`.includes(r))t.push({t:`op`,v:r,at:n}),n++;else throw new Uz(`Unexpected "${r}" at ${n+1}`)}return t.push({t:`end`,v:``,at:e.length}),t}function qz(e){if(e.length>Wz)throw new Uz(`A formula can have at most ${Wz} characters`);if(!e.trim())throw new Uz(`The formula is empty`);let t=Kz(e),n=0,r=0,i=()=>t[n],a=(...e)=>i().t===`op`&&e.includes(i().v),o=(...e)=>i().t===`id`&&e.includes(i().v.toLowerCase()),s=e=>{if(!a(e))throw new Uz(`Expected "${e}" at ${i().at+1}`);n++},c=()=>{if(++r>Gz)throw new Uz(`The formula is nested too deeply`)},l=(e,t)=>{let n=e();for(let r=t();r;r=t())n={k:`bin`,op:r,a:n,b:e()};return n},u=()=>l(d,()=>a(`||`)||o(`or`)?(n++,`or`):null),d=()=>l(f,()=>a(`&&`)||o(`and`)?(n++,`and`):null),f=()=>l(p,()=>a(`==`,`!=`)?t[n++].v:null),p=()=>l(m,()=>a(`<`,`<=`,`>`,`>=`)?t[n++].v:null),m=()=>l(h,()=>a(`+`,`-`)?t[n++].v:null),h=()=>l(g,()=>a(`*`,`/`,`%`)?t[n++].v:null),g=()=>{if(a(`-`)){n++,c();let e=g();return r--,{k:`un`,op:`-`,a:e}}if(a(`!`)||o(`not`)){n++,c();let e=g();return r--,{k:`un`,op:`not`,a:e}}return _()},_=()=>{let e=i();if(e.t===`num`)return n++,{k:`num`,v:Number(e.v)};if(e.t===`str`)return n++,{k:`str`,v:e.v};if(a(`(`)){n++,c();let e=u();return r--,s(`)`),e}if(e.t===`id`){n++;let t=e.v.toLowerCase();if(t===`true`||t===`false`)return{k:`bool`,v:t===`true`};if(!a(`(`))throw new Uz(`Unknown name "${e.v}" at ${e.at+1}; write prop("${e.v}") for a property`);n++,c();let i=[];if(!a(`)`))for(i.push(u());a(`,`);)n++,i.push(u());if(r--,s(`)`),t===`prop`){if(i.length!==1||i[0].k!==`str`)throw new Uz(`prop() takes a property name in quotes, at ${e.at+1}`);return{k:`prop`,name:i[0].v}}let o=Jz[t];if(!o)throw new Uz(`Unknown function "${e.v}" at ${e.at+1}`);if(i.lengtho[1])throw new Uz(`${e.v}() takes ${o[0]===o[1]?o[0]:`${o[0]} to ${o[1]===1/0?`any number of`:o[1]}`} arguments`);return{k:`call`,fn:t,args:i}}throw new Uz(e.t===`end`?`The formula ends too early`:`Unexpected "${e.v}" at ${e.at+1}`)},v=u();if(i().t!==`end`)throw new Uz(`Unexpected "${i().v}" at ${i().at+1}`);return v}var Jz={if:[3,3],abs:[1,1],round:[1,2],floor:[1,1],ceil:[1,1],min:[1,1/0],max:[1,1/0],length:[1,1],lower:[1,1],upper:[1,1],contains:[2,2],concat:[1,1/0],empty:[1,1],tonumber:[1,1],format:[1,1],today:[0,0],now:[0,0],dateadd:[3,3],datebetween:[3,3],year:[1,1],month:[1,1],day:[1,1]},Yz=e=>typeof e==`object`&&!!e;function Xz(e){return e===null?``:typeof e==`number`?Number.isFinite(e)?String(Math.round(e*1e10)/1e10):``:typeof e==`boolean`?e?`true`:`false`:Yz(e)?e.day:e}function Zz(e,t){if(typeof e==`number`)return e;if(e===null||e===``)return 0;if(typeof e==`boolean`)return+!!e;if(typeof e==`string`){let t=Number(e.trim().replace(`,`,`.`));if(Number.isFinite(t))return t}throw new Uz(`${t} needs a number, not "${Xz(e)}"`)}function Qz(e,t){if(Yz(e))return e.day;if(typeof e==`string`&&/^\d{4}-\d{2}-\d{2}$/.test(e))return e;throw new Uz(`${t} needs a date`)}var $z=e=>typeof e==`boolean`?e:typeof e==`number`?e!==0:Yz(e)?!0:!!e;function eB(e){return Date.UTC(+e.slice(0,4),e.slice(5,7)-1,+e.slice(8,10))}function tB(e,t,n){let r=+e.slice(0,4),i=e.slice(5,7)-1,a=+e.slice(8,10),o=Math.trunc(t),s;switch(n){case`days`:s=new Date(Date.UTC(r,i,a+o));break;case`weeks`:s=new Date(Date.UTC(r,i,a+o*7));break;case`months`:case`years`:{let e=n===`years`?o*12:o,t=new Date(Date.UTC(r,i+e+1,0)).getUTCDate();s=new Date(Date.UTC(r,i+e,Math.min(a,t)));break}default:throw new Uz(`Unknown unit "${n}"; use days, weeks, months or years`)}return s.toISOString().slice(0,10)}function nB(e,t,n){let r=Math.round((eB(e)-eB(t))/864e5);switch(n){case`days`:return r;case`weeks`:return Math.trunc(r/7);case`months`:case`years`:{let r=(+e.slice(0,4)-t.slice(0,4))*12+(+e.slice(5,7)-t.slice(5,7));return r>0&&+e.slice(8,10)<+t.slice(8,10)&&r--,r<0&&+e.slice(8,10)>+t.slice(8,10)&&r++,n===`years`?Math.trunc(r/12):r}default:throw new Uz(`Unknown unit "${n}"; use days, weeks, months or years`)}}function rB(e,t){if(Yz(e)||Yz(t))return Xz(e)===Xz(t);if(typeof e==`number`||typeof t==`number`){if(e===null||t===null)return e===t;try{return Zz(e,`==`)===Zz(t,`==`)}catch{return!1}}return(e??``)===(t??``)}function iB(e,t){return Yz(e)||Yz(t)?Xz(e).localeCompare(Xz(t)):typeof e==`string`&&typeof t==`string`?e.localeCompare(t):Zz(e,`Comparing`)-Zz(t,`Comparing`)}function aB(e,t){let n=e=>aB(e,t);switch(e.k){case`num`:return e.v;case`str`:return e.v;case`bool`:return e.v;case`prop`:return t.prop(e.name);case`un`:{let t=n(e.a);return e.op===`-`?-Zz(t,`-`):!$z(t)}case`bin`:{if(e.op===`and`)return $z(n(e.a))&&$z(n(e.b));if(e.op===`or`)return $z(n(e.a))||$z(n(e.b));let t=n(e.a),r=n(e.b);switch(e.op){case`+`:return typeof t==`string`||typeof r==`string`||typeof t==`boolean`||typeof r==`boolean`?Yz(t)&&typeof r==`number`?{day:tB(t.day,r,`days`)}:Xz(t)+Xz(r):Yz(t)?{day:tB(t.day,Zz(r,`+`),`days`)}:Yz(r)?{day:tB(r.day,Zz(t,`+`),`days`)}:Zz(t,`+`)+Zz(r,`+`);case`-`:return Yz(t)&&Yz(r)?nB(t.day,r.day,`days`):Yz(t)?{day:tB(t.day,-Zz(r,`-`),`days`)}:Zz(t,`-`)-Zz(r,`-`);case`*`:return Zz(t,`*`)*Zz(r,`*`);case`/`:{let e=Zz(r,`/`);if(e===0)throw new Uz(`Division by zero`);return Zz(t,`/`)/e}case`%`:{let e=Zz(r,`%`);if(e===0)throw new Uz(`Division by zero`);return Zz(t,`%`)%e}case`==`:return rB(t,r);case`!=`:return!rB(t,r);case`<`:return iB(t,r)<0;case`<=`:return iB(t,r)<=0;case`>`:return iB(t,r)>0;case`>=`:return iB(t,r)>=0}throw new Uz(`Unknown operator ${e.op}`)}case`call`:return oB(e.fn,e.args,n,t)}}function oB(e,t,n,r){if(e===`if`)return $z(n(t[0]))?n(t[1]):n(t[2]);let i=t.map(n),a=e=>Xz(e);switch(e){case`abs`:return Math.abs(Zz(i[0],`abs`));case`round`:{let e=i.length>1?Math.trunc(Zz(i[1],`round`)):0,t=10**Math.min(Math.max(e,0),10);return Math.round(Zz(i[0],`round`)*t)/t}case`floor`:return Math.floor(Zz(i[0],`floor`));case`ceil`:return Math.ceil(Zz(i[0],`ceil`));case`min`:return Math.min(...i.map(e=>Zz(e,`min`)));case`max`:return Math.max(...i.map(e=>Zz(e,`max`)));case`length`:return[...a(i[0])].length;case`lower`:return a(i[0]).toLowerCase();case`upper`:return a(i[0]).toUpperCase();case`contains`:return a(i[0]).toLowerCase().includes(a(i[1]).toLowerCase());case`concat`:return i.map(a).join(``);case`empty`:return i[0]===null||a(i[0])===``;case`tonumber`:try{return Zz(i[0],`toNumber`)}catch{return null}case`format`:return a(i[0]);case`today`:return{day:r.today};case`now`:return r.now;case`dateadd`:return{day:tB(Qz(i[0],`dateAdd`),Zz(i[1],`dateAdd`),a(i[2]))};case`datebetween`:return nB(Qz(i[0],`dateBetween`),Qz(i[1],`dateBetween`),a(i[2]));case`year`:return+Qz(i[0],`year`).slice(0,4);case`month`:return+Qz(i[0],`month`).slice(5,7);case`day`:return+Qz(i[0],`day`).slice(8,10)}throw new Uz(`Unknown function "${e}"`)}function sB(e,t,n){switch(t.type){case`number`:case`progress`:{let n=e.cells[t.id];return typeof n==`number`&&Number.isFinite(n)?n:null}case`checkbox`:return e.cells[t.id]===!0;case`date`:case`createdTime`:{let n=oz(t.type===`createdTime`?e.createdAt:e.cells[t.id]);return n?{day:n}:null}case`rollup`:{let n=e.computed?.[t.id]?.value;return typeof n==`number`?n:uz(e,t)||null}case`formula`:return n(t);default:return uz(e,t)||null}}function cB(e=new Date){let t=e=>String(e).padStart(2,`0`),n=`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`;return{today:n,now:`${n} ${t(e.getHours())}:${t(e.getMinutes())}`}}function lB(e,t=cB()){let n=e.columns.filter(e=>e.type===`formula`);if(!n.length)return e;let r=new Map;for(let e of n)try{r.set(e.id,qz(e.formula??``))}catch(t){r.set(e.id,t instanceof Uz?t:new Uz(String(t)))}let i=t=>e.columns.find(e=>e.name===t)??e.columns.find(e=>e.name.toLowerCase()===t.toLowerCase()),a=e.rows.map(e=>{let a=new Map,o=new Set,s=n=>{let c=a.get(n.id);if(c)return c;if(o.has(n.id))throw new Uz(`"${n.name}" refers to itself through other formulas`);let l=r.get(n.id),u;if(l instanceof Uz)u={value:null,error:l.message};else{o.add(n.id);try{let n=aB(l,{...t,prop:t=>{let n=i(t);if(!n)throw new Uz(`No property called "${t}"`);return sB(e,n,e=>{let t=s(e);if(t.error)throw new Uz(t.error.startsWith(`"${e.name}"`)?t.error:`"${e.name}" has an error`);return t.value})}});u={value:typeof n==`number`&&!Number.isFinite(n)?null:n}}catch(e){u={value:null,error:e instanceof Uz?e.message:String(e)}}finally{o.delete(n.id)}}return a.set(n.id,u),u},c={...e.computed};for(let e of n){let t;try{t=s(e)}catch(e){t={value:null,error:e instanceof Error?e.message:String(e)}}let n=t.value;c[e.id]={text:t.error?``:Xz(n),value:Yz(n)?n.day:n,...t.error?{error:t.error}:{}}}return{...e,computed:c}});return{...e,rows:a}}function L(e,t={},...n){let r=document.createElement(e);for(let[e,n]of Object.entries(t))if(n!=null&&n!==!1){if(e===`class`)r.className=String(n);else if(e===`on`)for(let[e,t]of Object.entries(n))r.addEventListener(e,t);else e===`dataset`?Object.assign(r.dataset,n):e===`style`?Object.assign(r.style,n):e in r&&typeof n!=`string`?r[e]=n:r.setAttribute(e,n===!0?``:String(n))}for(let e of n.flat())e!=null&&e!==!1&&r.append(e);return r}function uB(e,t=16){return Vj(e,t)}function dB(e,t,n,r){let i=L(`button`,{type:`button`,class:r?`dw-db__btn`:`dw-db__btn dw-db__btn--icon`,title:t,"aria-label":t},uB(e,15),r?L(`span`,{},r):null);return i.addEventListener(`click`,e=>{e.preventDefault(),n(e)}),i}var fB=null;function pB(e,t,n={}){fB?.close();let r=L(`div`,{class:`dw-db-pop ${n.class??``}`,role:`dialog`,"aria-label":n.label}),i=!1,a=()=>{i||(i=!0,c(),r.remove(),document.removeEventListener(`mousedown`,o,!0),document.removeEventListener(`keydown`,s,!0),fB?.box===r&&(fB=null),n.onClose?.())},o=t=>{let n=t.target;r.contains(n)||e.contains(n)||n instanceof Element&&n.closest(`.dw-block-menu`)||a()},s=t=>{t.key===`Escape`&&!document.querySelector(`.dw-block-menu`)&&(t.preventDefault(),t.stopPropagation(),a(),e instanceof HTMLElement&&e.focus())};document.body.append(r);let c=Aj(e,r,()=>{Pj(e,r,{placement:n.placement??`bottom-start`,strategy:`fixed`,middleware:[jj(4),Nj(),Mj({padding:8})]}).then(({x:e,y:t})=>Object.assign(r.style,{left:`${e}px`,top:`${t}px`}))});return document.addEventListener(`mousedown`,o,!0),document.addEventListener(`keydown`,s,!0),t(r,a),fB={box:r,close:a},fB}function mB(){fB?.close()}function hB(e,t){let n=L(`input`,{type:t.type??`text`,class:t.class??`dw-db-input`,placeholder:t.placeholder,"aria-label":t.label??t.placeholder});n.value=e;let r=!1,i=()=>{r||(r=!0,t.onCommit(n.value))};return n.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),i()):e.key===`Escape`&&(r=!0,t.onCancel?.())}),n.addEventListener(`blur`,i),n}function gB(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=L(`a`,{href:r,download:e});document.body.append(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function _B(e){return new Promise(t=>{let n=L(`input`,{type:`file`,accept:e});n.onchange=()=>t(n.files?.[0]??null),n.click()})}function vB(e,t){let n=e.read(t);return!n||!e.pointsHere?[]:n.columns.filter(n=>n.type===`relation`&&n.relation&&!n.relation.back&&e.pointsHere(t,n.relation))}var yB=e=>`fn${e[0].toUpperCase()}${e.slice(1)}`,bB=(e,t)=>e[yB(t)];function xB(e,t,n,r){let i=L(`div`,{class:`dw-db-pop__item${t?` is-active`:``}`,role:`option`,"aria-selected":String(t)},L(`span`,{},e),r?L(`small`,{class:`dw-db-pop__sub`},r):null);return i.addEventListener(`mousedown`,e=>e.preventDefault()),i.addEventListener(`click`,n),i}function SB(e,t,n,r){let i=e.store,a=e.linked;if(!i||!a)return;let o=e.labels;pB(t,(t,r)=>{let s=n.relation,c=e=>{let c={page:e.page,database:e.database},l=vB(a,c);if(!l.length)return i.setRelation(n.id,c),r();let u=!!s&&s.page===e.page&&s.database===e.database;t.replaceChildren(L(`div`,{class:`dw-db-pop__title`},e.title||o.untitled),L(`div`,{class:`dw-db-pop__list`,role:`listbox`},xB(o.relationOneWay,u&&!s.back,()=>{i.setRelation(n.id,c),r()}),...l.map(e=>xB(LR(o.relationMirror,e.name||o.typeRelation),u&&s.back===e.id,()=>{i.setRelation(n.id,{...c,back:e.id}),r()},o.relationTwoWay))))},l=L(`div`,{class:`dw-db-pop__list`,role:`listbox`});if((()=>{let e=a.local();l.replaceChildren(L(`div`,{class:`dw-db-pop__heading`},o.relationThisPage),...e.length?e.map(e=>xB(e.title||o.untitled,!!s&&!s.page&&s.database===e.database,()=>c(e))):[L(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})(),t.append(L(`div`,{class:`dw-db-pop__title`},o.relationPick),l),a.searchPages&&a.databasesOn){let e=L(`input`,{class:`dw-db-input`,placeholder:o.relationSearchPage,"aria-label":o.relationOtherPage}),n=L(`div`,{class:`dw-db-pop__list`,role:`listbox`}),r=0;e.addEventListener(`input`,async()=>{let t=e.value.trim(),i=++r;if(!t)return n.replaceChildren();let l=await a.searchPages(t).catch(()=>[]);i===r&&n.replaceChildren(...l.slice(0,8).map(e=>xB(e.title||o.untitled,!1,async()=>{let t=await a.databasesOn(e.id).catch(()=>[]);i===r&&n.replaceChildren(L(`div`,{class:`dw-db-pop__heading`},e.title||o.untitled),...t.length?t.map(e=>xB(e.title||o.untitled,s?.page===e.page&&s.database===e.database,()=>c(e))):[L(`div`,{class:`dw-db-pop__empty`},o.relationNoDatabases)])})))}),e.addEventListener(`keydown`,e=>e.stopPropagation()),t.append(L(`div`,{class:`dw-db-pop__heading`},o.relationOtherPage),e,n)}if(s&&!s.back&&a.addBack&&a.writable?.(s)){let i=a.read(s),c=i?.columns.some(e=>e.relation?.back===n.id&&a.pointsHere?.(s,e.relation));if(i&&!c){let c=L(`button`,{type:`button`,class:`dw-db__btn dw-db-pop__add`},uB(`plus`,14),L(`span`,{},LR(o.relationShowOn,i.title||o.untitled)));c.addEventListener(`click`,()=>{a.addBack(s,n.id,e.db.title||n.name||o.typeRelation),r()}),t.append(c)}}},{class:`dw-db-pop--choices`,label:o.relationTo,onClose:r})}function CB(e,t,n,r,i){let a=e.store,o=e.labels,s=r.relation,c=s?e.linked?.read(s):null;if(!s||!c){if(t.append(L(`div`,{class:`dw-db-pop__empty`},s?o.relationMissing:o.relationPick)),!s&&e.linked){let n=L(`button`,{type:`button`,class:`dw-db__btn`},o.relationTo);n.addEventListener(`click`,()=>{i(),SB(e,t,r)}),t.append(n)}return}let l=rz(c),u=!!s.back,d=!u||!!e.linked?.writable?.(s),f=Rz(n,r,c),p=L(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),m=L(`input`,{class:`dw-db-input`,placeholder:o.searchRecords,"aria-label":o.linkRecord}),h=L(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(p),d?t.append(m,h):t.append(L(`div`,{class:`dw-db-pop__empty`},o.relationBackReadOnly));let g=e=>uz(e,l)||o.untitledRow,_=t=>{if(!d)return;let i=!f.includes(t);if(u){if(!e.linked?.link?.(s,n.id,t,i))return}else a.setCell(n.id,r.id,i?[...f,t]:f.filter(e=>e!==t));f=i?[...f,t]:f.filter(e=>e!==t),b()},v=0,y=[],b=()=>{let e=new Map(c.rows.map(e=>[e.id,e]));p.replaceChildren(...f.flatMap(t=>{let n=e.get(t);if(!n)return[];let r=L(`span`,{class:`dw-db-tag`,dataset:{color:`gray`}},g(n));if(d){let e=L(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,()=>_(t)),r.append(e)}return[r]}));let t=m.value.trim().toLowerCase();y=c.rows.filter(e=>!t||g(e).toLowerCase().includes(t)).slice(0,50),v=Math.min(v,Math.max(0,y.length-1)),h.replaceChildren(...y.length?y.map((e,t)=>{let n=xB(g(e),t===v,()=>_(e.id));return f.includes(e.id)&&n.prepend(L(`span`,{class:`dw-db-pop__check`},`✓`)),n}):[L(`div`,{class:`dw-db-pop__empty`},o.noRecords)])};m.addEventListener(`input`,()=>{v=0,b()}),m.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),y.length&&(v=(v+(e.key===`ArrowDown`?1:-1)+y.length)%y.length),b();else if(e.key===`Enter`){e.preventDefault();let t=y[v];t&&_(t.id)}else e.key===`Escape`&&(e.preventDefault(),i())}),b(),d&&m.focus({preventScroll:!0})}function wB(e,t,n,r){let i=e.store;if(!i)return;let a=e.labels;pB(t,t=>{let r=e.db.columns.filter(e=>e.type===`relation`);if(!r.length){t.append(L(`div`,{class:`dw-db-pop__empty`},a.rollupNeedsRelation));return}let o=n.rollup??{relation:r[0].id,property:``,fn:`count`},s=(e,t,n,r)=>{let i=L(`select`,{class:`dw-db-input`,"aria-label":e});for(let[e,n]of t)i.append(L(`option`,{value:e},n));return i.value=n,i.addEventListener(`change`,()=>r(i.value)),L(`label`,{class:`dw-db-pop__field`},L(`span`,{},e),i)},c=()=>{let l=r.find(e=>e.id===o.relation)??r[0],u=l.relation?e.linked?.read(l.relation):null,d=[[``,a.rollupRecords]];for(let e of u?.columns??[])d.push([e.id,e.name||MR(a,e.type)]);let f=u?.columns.find(e=>e.id===o.property),p=Iz(f?f.type:``);p.includes(o.fn)||(o.fn=o.property?p[0]:`count`),t.replaceChildren(s(a.rollupRelation,r.map(e=>[e.id,e.name||a.typeRelation]),l.id,e=>{o.relation=e,o.property=``,o.fn=`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupProperty,d,o.property,e=>{o.property=e;let t=u?.columns.find(t=>t.id===e);o.fn=e?Iz(t?t.type:``)[0]:`count`,i.setRollup(n.id,{...o}),c()}),s(a.rollupFn,(o.property?p:[`count`,`showOriginal`]).map(e=>[e,bB(a,e)]),o.fn,e=>{o.fn=e,i.setRollup(n.id,{...o})}),u?L(`span`):L(`div`,{class:`dw-db-pop__empty`},a.relationMissing))};n.rollup||i.setRollup(n.id,{...o}),c()},{class:`dw-db-pop--choices`,label:a.rollupSettings,onClose:r})}function TB(e,t,n){let r=t.computed?.[n.id],i=L(`span`,{class:`dw-db-tags`});if(r?.links&&n.relation){let t=n.relation;for(let n of r.links){let r=L(`button`,{type:`button`,class:`dw-db-tag dw-db-rel`,dataset:{color:`gray`},title:e.labels.openRelated},n.title||e.labels.untitledRow);r.addEventListener(`click`,r=>{r.stopPropagation(),e.linked?.openRecord(t,n.id)}),i.append(r)}}else r?.text&&i.append(L(`span`,{class:`dw-db-cell__text`},r.text));return i}var EB={title:`text`,text:`type`,number:`sigma`,checkbox:`todo`,select:`tag`,multiSelect:`layers`,date:`calendar`,progress:`sliders`,link:`link`,attachment:`paperclip`,member:`users`,createdTime:`clock`,createdBy:`at`,relation:`relation`,rollup:`rollup`,formula:`sigma`},DB=[`title`,`text`,`number`,`link`],OB=[`createdTime`,`createdBy`,`rollup`,`formula`];function kB(e,t){let[n,r,i]=e.split(`-`).map(Number);return!n||!r||!i?e:new Date(n,r-1,i).toLocaleDateString(t,{year:`numeric`,month:`short`,day:`numeric`})}function AB(e,t,n){let r=L(`span`,{class:`dw-db-tag`,dataset:{color:t??`gray`}},e);if(n){let e=L(`button`,{type:`button`,class:`dw-db-tag__x`,"aria-label":`×`},`×`);e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,e=>{e.stopPropagation(),n()}),r.append(e)}return r}function jB(e){try{let t=new URL(e.includes(`://`)?e:`https://${e}`);return t.protocol===`http:`||t.protocol===`https:`||t.protocol===`mailto:`?t.href:null}catch{return null}}function MB(e,t,n){let r=iz(t,n),i=e.labels;switch(n.type){case`title`:{let e=typeof r==`string`?r:``;return L(`span`,{class:e?`dw-db-cell__title`:`dw-db-cell__title is-empty`},e||i.untitledRow)}case`text`:return L(`span`,{class:`dw-db-cell__text`},typeof r==`string`?r:``);case`number`:{let t=cz(r);return L(`span`,{class:`dw-db-cell__number`},t===null?``:t.toLocaleString(e.locale))}case`checkbox`:return L(`span`,{class:r===!0?`dw-db-check is-on`:`dw-db-check`,role:`img`,"aria-label":r===!0?i.checked:i.unchecked},r===!0?uB(`check`,13):null);case`select`:{let e=n.options?.find(e=>e.id===r);return L(`span`,{class:`dw-db-tags`},e?AB(e.name,e.color):null)}case`multiSelect`:return L(`span`,{class:`dw-db-tags`},lz(r).flatMap(e=>{let t=n.options?.find(t=>t.id===e);return t?[AB(t.name,t.color)]:[]}));case`date`:case`createdTime`:{let t=oz(r);return L(`span`,{class:`dw-db-cell__text`},t?kB(t,e.locale):``)}case`progress`:{let e=cz(r);if(e===null)return L(`span`);let t=Math.max(0,Math.min(100,e));return L(`span`,{class:`dw-db-progress`},L(`span`,{class:`dw-db-progress__bar`},L(`span`,{class:`dw-db-progress__fill`,style:{width:`${t}%`}})),L(`span`,{class:`dw-db-progress__num`},`${t}%`))}case`link`:{let e=typeof r==`string`?r:``,t=e?jB(e):null;if(!t)return L(`span`,{class:`dw-db-cell__text`},e);let n=L(`a`,{class:`dw-db-cell__link`,href:t,target:`_blank`,rel:`noopener noreferrer`},e);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}case`attachment`:return L(`span`,{class:`dw-db-tags`},lz(r).map(t=>{let n=L(`a`,{class:`dw-db-file`,href:e.files?e.files.resolve(t.src):t.src,target:`_blank`,rel:`noopener noreferrer`},uB(`paperclip`,12),t.name);return n.addEventListener(`click`,e=>{!e.ctrlKey&&!e.metaKey&&e.preventDefault()}),n}));case`member`:case`createdBy`:return L(`span`,{class:`dw-db-tags`},lz(r).map(e=>L(`span`,{class:`dw-db-person`},L(`span`,{class:`dw-db-person__dot`},(e?.name||`?`).slice(0,1).toUpperCase()),e?.name??``)));case`relation`:return TB(e,t,n);case`formula`:{let r=t.computed?.[n.id];if(r?.error)return L(`span`,{class:`dw-db-cell__error`,title:r.error},`⚠ `,e.labels.formulaError);let i=r?.value;return typeof i==`boolean`?L(`span`,{class:i?`dw-db-check is-on`:`dw-db-check`,role:`img`,"aria-label":i?e.labels.checked:e.labels.unchecked},i?uB(`check`,12):null):typeof i==`number`?L(`span`,{class:`dw-db-cell__number`},i.toLocaleString(e.locale,{maximumFractionDigits:10})):L(`span`,{class:`dw-db-cell__text`},r?.text??``)}case`rollup`:{let r=t.computed?.[n.id],i=r?.value;return typeof i==`number`?L(`span`,{class:`dw-db-cell__number`},/^-?\d+(\.\d+)?%?$/.test(r.text)?i.toLocaleString(e.locale,{maximumFractionDigits:2})+(r.text.endsWith(`%`)?`%`:``):r.text):L(`span`,{class:`dw-db-cell__text`},r?.text??``)}}}function NB(e,t,n,r,i){let a=e.store;if(!a||OB.includes(r.type))return i.onDone();let o=iz(n,r);if(r.type===`checkbox`)return a.setCell(n.id,r.id,o!==!0),i.onDone();e.setEditing(!0);let s=t=>{e.setEditing(!1),i.onDone(t)};if(DB.includes(r.type)){let e=i.initial??(r.type===`number`?cz(o)?.toString()??``:typeof o==`string`?o:``),c,l=hB(e,{class:`dw-db-cell__input`,type:(r.type,`text`),label:r.name,onCommit:e=>{let t=e.trim(),i=r.type===`number`?cz(t):r.type===`title`||r.type===`text`?e:t;i!==(o??null)&&(i!==``||o!==void 0)&&a.setCell(n.id,r.id,i),s(c)},onCancel:()=>s()});l.addEventListener(`keydown`,e=>{e.key===`Enter`&&(c=`down`),e.key===`Tab`&&(e.preventDefault(),c=e.shiftKey?`left`:`right`,l.blur())}),t.replaceChildren(l),t.classList.add(`is-editing`),l.focus(),i.initial===void 0?l.select():l.setSelectionRange(l.value.length,l.value.length);return}let c=(e,n=``)=>pB(t,e,{class:n,onClose:()=>s(),label:r.name});switch(r.type){case`select`:case`multiSelect`:c((t,a)=>PB(e,t,n,r,a,i.initial),`dw-db-pop--choices`);break;case`date`:c((t,i)=>{let s=L(`input`,{type:`date`,class:`dw-db-input`,"aria-label":r.name});s.value=oz(o),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,s.value||null)),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&i()});let c=L(`button`,{type:`button`,class:`dw-db__btn`},e.labels.clear);c.addEventListener(`click`,()=>{a.setCell(n.id,r.id,null),i()});let l=L(`button`,{type:`button`,class:`dw-db__btn`},e.labels.today);l.addEventListener(`click`,()=>{let e=new Date;a.setCell(n.id,r.id,`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`),i()}),t.append(s,L(`div`,{class:`dw-db-pop__row`},l,c)),s.focus({preventScroll:!0})});break;case`progress`:c((e,t)=>{let i=cz(o)??0,s=L(`input`,{type:`range`,min:`0`,max:`100`,step:`1`,class:`dw-db-range`,"aria-label":r.name});s.value=String(i);let c=L(`span`,{class:`dw-db-progress__num`},`${i}%`);s.addEventListener(`input`,()=>c.textContent=`${s.value}%`),s.addEventListener(`change`,()=>a.setCell(n.id,r.id,Number(s.value))),s.addEventListener(`keydown`,e=>{e.key===`Enter`&&t()}),e.append(L(`div`,{class:`dw-db-pop__row`},s,c)),s.focus({preventScroll:!0})});break;case`member`:c((t,i)=>FB(e,t,n,r,i),`dw-db-pop--choices`);break;case`attachment`:c(t=>IB(e,t,n,r),`dw-db-pop--choices`);break;case`relation`:c((t,i)=>CB(e,t,n,r,i),`dw-db-pop--choices`);break;default:s()}}function PB(e,t,n,r,i,a){let o=e.store,s=e.labels,c=r.type===`multiSelect`,l=[...r.options??[]],u=c?lz(iz(n,r)):[String(iz(n,r)??``)].filter(Boolean),d=0,f=L(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),p=L(`input`,{class:`dw-db-input`,placeholder:s.searchOptions,"aria-label":s.searchOptions});p.value=a??``;let m=L(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(f,p,m);let h=()=>o.setCell(n.id,r.id,c?u:u[0]??null),g=e=>{u=c?u.includes(e)?u.filter(t=>t!==e):[...u,e]:u[0]===e?[]:[e],h(),c?b():i()},_=e=>{let t={id:qR(),name:e,color:xz(l)};l=[...l,t],o.tx(()=>{o.setOptions(r.id,l),u=c?[...u,t.id]:[t.id],h()}),p.value=``,c?b():i()},v=(t,n)=>{Gj(t,[{id:`rename`,label:s.renameOption,icon:`pencil`,run:()=>{let e=window.prompt(s.renameOption,n.name)?.trim();e&&(l=l.map(t=>t.id===n.id?{...t,name:e}:t),o.setOptions(r.id,l),b())}},{id:`color`,label:s.optionColor,icon:`palette`,children:PP.map(t=>({id:t,label:e.colorNames[t]??t,icon:t===n.color?`check`:`drop`,run:()=>{l=l.map(e=>e.id===n.id?{...e,color:t}:e),o.setOptions(r.id,l),b()}}))},{id:`delete`,label:s.deleteOption,icon:`trash`,danger:!0,run:()=>{l=l.filter(e=>e.id!==n.id),u=u.filter(e=>e!==n.id),o.setOptions(r.id,l),b()}}],s.optionColor,()=>p.focus())},y=[];function b(){f.replaceChildren(...u.flatMap(e=>{let t=l.find(t=>t.id===e);return t?[AB(t.name,t.color,()=>g(e))]:[]}));let e=p.value.trim();y=l.filter(t=>t.name.toLowerCase().includes(e.toLowerCase())).map(e=>({kind:`option`,o:e})),e&&!l.some(t=>t.name.toLowerCase()===e.toLowerCase())&&y.push({kind:`create`,name:e}),d=Math.min(d,Math.max(0,y.length-1)),m.replaceChildren(...y.map((e,t)=>{let n=L(`div`,{class:`dw-db-pop__item${t===d?` is-active`:``}`,role:`option`,"aria-selected":String(e.kind===`option`&&u.includes(e.o.id))});if(n.addEventListener(`mousedown`,e=>e.preventDefault()),e.kind===`option`){n.append(L(`span`,{class:`dw-db-pop__check`},u.includes(e.o.id)?uB(`check`,13):null),AB(e.o.name,e.o.color));let t=L(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon dw-db-pop__more`,"aria-label":s.optionColor},uB(`more`,14));t.addEventListener(`click`,n=>{n.stopPropagation(),v(t,e.o)}),n.append(t),n.addEventListener(`click`,()=>g(e.o.id))}else n.append(L(`span`,{class:`dw-db-pop__check`},uB(`plus`,13)),L(`span`,{},LR(s.createOption,e.name))),n.addEventListener(`click`,()=>_(e.name));return n}))}p.addEventListener(`input`,()=>{d=0,b()}),p.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),y.length&&(d=(d+(e.key===`ArrowDown`?1:-1)+y.length)%y.length),b();else if(e.key===`Enter`){e.preventDefault();let t=y[d];t?.kind===`option`?g(t.o.id):t?.kind===`create`?_(t.name):i()}else e.key===`Backspace`&&!p.value&&c&&u.length&&g(u[u.length-1])}),b(),p.focus({preventScroll:!0}),p.setSelectionRange(p.value.length,p.value.length)}function FB(e,t,n,r,i){let a=e.store,o=e.labels,s=lz(iz(n,r)).filter(e=>e?.id),c=L(`div`,{class:`dw-db-tags dw-db-pop__chosen`}),l=L(`input`,{class:`dw-db-input`,placeholder:o.searchPeople,"aria-label":o.searchPeople}),u=L(`div`,{class:`dw-db-pop__list`,role:`listbox`});t.append(c,l,u);let d=()=>a.setCell(n.id,r.id,s),f=()=>c.replaceChildren(...s.map(e=>AB(e.name,`gray`,()=>{s=s.filter(t=>t.id!==e.id),d(),f()}))),p=0,m=[],h=0,g=()=>{u.replaceChildren(...m.length?m.map((e,t)=>{let n=L(`div`,{class:`dw-db-pop__item${t===h?` is-active`:``}`,role:`option`},L(`span`,{class:`dw-db-person__dot`},(e.name||`?`).slice(0,1).toUpperCase()),L(`span`,{},e.name));return n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>_(e)),n}):[L(`div`,{class:`dw-db-pop__empty`},l.value.trim()?o.noPeople:``)])},_=e=>{s.some(t=>t.id===e.id)||(s=[...s,e]),d(),l.value=``,m=[],f(),g()};l.addEventListener(`input`,async()=>{let t=l.value.trim(),n=++p,r=e.people&&t?await e.people.search(t).catch(()=>[]):[];n===p&&(m=r.slice(0,8).map(e=>({id:e.id,name:e.label})),h=0,g())}),l.addEventListener(`keydown`,e=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`)e.preventDefault(),m.length&&(h=(h+(e.key===`ArrowDown`?1:-1)+m.length)%m.length),g();else if(e.key===`Enter`){e.preventDefault();let t=m[h];t?_(t):i()}}),f(),g(),l.focus({preventScroll:!0})}function IB(e,t,n,r){let i=e.store,a=e.labels,o=lz(iz(n,r)).filter(e=>e?.src),s=L(`div`,{class:`dw-db-pop__list`}),c=()=>s.replaceChildren(...o.map((t,s)=>{let l=e.files?e.files.resolve(t.src):t.src,u=L(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":a.remove,title:a.remove},uB(`trash`,14));return u.addEventListener(`click`,()=>{o=o.filter((e,t)=>t!==s),i.setCell(n.id,r.id,o),c()}),L(`div`,{class:`dw-db-pop__item`},L(`a`,{class:`dw-db-file`,href:l,target:`_blank`,rel:`noopener noreferrer`},uB(`paperclip`,12),t.name),u)}));t.append(s);let l=e.files?.upload;if(l){let s=L(`button`,{type:`button`,class:`dw-db__btn`},uB(`upload`,14),L(`span`,{},a.upload));s.addEventListener(`click`,()=>{let t=L(`input`,{type:`file`,multiple:!0});t.onchange=async()=>{for(let a of[...t.files??[]])try{let t=await l.call(e.files,a);o=[...o,{name:t.name,src:t.url,size:t.size,mime:t.mime}],i.setCell(n.id,r.id,o),c()}catch{}},t.click()}),t.append(L(`div`,{class:`dw-db-pop__row`},s))}c()}var LB=class{host;db;rowId;order;onClose;dom;panel;head=L(`div`,{class:`dw-db-peek__head`});props=L(`div`,{class:`dw-db-peek__props`});bodyEl=L(`div`,{class:`dw-db-peek__body`});unmount=null;editing=0;pending=!1;wide=!1;returnFocus;constructor(e,t,n,r,i){this.host=e,this.db=t,this.rowId=n,this.order=r,this.onClose=i,this.returnFocus=document.activeElement,this.panel=L(`div`,{class:`dw-db-peek__panel`,role:`dialog`,"aria-modal":`true`,tabIndex:-1},this.head,this.props,this.bodyEl),this.dom=L(`div`,{class:e.page?`dw-db-peek dw-db-peek--page`:`dw-db-peek`},this.panel),this.dom.addEventListener(`mousedown`,e=>{e.target===this.dom&&!this.host.page&&this.close()}),this.dom.addEventListener(`keydown`,e=>{e.key===`Escape`&&!document.querySelector(`.dw-db-pop, .dw-block-menu`)&&(e.preventDefault(),e.stopPropagation(),this.close())}),e.page?(this.panel.removeAttribute(`aria-modal`),this.panel.setAttribute(`role`,`region`),e.page.container.replaceChildren(this.dom)):document.body.append(this.dom),this.draw(!0),this.panel.focus({preventScroll:!0})}get row(){return this.rowId}ctx(){return{...this.host.ctx,db:this.db,openRow:e=>this.show(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw(!1))}}}update(e,t){if(this.db=e,t&&(this.host={...this.host,ctx:{...this.host.ctx,...t}}),!e.rows.some(e=>e.id===this.rowId))return this.close();this.editing?this.pending=!0:this.draw(!1)}show(e){e!==this.rowId&&(this.rowId=e,this.draw(!0))}draw(e){let t=this.db.rows.find(e=>e.id===this.rowId);if(!t)return;let n=this.ctx(),r=n.labels,i=n.store;this.panel.classList.toggle(`is-wide`,this.wide);let a=this.order.indexOf(this.rowId),o=dB(`chevron-up`,r.previousRow,()=>this.show(this.order[a-1])),s=dB(`chevron-down`,r.nextRow,()=>this.show(this.order[a+1]));o.disabled=a<=0,s.disabled=a<0||a>=this.order.length-1;let c=this.host.page;this.head.replaceChildren(...c?[dB(`chevron-left`,r.backToPage,()=>this.close())]:[],L(`span`,{class:`dw-db-peek__db`},uB(`database`,14),this.db.title||r.untitled),L(`span`,{class:`dw-db-peek__grow`}),o,s,...c?[]:[dB((this.wide,`width`),this.wide?r.collapse:r.expand,()=>{this.wide=!this.wide,this.panel.classList.toggle(`is-wide`,this.wide)})],...this.host.openPage?[dB(`open`,r.openFullPage,()=>this.host.openPage(this.rowId))]:[],...this.host.copyLink?[dB(`link`,r.copyLink,()=>this.host.copyLink(this.rowId))]:[],...c?[]:[dB(`close`,r.close,()=>this.close())]);let l=rz(this.db),u=String(iz(t,l)??``),d=i?(()=>{let e=L(`input`,{class:`dw-db-peek__title`,placeholder:r.untitledRow,"aria-label":l.name||r.typeTitle});return e.value=u,e.addEventListener(`focus`,()=>n.setEditing(!0)),e.addEventListener(`blur`,()=>{e.value!==u&&i.setCell(t.id,l.id,e.value),n.setEditing(!1)}),e.addEventListener(`keydown`,t=>{t.stopPropagation(),t.key===`Enter`&&e.blur()}),e})():L(`h2`,{class:`dw-db-peek__title`},u||r.untitledRow);this.panel.setAttribute(`aria-label`,u||r.untitledRow);let f=[d,...this.db.columns.filter(e=>e.type!==`title`).map(e=>{let a=L(`div`,{class:`dw-db-peek__value dw-db-t__cell--${e.type}`,tabIndex:i&&!OB.includes(e.type)?0:-1},MB(n,t,e)),o=()=>{i&&NB(n,a,t,e,{onDone:()=>this.draw(!1)})};return a.addEventListener(`click`,e=>{e.target.closest(`a, button`)||o()}),a.addEventListener(`keydown`,e=>{e.target===a&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())}),L(`div`,{class:`dw-db-peek__prop`},L(`div`,{class:`dw-db-peek__label`},uB(EB[e.type],14),L(`span`,{},e.name||MR(r,e.type))),a)})];if(i){let e=dB(`plus`,r.addColumn,()=>Gj(e,HR.map(e=>({id:e,label:MR(r,e),icon:EB[e],run:()=>i.addColumn(e,MR(r,e))})),r.addColumn),r.addColumn);e.classList.add(`dw-db-peek__add`),f.push(e)}let p=this.props.contains(document.activeElement);this.props.replaceChildren(...f),p&&this.panel.focus({preventScroll:!0}),e&&(this.unmount?.(),this.bodyEl.replaceChildren(),this.unmount=this.host.mountBody(this.bodyEl,t))}close(e=!0){this.unmount?.(),this.unmount=null,this.dom.remove(),this.onClose(),e&&this.host.page?.onLeave?.(),this.returnFocus instanceof HTMLElement&&this.returnFocus.isConnected&&this.returnFocus.focus({preventScroll:!0})}},RB=`docwell-database`,zB=e=>e.getMap(`blocks`);function BB(e){let t=new zb;t.set(`title`,e.title);let n=(e,t)=>{let n=new Ib;return n.push(e.map((e,n)=>VB(t(e),n))),n};return t.set(`columns`,n(e.columns,HB)),t.set(`rows`,n(e.rows,UB)),t.set(`views`,n(e.views,WB)),t}function VB(e,t){return e.set(`pos`,t),e}function HB(e){let t=new zb;return t.set(`id`,e.id),t.set(`name`,e.name),t.set(`type`,e.type),e.options&&t.set(`options`,e.options),e.relation&&t.set(`relation`,e.relation),e.rollup&&t.set(`rollup`,e.rollup),e.formula!==void 0&&t.set(`formula`,e.formula),t}function UB(e){let t=new zb;t.set(`id`,e.id),t.set(`createdAt`,e.createdAt),e.createdBy&&t.set(`createdBy`,e.createdBy);let n=new zb;for(let[t,r]of Object.entries(e.cells))r!=null&&n.set(t,r);return t.set(`cells`,n),t}function WB(e){let t=new zb;for(let[n,r]of Object.entries(e))t.set(n,r);return t}function GB(e){return e.toArray().filter(e=>e instanceof zb).map((e,t)=>({m:e,p:KB(e,t),i:t})).sort((e,t)=>e.p-t.p||e.i-t.i).map(e=>e.m)}function KB(e,t){let n=e?.get(`pos`);return typeof n==`number`?n:t}function qB(e,t,n){let r=n?e.filter(e=>e!==n):e,i=Math.max(0,Math.min(t,r.length)),a=i>0?KB(r[i-1],i-1):null,o=i{let n=e.get(t);return n instanceof Ib?GB(n):[]},n=e=>{let t=e.toJSON();return delete t.pos,t},r=new Set,i=t(`rows`).map(e=>{let t=e.get(`cells`),n=e.get(`body`),i=e.get(`id`);return typeof i==`string`&&n instanceof ox&&n.length>0&&r.add(i),{id:i,createdAt:e.get(`createdAt`),createdBy:e.get(`createdBy`),cells:t instanceof zb?t.toJSON():{}}}),a=$R({title:e.get(`title`),columns:t(`columns`).map(n),rows:i,views:t(`views`).map(n)});for(let e of a.rows)r.has(e.id)&&(e.hasBody=!0);return a}function YB(e,t=``){let n=[{id:qR(),name:e.columnName(`title`),type:`title`},{id:qR(),name:e.columnName(`select`),type:`select`,options:[]}],r=Date.now();return{title:t,columns:n,rows:[0,1,2].map(e=>({id:qR(),cells:{},createdAt:r+e,createdBy:null})),views:[JR(`table`,e.tableView,n)]}}var XB=e=>e==null||e===``||Array.isArray(e)&&!e.length,ZB=class{doc;map;me;constructor(e,t,n){this.doc=e,this.map=t,this.me=n}snapshot(){return JB(this.map)}observe(e){let t=()=>e();return this.map.observeDeep(t),()=>this.map.unobserveDeep(t)}tx(e){this.doc.transact(e,RB)}list(e){let t=this.map.get(e);return t instanceof Ib||(t=new Ib,this.map.set(e,t)),t}find(e,t){let n=GB(this.list(e)),r=n.findIndex(e=>e.get(`id`)===t);return r<0?null:{item:n[r],index:r}}insertAt(e,t,n){let r=this.list(e),i=GB(r),a=Math.max(0,Math.min(t??i.length,i.length));for(let e of n)e.set(`pos`,qB(i,a)),i.splice(a++,0,e);r.push(n)}moveTo(e,t,n){let r=this.find(e,t);r&&r.index!==n&&r.item.set(`pos`,qB(GB(this.list(e)),n,r.item))}remove(e,t){let n=this.list(e),r=n.toArray().indexOf(t);r>=0&&n.delete(r,1)}setTitle(e){this.tx(()=>this.map.set(`title`,e))}addColumn(e,t,n){let r={id:qR(),name:t,type:e};return(e===`select`||e===`multiSelect`)&&(r.options=[]),this.tx(()=>this.insertAt(`columns`,n,[HB(r)])),r.id}renameColumn(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`name`,t))}setRelation(e,t){this.tx(()=>{let n=this.find(`columns`,e);if(!n)return;let r=n.item.get(`relation`);if(n.item.set(`relation`,t),t.back||r&&(r.page!==t.page||r.database!==t.database))for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof zb&&n.delete(e)}})}setRollup(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`rollup`,t))}setFormula(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`formula`,t))}setOptions(e,t){this.tx(()=>this.find(`columns`,e)?.item.set(`options`,t))}changeType(e,t){let n=this.snapshot(),r=n.columns.find(t=>t.id===e);if(!r||r.type===t||r.type===`title`||t===`title`)return;let i=t===`select`||t===`multiSelect`?r.options??[]:[],a=new Map;for(let o of n.rows){let n=Sz(o.cells[e],r,t,i);i=n.options,a.set(o.id,n.value)}this.tx(()=>{let n=this.find(`columns`,e);if(n){n.item.set(`type`,t),t===`select`||t===`multiSelect`?n.item.set(`options`,i):n.item.delete(`options`),t!==`relation`&&n.item.delete(`relation`),t!==`rollup`&&n.item.delete(`rollup`),t===`formula`?typeof n.item.get(`formula`)!=`string`&&n.item.set(`formula`,``):n.item.delete(`formula`);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);if(!(n instanceof zb))continue;let r=a.get(String(t.get(`id`)));XB(r)||r===!1?n.delete(e):n.set(e,r)}}})}deleteColumn(e){this.tx(()=>{let t=this.find(`columns`,e);if(t&&t.item.get(`type`)!==`title`){this.remove(`columns`,t.item);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof zb&&n.delete(e)}}})}moveColumn(e,t){this.tx(()=>this.moveTo(`columns`,e,t))}duplicateColumn(e,t){let n=this.snapshot().columns.find(t=>t.id===e);if(!n||n.type===`title`)return null;let r={...structuredClone(n),id:qR(),name:t};return this.tx(()=>{let t=this.find(`columns`,e);if(t){this.insertAt(`columns`,t.index+1,[HB(r)]);for(let t of this.list(`rows`).toArray()){let n=t.get(`cells`);n instanceof zb&&n.has(e)&&n.set(r.id,n.get(e))}}}),r.id}addRow(e={},t){return this.addRows([e],t)[0]}addRows(e,t){let n=this.me(),r=Date.now(),i=e.map((e,t)=>({id:qR(),cells:e,createdAt:r+t,createdBy:n}));return this.tx(()=>this.insertAt(`rows`,t,i.map(UB))),i.map(e=>e.id)}setCell(e,t,n){this.setCells([{row:e,col:t,value:n}])}setCells(e){this.tx(()=>{for(let{row:t,col:n,value:r}of e){let e=this.find(`rows`,t)?.item.get(`cells`);e instanceof zb&&(XB(r)?e.delete(n):e.set(n,r))}})}deleteRows(e){this.tx(()=>{let t=this.list(`rows`);for(let n=t.length-1;n>=0;n--)e.includes(String(t.get(n)?.get(`id`)))&&t.delete(n,1)})}moveRow(e,t){this.tx(()=>this.moveTo(`rows`,e,t))}duplicateRow(e){let t=this.find(`rows`,e);if(!t)return null;let n=QB(t.item,this.me());return this.tx(()=>this.insertAt(`rows`,t.index+1,[n])),String(n.get(`id`))}rowBody(e){let t=this.find(`rows`,e);if(!t)return null;let n=t.item.get(`body`);if(n instanceof ox)return n;let r=new ox;return this.tx(()=>t.item.set(`body`,r)),r}rowIndex(e){return this.find(`rows`,e)?.index??-1}addView(e,t){let n=JR(e,t,this.snapshot().columns);return this.tx(()=>this.insertAt(`views`,void 0,[WB(n)])),n.id}updateView(e,t){this.tx(()=>{let n=this.find(`views`,e);if(n)for(let[e,r]of Object.entries(t))n.item.set(e,r)})}duplicateView(e,t){let n=this.snapshot().views.find(t=>t.id===e);if(!n)return null;let r={...structuredClone(n),id:qR(),name:t};return this.tx(()=>{let t=this.find(`views`,e);this.insertAt(`views`,(t?.index??-1)+1,[WB(r)])}),r.id}deleteView(e){this.tx(()=>{let t=this.find(`views`,e);t&&this.list(`views`).length>1&&this.remove(`views`,t.item)})}moveView(e,t){this.tx(()=>this.moveTo(`views`,e,t))}};function QB(e,t){let n=new zb;n.set(`id`,qR()),n.set(`createdAt`,Date.now());let r=t??e.get(`createdBy`);nz(r)&&n.set(`createdBy`,r);let i=new zb,a=e.get(`cells`);if(a instanceof zb)for(let[e,t]of a.entries())i.set(e,t);n.set(`cells`,i);let o=e.get(`body`);if(o instanceof ox&&o.length){let e=new ox;e.insert(0,o.toArray().map(e=>e.clone())),n.set(`body`,e)}return n}function $B(e,t){let n=JB(e),r=e.get(`rows`);if(r instanceof Ib){let e=new Map;for(let t of r.toArray()){let n=t.get(`body`);n instanceof ox&&n.length&&e.set(String(t.get(`id`)),n)}for(let r of n.rows){let n=e.get(r.id);n&&(r.body=t(n))}}return n}function eV(e,t,n,r){e.transact(()=>{let i=BB(n);zB(e).set(t,i);let a=i.get(`rows`),o=new Map(n.rows.map(e=>[e.id,e]));for(let e of a.toArray()){let t=o.get(String(e.get(`id`)))?.body;if(!t?.length)continue;let n=new ox;e.set(`body`,n),r(t,n)}},RB)}function tV(e,t=`,`){let n=[],r=[],i=``,a=!1,o=0,s=e.replace(/^\uFEFF/,``);for(;oe.map(e=>xB(e,t)).join(t)).join(`\r -`)}function CB(e,t,n){return SB([t.map(e=>e.name),...n.map(e=>t.map(t=>iz(e,t)))])}function wB(e){let t=e.map(e=>e.trim()).filter(Boolean);if(!t.length)return`text`;if(t.every(e=>nz(e)!==null))return`number`;if(t.every(e=>/^\d{4}-\d{2}-\d{2}/.test(e)))return`date`;if(t.every(e=>/^(true|false|yes|no)$/i.test(e)))return`checkbox`;if(t.every(e=>/^https?:\/\/\S+$/.test(e)))return`link`;let n=new Set(t.map(e=>e.toLowerCase()));return t.length>=4&&n.size<=Math.max(2,t.length/3)&&t.every(e=>e.length<=40)?`select`:`text`}function TB(e,t,n){let r=e.trim();if(!r)return null;let i=e=>{let t=n.find(t=>t.name.toLowerCase()===e.toLowerCase());return t||(t={id:WR(),name:e,color:hz(n)},n.push(t)),t.id};switch(t.type){case`number`:return nz(r);case`progress`:{let e=nz(r.replace(`%`,``));return e===null?null:Math.max(0,Math.min(100,Math.round(e)))}case`checkbox`:return/^(true|yes|1|x|✓|done)$/i.test(r);case`date`:return ez(r)||null;case`select`:return i(r);case`multiSelect`:return[...new Set(r.split(/[,;]/).map(e=>e.trim()).filter(Boolean).map(i))];case`member`:case`attachment`:case`createdBy`:case`createdTime`:return null;default:return r}}function EB(e,t=`,`){let n=bB(e,t).filter(e=>e.some(e=>e.trim())),r=n[0]??[],i=n.slice(1),a=r.map((e,t)=>({id:WR(),name:e.trim()||`${t+1}`,type:t===0?`title`:wB(i.map(e=>e[t]??``))}));for(let e of a)e.type===`select`&&(e.options=[]);return{columns:a,rows:i.map(e=>{let t={};return a.forEach((n,r)=>{let i=TB(e[r]??``,n,n.options??[]);i!==null&&(!Array.isArray(i)||i.length)&&(t[n.id]=i)}),t})}}function DB(e,t){let n=[];return{index:e.map(e=>{let r=t.find(t=>t.name.trim().toLowerCase()===e.trim().toLowerCase());return!r&&e.trim()&&n.push(e.trim()),r??null}),missing:n}}function OB(e,t,n,r){let i=I(`select`,{class:`dw-db-select`,"aria-label":n});for(let n of t){let t=I(`option`,{value:n.value},n.label);n.value===e&&(t.selected=!0),i.append(t)}return i.addEventListener(`change`,()=>r(i.value)),i.addEventListener(`keydown`,e=>e.stopPropagation()),i}var kB=e=>e.map(e=>({value:e.id,label:e.name||`…`}));function AB(e,t,n,r){let i=e.labels;if(!oz(n.op))return null;if(t.type===`select`||t.type===`multiSelect`)return OB(typeof n.value==`string`?n.value:``,[{value:``,label:`—`},...(t.options??[]).map(e=>({value:e.id,label:e.name}))],i.value,r);let a=t.type===`date`||t.type===`createdTime`?`date`:t.type===`number`||t.type===`progress`?`number`:`text`,o=I(`input`,{class:`dw-db-input dw-db-input--small`,type:a,"aria-label":i.value,placeholder:i.value});return o.value=n.value===void 0||n.value===null?``:String(n.value),o.addEventListener(`keydown`,e=>e.stopPropagation()),o.addEventListener(`change`,()=>r(a===`number`?o.value===``?null:Number(o.value):o.value)),o}function jB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.filters),s=()=>r?.updateView(n.id,{filters:o}),c=()=>{t.replaceChildren(),o.length>1&&t.append(OB(n.filterMode,[{value:`and`,label:i.matchAll},{value:`or`,label:i.matchAny}],i.filter,e=>{n.filterMode=e,r?.updateView(n.id,{filterMode:n.filterMode})})),o.length||t.append(I(`p`,{class:`dw-db-pop__empty`},i.noFilters)),o.forEach((n,r)=>{let l=a.find(e=>e.id===n.column);if(!l)return;let u=az(l.type),d=I(`div`,{class:`dw-db-pop__line`},OB(n.column,kB(a),i.filter,e=>{let t=a.find(t=>t.id===e);o[r]={column:e,op:az(t.type)[0]},s(),c()}),OB(n.op,u.map(e=>({value:e,label:FR(i,e)})),i.filter,e=>{o[r]={...n,op:e},oz(e)||delete o[r].value,s(),c()}),AB(e,l,n,e=>{o[r]={...o[r],value:e},s()}),IB(i.remove,()=>{o.splice(r,1),s(),c()}));t.append(d)}),r&&t.append(LB(i.addFilter,()=>{let e=a.find(e=>e.type!==`title`)??a[0];o.push({column:e.id,op:az(e.type)[0]}),s(),c()}))};c()}function MB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.sorts),s=()=>r?.updateView(n.id,{sorts:o}),c=()=>{t.replaceChildren(),o.length||t.append(I(`p`,{class:`dw-db-pop__empty`},i.noSorts)),o.forEach((e,n)=>{t.append(I(`div`,{class:`dw-db-pop__line`},OB(e.column,kB(a),i.sort,t=>{o[n]={...e,column:t},s()}),OB(e.desc?`desc`:`asc`,[{value:`asc`,label:i.ascending},{value:`desc`,label:i.descending}],i.sort,t=>{o[n]={...e,desc:t===`desc`},s()}),IB(i.remove,()=>{o.splice(n,1),s(),c()})))}),r&&t.append(LB(i.addSort,()=>{let e=new Set(o.map(e=>e.column)),t=a.find(t=>!e.has(t.id))??a[0];o.push({column:t.id,desc:!1}),s(),c()}))};c()}function NB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>KR.includes(e.type)),o=a.map(e=>({value:e.id,label:e.name||NR(i,e.type)}));n.type!==`kanban`&&o.unshift({value:``,label:i.noGrouping}),t.append(I(`label`,{class:`dw-db-pop__label`},i.groupBy),a.length||n.type!==`kanban`?OB(n.groupBy??``,o,i.groupBy,e=>r?.updateView(n.id,{groupBy:e||null})):I(`p`,{class:`dw-db-pop__empty`},i.noGroupColumn))}function PB(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>e.type===`date`||e.type===`createdTime`);t.append(I(`label`,{class:`dw-db-pop__label`},i.dateColumn),a.length?OB(n.dateColumn??``,[{value:``,label:`—`},...a.map(e=>({value:e.id,label:e.name||NR(i,e.type)}))],i.dateColumn,e=>r?.updateView(n.id,{dateColumn:e||null})):I(`p`,{class:`dw-db-pop__empty`},i.noDateColumn))}function FB(e,t,n){let r=e.store,i=e.labels,a=[...n.hidden],o=()=>r?.updateView(n.id,{hidden:a}),s=()=>{t.replaceChildren();let n=e.db.columns.filter(e=>e.type!==`title`);if(r&&n.length){let e=I(`button`,{type:`button`,class:`dw-db__btn`},a.length?i.showAll:i.hideAll);e.addEventListener(`click`,()=>{a=a.length?[]:n.map(e=>e.id),o(),s()}),t.append(I(`div`,{class:`dw-db-pop__row dw-db-pop__row--end`},e))}for(let n of e.db.columns){let e=n.type===`title`||!a.includes(n.id),c=I(`button`,{type:`button`,class:`dw-db-pop__item`,role:`switch`,"aria-checked":String(e),disabled:n.type===`title`||!r},I(`span`,{class:`dw-db-pop__check`},kz(Gz[n.type],14)),I(`span`,{class:`dw-db-pop__grow`},n.name||NR(i,n.type)),I(`span`,{class:e?`dw-db-switch is-on`:`dw-db-switch`}));c.addEventListener(`click`,()=>{a=e?[...a,n.id]:a.filter(e=>e!==n.id),o(),s()}),t.append(c)}};s()}function IB(e,t){let n=I(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":e,title:e},kz(`close`,14));return n.addEventListener(`click`,t),n}function LB(e,t){let n=I(`button`,{type:`button`,class:`dw-db__btn dw-db-pop__add`},kz(`plus`,14),I(`span`,{},e));return n.addEventListener(`click`,t),n}var RB=6,zB=48;function BB(e,t){e.classList.add(`dw-db-touch-handle`);let n=!1,r=-1,i=0,a=0,o=0,s=0,c=0,l=null,u=null,d=0,f,p=0,m=()=>document.elementFromPoint(o,s),h=()=>{clearTimeout(f),cancelAnimationFrame(d),u&&(u.remove(),u=null,t.end()),t.source.classList.remove(`is-held`,`is-dragging`),n=!1,r=-1,p=Date.now()},g=()=>{if(!u)return;let e=oinnerWidth-zB),n=sinnerHeight-zB),r=!1;for(let[i,a]of[[`x`,e],[`y`,n]]){if(!a)continue;let e=VB(t.source,i)??(i===`y`?document.scrollingElement:null);if(!e)continue;let n=i===`x`?`scrollLeft`:`scrollTop`,o=e[n];e[n]+=a*12,r||=e[n]!==o}r&&t.over(m(),o,s),d=requestAnimationFrame(g)},_=e=>[...e.changedTouches].find(e=>e.identifier===r);e.addEventListener(`touchstart`,u=>{if(n||u.touches.length!==1)return;let d=u.changedTouches[0],p=u.target.closest(`input, textarea, select, [contenteditable='true']`);p&&e.contains(p)||(u.preventDefault(),n=!0,r=d.identifier,i=o=d.clientX,a=s=d.clientY,c=Date.now(),l=u.target,f=setTimeout(()=>{t.source.classList.add(`is-held`),navigator.vibrate?.(10)},500))},{passive:!1}),e.addEventListener(`touchmove`,e=>{let r=n&&_(e);if(r){if(e.preventDefault(),o=r.clientX,s=r.clientY,!u){if(Math.hypot(o-i,s-a)<=RB)return;clearTimeout(f),t.source.classList.remove(`is-held`),u=t.ghost();let e=t.source.getBoundingClientRect();Object.assign(u.style,{position:`fixed`,left:`${e.left}px`,top:`${e.top}px`,width:`${Math.max(80,Math.min(e.width,innerWidth-Math.max(e.left,0)-8))}px`,margin:`0`,pointerEvents:`none`,zIndex:`1000`}),u.classList.add(`dw-db-ghost`),document.body.append(u),t.source.classList.add(`is-dragging`),d=requestAnimationFrame(g)}u.style.transform=`translate(${o-i}px, ${s-a}px)`,t.over(m(),o,s)}},{passive:!1}),e.addEventListener(`touchend`,e=>{if(!n||!_(e))return;e.preventDefault();let r=u!==null,i=Date.now()-c>=500,a=l;r&&t.drop(m(),o,s),h(),r||(i&&t.hold?t.hold():a instanceof HTMLElement&&a.click())}),e.addEventListener(`touchcancel`,e=>{n&&_(e)&&h()});for(let t of[`contextmenu`,`dragstart`])e.addEventListener(t,e=>{(n||Date.now()-p<800)&&(e.preventDefault(),e.stopPropagation())},!0)}function VB(e,t){for(let n=e.parentElement;n;n=n.parentElement){let e=getComputedStyle(n),r=t===`x`?e.overflowX:e.overflowY;if((t===`x`?n.scrollWidth>n.clientWidth:n.scrollHeight>n.clientHeight)&&(r===`auto`||r===`scroll`))return n}return null}var HB=200,UB=class{host;dom=I(`div`,{class:`dw-db`,dataset:{type:`database`},contentEditable:`false`});db;viewId=null;search=``;editing=0;pending=!1;limit=HB;collapsed=new Set;sel=null;anchor=null;picked=new Set;month;titleEl=I(`div`,{class:`dw-db__title`});tabs=I(`div`,{class:`dw-db__tabs`,role:`tablist`});tools=I(`div`,{class:`dw-db__tools`});body=I(`div`,{class:`dw-db__body`});bulk=I(`div`,{class:`dw-db__bulk`});searchInput;buttons;constructor(e,t){this.host=e,this.db=t;let n=new Date;this.month={y:n.getFullYear(),m:n.getMonth()};let r=e.labels;this.searchInput=I(`input`,{class:`dw-db-input dw-db__search`,placeholder:r.search,"aria-label":r.search,hidden:!0}),this.searchInput.addEventListener(`input`,()=>{this.search=this.searchInput.value,this.limit=HB,this.drawBody()}),this.searchInput.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&(this.searchInput.value=``,this.search=``,this.searchInput.hidden=!0,this.drawBody())}),this.buttons={search:Az(`search`,r.search,()=>{this.searchInput.hidden=!this.searchInput.hidden,this.searchInput.hidden||this.searchInput.focus()}),filter:Az(`filter`,r.filter,e=>this.panel(e,`filter`),r.filter),sort:Az(`sort`,r.sort,e=>this.panel(e,`sort`),r.sort),group:Az(`layers`,r.group,e=>this.panel(e,`group`),r.group),props:Az(`sliders`,r.properties,e=>this.panel(e,`props`)),more:Az(`more`,r.more,()=>this.moreMenu()),add:Az(`plus`,r.newRow,()=>this.addRow(),r.newRow)},this.buttons.add.classList.add(`dw-db__btn--primary`);let i=I(`div`,{class:`dw-db__head`},this.titleEl),a=I(`div`,{class:`dw-db__bar`},this.tabs,this.tools);this.tools.append(this.searchInput,this.buttons.search,this.buttons.filter,this.buttons.sort,this.buttons.group,this.buttons.props,this.buttons.more,this.buttons.add),this.dom.append(i,a,this.bulk,this.body),this.draw()}get labels(){return this.host.labels}get editable(){return!!this.host.store}get view(){return this.db.views.find(e=>e.id===this.viewId)??this.db.views[0]??WB}ctx(){return{...this.host,db:this.db,openRow:e=>this.openRow(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw())}}}update(e,t){this.db=e,t&&(this.host={...this.host,...t}),this.editing?this.pending=!0:this.draw()}destroy(){Nz()}draw(){this.drawTitle(),this.drawTabs(),this.drawTools(),this.drawBody()}drawTitle(){let e=this.labels,t=this.db.title;if(this.titleEl.querySelector(`input`)===document.activeElement)return;if(!this.editable){this.titleEl.replaceChildren(I(`span`,{class:t?``:`is-empty`},t||e.untitled));return}let n=I(`input`,{class:`dw-db__title-input`,placeholder:e.untitled,"aria-label":e.untitled});n.value=t,n.addEventListener(`keydown`,e=>{e.stopPropagation(),(e.key===`Enter`||e.key===`Escape`)&&n.blur()}),n.addEventListener(`change`,()=>this.host.store?.setTitle(n.value)),this.titleEl.replaceChildren(n)}drawTabs(){let e=this.labels,t=this.view;if(this.tabs.replaceChildren(...this.db.views.map(n=>{let r=I(`button`,{type:`button`,class:n.id===t.id?`dw-db__tab is-active`:`dw-db__tab`,role:`tab`,"aria-selected":String(n.id===t.id)},kz(n.type===`kanban`?`cards`:n.type===`calendar`?`calendar`:`table`,14),I(`span`,{},n.name||IR(e,n.type)));return r.addEventListener(`click`,()=>{if(n.id===t.id&&this.editable)return this.viewMenu(r,n);this.viewId=n.id,this.sel=null,this.limit=HB,this.draw()}),r.addEventListener(`contextmenu`,e=>{this.editable&&(e.preventDefault(),this.viewMenu(r,n))}),r})),this.editable){let t=Az(`plus`,e.addView,()=>Kj(t,UR.map(t=>({id:t,label:IR(e,t),icon:t===`kanban`?`cards`:t===`calendar`?`calendar`:`table`,run:()=>{this.showView(this.host.store.addView(t,IR(e,t)))}})),e.addView));this.tabs.append(t)}}drawTools(){let e=this.view,t=this.buttons,n=(e,t)=>{e.classList.toggle(`is-on`,t>0);let n=e.querySelector(`span`);n&&(n.textContent=t?`${e.title} ${t}`:e.title)};n(t.filter,e.filters.length),n(t.sort,e.sorts.length),t.sort.hidden=e.type===`calendar`,t.group.classList.toggle(`is-on`,!!e.groupBy&&e.type===`table`),t.group.hidden=e.type===`calendar`,t.add.hidden=!this.editable,this.drawBulk()}drawBulk(){let e=[...this.picked].filter(e=>this.db.rows.some(t=>t.id===e));if(this.picked=new Set(e),this.bulk.hidden=!e.length||!this.editable,this.bulk.hidden)return this.bulk.replaceChildren();let t=this.labels;this.bulk.replaceChildren(I(`span`,{},LR(t.selected,e.length)),Az(`trash`,t.deleteRows,()=>{this.host.store?.deleteRows(e),this.picked.clear()},t.deleteRows),Az(`close`,t.close,()=>{this.picked.clear(),this.draw()}))}panel(e,t){let n=e.currentTarget;Mz(n,e=>{let n=this.ctx(),r=this.view;t===`filter`?jB(n,e,r):t===`sort`?MB(n,e,r):t===`group`?NB(n,e,r):(r.type===`calendar`&&PB(n,e,r),r.type===`kanban`&&NB(n,e,r),FB(n,e,r))},{class:`dw-db-pop--panel`,label:n.title,placement:`bottom-end`})}viewMenu(e,t){let n=this.labels,r=this.host.store,i=[{id:`rename`,label:n.renameView,icon:`pencil`,run:()=>{let e=window.prompt(n.viewName,t.name)?.trim();e&&r.updateView(t.id,{name:e})}},{id:`layout`,label:n.layout,icon:`grid`,children:UR.map(e=>({id:e,label:IR(n,e),icon:e===t.type?`check`:e===`kanban`?`cards`:e===`calendar`?`calendar`:`table`,run:()=>this.setLayout(t,e)}))},{id:`duplicate`,label:n.duplicateView,icon:`copy`,run:()=>{this.showView(r.duplicateView(t.id,`${t.name||IR(n,t.type)} 2`))}}];this.db.views.length>1&&i.push({id:`delete`,label:n.deleteView,icon:`trash`,danger:!0,run:()=>r.deleteView(t.id)}),Kj(e,i,n.layout)}showView(e){e&&(this.viewId=e,this.sel=null,this.limit=HB,this.draw())}setLayout(e,t){let n={type:t},r=this.db.columns;t===`kanban`&&!e.groupBy&&(n.groupBy=r.find(e=>[`select`,`multiSelect`,`checkbox`,`member`].includes(e.type))?.id??null),t===`calendar`&&!e.dateColumn&&(n.dateColumn=r.find(e=>e.type===`date`)?.id??null),t===`calendar`&&!n.dateColumn&&!e.dateColumn&&this.host.store&&(n.dateColumn=this.host.store.addColumn(`date`,this.labels.typeDate)),this.host.store?.updateView(e.id,n)}moreMenu(){let e=this.labels,t=this.view,n=[{id:`csv`,label:e.exportCsv,icon:`download`,run:()=>{let n=uz(this.db,t);Fz(`${(this.db.title||e.untitled).replace(/[\\/:*?"<>|]+/g,` `).trim()}.csv`,`\uFEFF${CB(this.db,n,lz(this.db,t,this.search))}`,`text/csv`)}}];this.editable&&(n.push({id:`import`,label:e.importCsv,icon:`upload`,run:()=>void this.importCsv()}),n.push({id:`view`,label:e.layout,icon:`grid`,run:()=>this.viewMenu(this.buttons.more,t)})),Kj(this.buttons.more,n,e.more)}async importCsv(){let e=this.host.store,t=await Iz(`.csv,text/csv,.tsv,text/tab-separated-values`);if(!e||!t)return;let n=await t.text(),r=t.name.endsWith(`.tsv`)?` `:`,`,i=bB(n,r).filter(e=>e.some(e=>e.trim()));i.length<2||e.tx(()=>{if(this.db.rows.every(e=>!iz(e,ZR(this.db)))){let t=EB(n,r);e.deleteRows(this.db.rows.map(e=>e.id));let i=ZR(this.db),[a,...o]=t.columns,s=new Map;a&&(e.renameColumn(i.id,a.name),s.set(a.id,i.id));for(let t of o){let n=this.db.columns.find(e=>e.name.toLowerCase()===t.name.toLowerCase()&&e.type!==`title`);n&&e.deleteColumn(n.id);let r=e.addColumn(t.type,t.name);t.options&&e.setOptions(r,t.options),s.set(t.id,r)}e.addRows(t.rows.map(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[s.get(e)??e,t])))),this.host.notify?.(LR(this.labels.imported,t.rows.length));return}let{index:t,missing:a}=DB(i[0],this.db.columns),o=new Map(a.map(t=>[t,e.addColumn(`text`,t)])),s=i[0].map((e,n)=>{let r=t[n];if(r)return r;let i=o.get(e.trim());return i?{id:i,name:e,type:`text`}:null}),c=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),l=i.slice(1).map(e=>{let t={};return s.forEach((n,r)=>{if(!n)return;let i=TB(e[r]??``,n,c.get(n.id)??[]);i!==null&&(t[n.id]=i)}),t});for(let t of this.db.columns){let n=c.get(t.id);n&&n.length!==(t.options?.length??0)&&e.setOptions(t.id,n)}e.addRows(l),this.host.notify?.(LR(this.labels.imported,l.length))})}addRow(e={},t=!1){let n=this.host.store;if(!n)return;let r=this.view;for(let t of r.filters){let n=this.db.columns.find(e=>e.id===t.column);!n||t.column in e||(t.op===`is`&&(n.type===`select`||n.type===`text`)&&t.value&&(e[n.id]=t.value),t.op===`contains`&&n.type===`multiSelect`&&t.value&&(e[n.id]=[t.value]),t.op===`checked`&&(e[n.id]=!0))}let i=n.addRow(e);t||r.type!==`table`?this.openRow(i):(this.sel={row:i,col:ZR(this.db).id},queueMicrotask(()=>this.startEdit()))}openRow(e){let t=lz(this.db,this.view,this.search).map(e=>e.id);this.host.openRow(e,t)}drawBody(){let e=this.view;e.type===`kanban`?this.drawKanban(e):e.type===`calendar`?this.drawCalendar(e):this.drawTable(e)}tableRows=[];tableCols=[];grid=null;drawTable(e){let t=this.labels,n=uz(this.db,e),r=lz(this.db,e,this.search),i=e.groupBy?this.db.columns.find(t=>t.id===e.groupBy):void 0,a=i?dz(r,i,t.noValue,t.checked,t.unchecked).filter(e=>e.rows.length||e.key!==``):[{key:``,label:``,rows:r}];this.tableCols=n,this.tableRows=[];let o=this.editable,s=e.sorts.length>0,c=I(`colgroup`,{},I(`col`,{class:`dw-db-t__gutter-col`}),n.map(t=>I(`col`,{style:{width:`${e.widths[t.id]??(t.type===`title`?240:160)}px`}})),o?I(`col`,{class:`dw-db-t__add-col`}):null),l=I(`table`,{class:`dw-db-t`},c,I(`thead`,{},I(`tr`,{},I(`th`,{class:`dw-db-t__gutter`,"aria-hidden":`true`}),n.map((e,t)=>this.headerCell(e,t,c.children[t+1])),o?I(`th`,{class:`dw-db-t__add`},Az(`plus`,t.addColumn,e=>this.addColumnMenu(e.currentTarget))):null))),u=0;for(let r of a){let a=I(`tbody`,{}),c=`${e.id}:${r.key}`;if(i){let e=!this.collapsed.has(c),t=I(`button`,{type:`button`,class:`dw-db-t__group`,"aria-expanded":String(e)},kz(e?`chevron-down`:`chevron-right`,14),r.key&&i.type!==`checkbox`&&i.type!==`member`&&i.type!==`createdBy`?I(`span`,{class:`dw-db-tag`,dataset:{color:r.color??`gray`}},r.label):I(`span`,{},r.label),I(`span`,{class:`dw-db-t__count`},String(r.rows.length)));if(t.addEventListener(`click`,()=>{e?this.collapsed.add(c):this.collapsed.delete(c),this.drawBody()}),a.append(I(`tr`,{class:`dw-db-t__group-row`},I(`td`,{colSpan:n.length+2},t))),!e){l.append(a);continue}}for(let e of r.rows){if(u>=this.limit)break;u++,this.tableRows.push(e),a.append(this.tableRow(e,n,o&&!s))}if(o&&u{let e={};i&&r.key?e[i.id]=mz({id:``,cells:{},createdAt:0,createdBy:null},i,``,r.key,r.rows.flatMap(e=>GB(QR(e,i)))):i?.type===`checkbox`&&(e[i.id]=r.key===`true`),this.addRow(e)}),a.append(I(`tr`,{class:`dw-db-t__new-row`},I(`td`,{colSpan:n.length+2},e)))}l.append(a)}let d=[],f=I(`div`,{class:`dw-db-t__wrap`,role:`grid`,tabIndex:0,"aria-label":this.db.title||t.database},l);if(d.push(f),r.length||d.push(I(`p`,{class:`dw-db__empty`},this.db.rows.length?t.noMatches:t.noRows)),r.length>u&&u>=this.limit){let e=I(`button`,{type:`button`,class:`dw-db__btn dw-db__more`},`${t.more} (${r.length-u})`);e.addEventListener(`click`,()=>{this.limit+=HB,this.drawBody()}),d.push(e)}this.grid=f,f.addEventListener(`keydown`,e=>this.onGridKey(e)),f.addEventListener(`copy`,e=>this.onCopy(e)),f.addEventListener(`paste`,e=>this.onPaste(e));let p=this.body.querySelector(`.dw-db-t__wrap`)?.scrollLeft??0,m=this.body.contains(document.activeElement);this.body.replaceChildren(...d),f.scrollLeft=p,this.markSelection(),m&&this.sel&&f.focus({preventScroll:!0})}headerCell(e,t,n){let r=this.labels,i=I(`span`,{class:`dw-db-t__name`},e.name||NR(r,e.type)),a=I(`button`,{type:`button`,class:`dw-db-t__head`,"aria-haspopup":`menu`,draggable:this.editable},kz(Gz[e.type],14),i),o=I(`th`,{dataset:{col:e.id}},a);if(a.addEventListener(`click`,()=>this.columnMenu(a,e,t)),this.editable){a.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-column`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),o.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-column`)&&(e.preventDefault(),o.classList.add(`is-drop`))}),o.addEventListener(`dragleave`,()=>o.classList.remove(`is-drop`)),o.addEventListener(`drop`,t=>{o.classList.remove(`is-drop`);let n=t.dataTransfer?.getData(`application/x-docwell-column`);n&&n!==e.id&&(t.preventDefault(),this.host.store?.moveColumn(n,this.db.columns.findIndex(t=>t.id===e.id)))});let t=I(`span`,{class:`dw-db-t__resize`,title:r.resize,"aria-hidden":`true`});t.addEventListener(`pointerdown`,r=>{r.preventDefault(),r.stopPropagation();let i=r.clientX,a=n.getBoundingClientRect().width||160,o=a;t.setPointerCapture(r.pointerId);let s=e=>{o=Math.max(72,Math.round(a+e.clientX-i)),n.style.width=`${o}px`},c=()=>{t.removeEventListener(`pointermove`,s),t.removeEventListener(`pointerup`,c);let n=this.view;o!==a&&this.host.store?.updateView(n.id,{widths:{...n.widths,[e.id]:o}})};t.addEventListener(`pointermove`,s),t.addEventListener(`pointerup`,c)}),o.append(t)}return o}columnMenu(e,t,n){let r=this.labels,i=this.host.store,a=this.view,o=e=>({id:e?`desc`:`asc`,label:e?r.sortDescending:r.sortAscending,icon:e?`arrow-down`:`arrow-up`,run:()=>i?.updateView(a.id,{sorts:[{column:t.id,desc:e}]})});if(!i){Kj(e,[o(!1),o(!0)],t.name);return}let s=this.db.columns,c=s.findIndex(e=>e.id===t.id),l=[{id:`rename`,label:r.rename,icon:`pencil`,run:()=>this.renameColumn(t)}];t.type!==`title`&&l.push({id:`type`,label:r.type,icon:Gz[t.type],children:HR.map(n=>({id:n,label:NR(r,n),icon:n===t.type?`check`:Gz[n],run:()=>{i.changeType(t.id,n),(n===`relation`||n===`rollup`)&&queueMicrotask(()=>this.linkSettings(e,t.id))}}))}),t.type===`relation`&&l.push({id:`relationTo`,label:r.relationTo,icon:`relation`,run:()=>this.linkSettings(e,t.id)}),t.type===`rollup`&&l.push({id:`rollup`,label:r.rollupSettings,icon:`rollup`,run:()=>this.linkSettings(e,t.id)}),l.push(o(!1),o(!0),{id:`filter`,label:r.filterBy,icon:`filter`,run:()=>{i.updateView(a.id,{filters:[...a.filters,{column:t.id,op:az(t.type)[0]}]}),this.buttons.filter.click()}}),t.type!==`title`&&l.push({id:`hide`,label:r.hide,icon:`close`,run:()=>i.updateView(a.id,{hidden:[...a.hidden,t.id]})}),l.push({id:`left`,label:r.insertLeft,icon:`plus`,run:()=>this.insertColumn(c)},{id:`right`,label:r.insertRight,icon:`plus`,run:()=>this.insertColumn(c+1)}),c>0&&l.push({id:`moveLeft`,label:r.moveLeft,icon:`arrow-up`,run:()=>i.moveColumn(t.id,c-1)}),ci.moveColumn(t.id,c+1)}),t.type!==`title`&&l.push({id:`duplicate`,label:r.duplicate,icon:`copy`,run:()=>i.duplicateColumn(t.id,`${t.name} 2`)},{id:`delete`,label:r.deleteColumn,icon:`trash`,danger:!0,run:()=>i.deleteColumn(t.id)}),Kj(e,l,t.name||NR(r,t.type))}linkSettings(e,t){let n=this.db.columns.find(e=>e.id===t),r=e.isConnected?e:this.dom.querySelector(`[data-col="${t}"]`)??this.dom;n?.type===`relation`?Vz(this.ctx(),r,n):n?.type===`rollup`&&Uz(this.ctx(),r,n)}insertColumn(e){let t=this.host.store;if(!t)return;let n=t.addColumn(`text`,this.labels.typeText,e);queueMicrotask(()=>{let e=this.db.columns.find(e=>e.id===n);e&&this.renameColumn(e)})}addColumnMenu(e){let t=this.labels;Kj(e,HR.map(e=>({id:e,label:NR(t,e),icon:Gz[e],run:()=>{let n=this.host.store?.addColumn(e,NR(t,e));queueMicrotask(()=>{let e=this.db.columns.find(e=>e.id===n);e&&this.renameColumn(e)})}})),t.addColumn)}renameColumn(e){let t=this.body.querySelector(`th[data-col="${CSS.escape(e.id)}"]`),n=this.host.store;if(!n)return;if(!t){let t=window.prompt(this.labels.columnName,e.name)?.trim();t&&n.renameColumn(e.id,t);return}let r=this.ctx();r.setEditing(!0);let i=Pz(e.name,{class:`dw-db-t__name-input`,label:this.labels.columnName,onCommit:t=>{t.trim()&&t.trim()!==e.name&&n.renameColumn(e.id,t.trim()),r.setEditing(!1),this.drawBody()},onCancel:()=>{r.setEditing(!1),this.drawBody()}});t.replaceChildren(i),i.focus(),i.select()}tableRow(e,t,n){let r=this.labels,i=I(`tr`,{dataset:{row:e.id},class:this.picked.has(e.id)?`is-picked`:``}),a=I(`td`,{class:`dw-db-t__gutter`});if(this.editable){let t=I(`input`,{type:`checkbox`,class:`dw-db-t__pick`,"aria-label":r.selectRow,checked:this.picked.has(e.id)});if(t.addEventListener(`change`,()=>{t.checked?this.picked.add(e.id):this.picked.delete(e.id),i.classList.toggle(`is-picked`,t.checked),this.drawBulk()}),a.append(t),n){let t=I(`span`,{class:`dw-db-t__grip`,draggable:!0,title:r.dragRow,"aria-hidden":`true`},kz(`grip`,14));t.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`),t.dataTransfer?.setDragImage(i,0,0)}),a.append(t),i.addEventListener(`dragover`,e=>{if(!e.dataTransfer?.types.includes(`application/x-docwell-row`))return;e.preventDefault();let t=e.clientY>i.getBoundingClientRect().top+i.offsetHeight/2;i.classList.toggle(`is-drop-below`,t),i.classList.toggle(`is-drop-above`,!t)}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop-below`,`is-drop-above`)),i.addEventListener(`drop`,t=>{let n=i.classList.contains(`is-drop-below`);i.classList.remove(`is-drop-below`,`is-drop-above`);let r=t.dataTransfer?.getData(`application/x-docwell-row`);r&&r!==e.id&&this.host.store&&(t.preventDefault(),this.moveRowBeside(r,e.id,n))});let n=null,o=()=>n?.classList.remove(`is-drop-below`,`is-drop-above`),s=e=>{let t=e?.closest(`tr[data-row]`);return t&&t.parentElement===i.parentElement&&t!==i?t:null},c=(e,t)=>t>e.getBoundingClientRect().top+e.offsetHeight/2;BB(t,{source:i,ghost:()=>I(`div`,{class:`dw-db-ghost--row`},iz(e,ZR(this.db))||r.untitledRow),over:(e,t,r)=>{o(),n=s(e),n&&n.classList.add(c(n,r)?`is-drop-below`:`is-drop-above`)},drop:(t,n,r)=>{let i=s(t);i?.dataset.row&&this.moveRowBeside(e.id,i.dataset.row,c(i,r))},end:o,hold:()=>this.rowMenu(i,e)})}}i.append(a);for(let n of t){let t=I(`td`,{dataset:{col:n.id},class:`dw-db-t__cell dw-db-t__cell--${n.type}`,role:`gridcell`},Zz(this.ctx(),e,n));if(n.type===`title`){let n=I(`button`,{type:`button`,class:`dw-db-t__open`,title:r.openRow},kz(`open`,13),I(`span`,{},r.openRow));n.addEventListener(`click`,t=>{t.stopPropagation(),this.openRow(e.id)}),t.append(n)}t.addEventListener(`mousedown`,t=>{t.target.closest(`input, button, a`)||(this.anchor=t.shiftKey&&this.sel?this.anchor??this.sel:null,this.sel={row:e.id,col:n.id},t.shiftKey||(this.anchor=null),this.markSelection(),t.preventDefault(),this.grid?.focus({preventScroll:!0}))});let a=!1;t.addEventListener(`pointerdown`,e=>a=e.pointerType===`touch`),t.addEventListener(`click`,e=>{e.target.closest(`input, button, a`)||e.shiftKey||(n.type===`checkbox`||a)&&this.startEdit()}),t.addEventListener(`dblclick`,()=>this.startEdit()),i.append(t)}return this.editable&&i.append(I(`td`,{class:`dw-db-t__add`})),i.addEventListener(`contextmenu`,t=>{(this.editable||this.host.copyLink)&&(t.preventDefault(),this.rowMenu(i,e))}),i}moveRowBeside(e,t,n){let r=this.host.store;if(!r||e===t)return;let i=r.rowIndex(e),a=r.rowIndex(t)+ +!!n;ithis.openRow(t.id)}];if(i&&a.push({id:`link`,label:n.copyLink,icon:`link`,run:()=>i(t.id)}),r){let e=r.rowIndex(t.id);a.push({id:`above`,label:n.insertAbove,icon:`arrow-up`,run:()=>r.addRow({},e)},{id:`below`,label:n.insertBelow,icon:`arrow-down`,run:()=>r.addRow({},e+1)},{id:`duplicate`,label:n.duplicateRow,icon:`copy`,run:()=>r.duplicateRow(t.id)},{id:`delete`,label:n.deleteRow,icon:`trash`,danger:!0,run:()=>r.deleteRows([t.id])})}Kj(e,a,n.openRow)}range(){if(!this.sel)return null;let e=e=>this.tableRows.findIndex(t=>t.id===e),t=e=>this.tableCols.findIndex(t=>t.id===e),n=this.anchor??this.sel,[r,i,a,o]=[e(n.row),e(this.sel.row),t(n.col),t(this.sel.col)];if(i<0||o<0)return null;let s=r<0?i:r,c=a<0?o:a;return{r0:Math.min(s,i),r1:Math.max(s,i),c0:Math.min(c,o),c1:Math.max(c,o)}}markSelection(){if(!this.grid)return;for(let e of this.grid.querySelectorAll(`.is-selected, .is-in-range`))e.classList.remove(`is-selected`,`is-in-range`);let e=this.range();if(!e||!this.sel)return;for(let t=e.r0;t<=e.r1;t++)for(let n=e.c0;n<=e.c1;n++)this.cellEl(this.tableRows[t].id,this.tableCols[n].id)?.classList.add(`is-in-range`);let t=this.cellEl(this.sel.row,this.sel.col);t?.classList.add(`is-selected`),t?.scrollIntoView({block:`nearest`,inline:`nearest`})}cellEl(e,t){return this.grid?.querySelector(`tr[data-row="${CSS.escape(e)}"] td[data-col="${CSS.escape(t)}"]`)??null}startEdit(e){if(!this.sel||!this.host.store)return;let t=this.db.rows.find(e=>e.id===this.sel.row),n=this.db.columns.find(e=>e.id===this.sel.col),r=this.cellEl(this.sel.row,this.sel.col);t&&n&&r&&Qz(this.ctx(),r,t,n,{initial:e,onDone:e=>{e&&this.moveSel(+(e===`down`),e===`right`?1:e===`left`?-1:0,!1),this.drawBody(),this.grid?.focus({preventScroll:!0})}})}moveSel(e,t,n){let r=this.tableRows,i=this.tableCols;if(!r.length||!i.length)return;if(!this.sel)return this.sel={row:r[0].id,col:i[0].id},this.markSelection();this.anchor=n?this.anchor??{...this.sel}:null;let a=Math.max(0,Math.min(r.length-1,r.findIndex(e=>e.id===this.sel.row)+e)),o=Math.max(0,Math.min(i.length-1,i.findIndex(e=>e.id===this.sel.col)+t));this.sel={row:r[a].id,col:i[o].id},this.markSelection()}onGridKey(e){if(e.target.closest(`input, select, textarea`))return;let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()===`z`)return e.preventDefault(),e.shiftKey?this.host.redo():this.host.undo();if(t&&e.key.toLowerCase()===`y`)return e.preventDefault(),this.host.redo();if(t)return;let n={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(n)return e.preventDefault(),this.moveSel(n[0],n[1],e.shiftKey);if(this.sel){if(e.key===`Tab`)return e.preventDefault(),this.moveSel(0,e.shiftKey?-1:1,!1);if(e.key===`Escape`)this.sel=null,this.anchor=null,this.markSelection();else{if(e.key===`Enter`||e.key===`F2`)return e.preventDefault(),this.startEdit();if(e.key===` `)return e.preventDefault(),this.db.columns.find(e=>e.id===this.sel.col)?.type===`title`?this.openRow(this.sel.row):this.startEdit();if((e.key===`Delete`||e.key===`Backspace`)&&this.host.store){e.preventDefault();let t=this.range();if(!t)return;let n=[];for(let e=t.r0;e<=t.r1;e++)for(let r=t.c0;r<=t.c1;r++){let t=this.tableCols[r];!qz.includes(t.type)&&!vz(t)&&n.push({row:this.tableRows[e].id,col:t.id,value:null})}this.host.store.setCells(n)}else if(e.key.length===1&&this.host.store){let t=this.db.columns.find(e=>e.id===this.sel.col);t&&(Kz.includes(t.type)||t.type===`select`||t.type===`multiSelect`)&&(e.preventDefault(),this.startEdit(e.key))}}}}onCopy(e){if(e.target.closest(`input, textarea`))return;let t=this.range();if(!t||!e.clipboardData)return;e.preventDefault();let n=[];for(let e=t.r0;e<=t.r1;e++){let r=[];for(let n=t.c0;n<=t.c1;n++)r.push(iz(this.tableRows[e],this.tableCols[n]));n.push(r)}e.clipboardData.setData(`text/plain`,SB(n,` `)),this.host.notify?.(LR(this.labels.copyNotice,(t.r1-t.r0+1)*(t.c1-t.c0+1)))}onPaste(e){if(e.target.closest(`input, textarea`))return;let t=this.host.store,n=e.clipboardData?.getData(`text/plain`);if(!t||!n||!this.sel)return;e.preventDefault();let r=bB(n.replace(/\r?\n$/,``),(n.includes(` `),` `)),i=this.tableRows.findIndex(e=>e.id===this.sel.row),a=this.tableCols.findIndex(e=>e.id===this.sel.col);if(i<0||a<0)return;let o=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),s=[],c=[];r.forEach((e,t)=>{let n=this.tableRows[i+t],r={};e.forEach((e,t)=>{let i=this.tableCols[a+t];if(!i||qz.includes(i.type)||vz(i))return;let c=TB(e,i,o.get(i.id)??[]);n?s.push({row:n.id,col:i.id,value:c}):c!==null&&(r[i.id]=c)}),n||c.push(r)}),t.tx(()=>{for(let e of this.db.columns){let n=o.get(e.id);n&&n.length!==(e.options?.length??0)&&t.setOptions(e.id,n)}t.setCells(s),c.length&&t.addRows(c)})}drawKanban(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.groupBy);if(!n){this.body.replaceChildren(I(`p`,{class:`dw-db__empty`},t.noGroupColumn));return}let r=lz(this.db,e,this.search),i=dz(r,n,t.noValue,t.checked,t.unchecked),a=uz(this.db,e).filter(e=>e.type!==`title`&&e.id!==n.id),o=ZR(this.db),s=r.flatMap(e=>GB(QR(e,n))),c=I(`div`,{class:`dw-db-k`}),l=(t,r,i,a)=>{let o=this.host.store,c=this.db.rows.find(e=>e.id===t);o&&c&&o.tx(()=>{if(r!==i&&o.setCell(t,n.id,mz(c,n,r,i,s)),a&&a!==t&&!e.sorts.length){let e=o.rowIndex(t),n=o.rowIndex(a);e0)continue;let r=I(`div`,{class:`dw-db-k__cards`,dataset:{group:e.key}}),i=I(`div`,{class:`dw-db-k__head`},e.key&&n.type!==`checkbox`&&n.type!==`member`&&n.type!==`createdBy`?I(`span`,{class:`dw-db-tag`,dataset:{color:e.color??`gray`}},e.label):I(`span`,{class:`dw-db-k__label`},e.label),I(`span`,{class:`dw-db-t__count`},String(e.rows.length)));for(let t of e.rows.slice(0,this.limit)){let i=I(`div`,{class:`dw-db-k__card`,tabIndex:0,role:`button`,draggable:this.editable&&!qz.includes(n.type),dataset:{row:t.id}},I(`div`,{class:`dw-db-k__title`},Zz(this.ctx(),t,o)),a.flatMap(e=>iz(t,e)===``||e.type===`checkbox`&&QR(t,e)!==!0?[]:[I(`div`,{class:`dw-db-k__prop`,title:e.name},Zz(this.ctx(),t,e))]));if(i.addEventListener(`click`,()=>this.openRow(t.id)),i.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.openRow(t.id))}),i.addEventListener(`dragstart`,n=>{n.dataTransfer?.setData(`application/x-docwell-card`,JSON.stringify({row:t.id,from:e.key})),n.dataTransfer&&(n.dataTransfer.effectAllowed=`move`),i.classList.add(`is-dragging`)}),i.addEventListener(`dragend`,()=>i.classList.remove(`is-dragging`)),i.draggable){let n=I(`span`,{class:`dw-db-k__grip`,"aria-hidden":`true`},kz(`grip`,14));i.append(n);let r=null,a=e=>{let t=e?.closest(`.dw-db-k__cards`);return t&&c.contains(t)?t:null};BB(n,{source:i,ghost:()=>i.cloneNode(!0),over:e=>{r?.classList.remove(`is-drop`),r=a(e),r?.classList.add(`is-drop`)},drop:n=>{let r=a(n);r&&l(t.id,e.key,r.dataset.group??``,n?.closest(`.dw-db-k__card`)?.dataset.row)},end:()=>r?.classList.remove(`is-drop`)})}r.append(i)}if(this.editable){let i=I(`button`,{type:`button`,class:`dw-db-t__new`},kz(`plus`,14),I(`span`,{},t.newRow));i.addEventListener(`click`,()=>{let t={id:``,cells:{},createdAt:0,createdBy:null};this.addRow(e.key||n.type===`checkbox`?{[n.id]:mz(t,n,``,e.key,s)}:{},!0)}),r.append(i),r.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-card`)&&(e.preventDefault(),r.classList.add(`is-drop`))}),r.addEventListener(`dragleave`,e=>{r.contains(e.relatedTarget)||r.classList.remove(`is-drop`)}),r.addEventListener(`drop`,t=>{r.classList.remove(`is-drop`);let n=t.dataTransfer?.getData(`application/x-docwell-card`),i=this.host.store;if(!n||!i)return;t.preventDefault();let{row:a,from:o}=JSON.parse(n);l(a,o,e.key,t.target.closest(`.dw-db-k__card`)?.dataset.row)})}c.append(I(`section`,{class:`dw-db-k__col`,"aria-label":e.label},i,r))}this.body.replaceChildren(c)}drawCalendar(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.dateColumn);if(!n){this.body.replaceChildren(I(`p`,{class:`dw-db__empty`},t.noDateColumn));return}let r=this.editable&&n.type===`date`,{y:i,m:a}=this.month,o=_z(i,a),s=lz(this.db,e,this.search),c=new Map,l=[];for(let e of s){let t=ez(QR(e,n));t?c.set(t,[...c.get(t)??[],e]):l.push(e)}let u=ZR(this.db),d=tz(new Date),f=new Date(i,a,1).toLocaleDateString(this.host.locale,{month:`long`,year:`numeric`}),p=e=>{let t=new Date(i,a+e,1);this.month={y:t.getFullYear(),m:t.getMonth()},this.drawBody()},m=I(`div`,{class:`dw-db-c__nav`},I(`strong`,{class:`dw-db-c__month`},f),Az(`chevron-left`,t.previousMonth,()=>p(-1)),Az(`chevron-right`,t.nextMonth,()=>p(1)),Az(`calendar`,t.today,()=>{let e=new Date;this.month={y:e.getFullYear(),m:e.getMonth()},this.drawBody()},t.today)),h=o.slice(0,7).map(e=>{let[t,n,r]=e.split(`-`).map(Number);return I(`div`,{class:`dw-db-c__wd`},new Date(t,n-1,r).toLocaleDateString(this.host.locale,{weekday:`short`}))}),g=e=>{let i=I(`button`,{type:`button`,class:`dw-db-c__chip`,draggable:r,dataset:{row:e.id}},iz(e,u)||t.untitledRow);if(i.addEventListener(`click`,()=>this.openRow(e.id)),i.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row-date`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),r){let t=null,r=e=>{let t=e?.closest(`.dw-db-c__day`);return t&&this.body.contains(t)?t:null};BB(i,{source:i,ghost:()=>i.cloneNode(!0),over:e=>{t?.classList.remove(`is-drop`),t=r(e),t?.classList.add(`is-drop`)},drop:t=>{let i=r(t)?.dataset.day;i&&this.host.store?.setCell(e.id,n.id,i)},end:()=>t?.classList.remove(`is-drop`)})}return i},_=I(`div`,{class:`dw-db-c__grid`,role:`grid`},h);for(let e of o){let i=I(`div`,{class:`dw-db-c__day${Number(e.slice(5,7))===a+1?``:` is-out`}${e===d?` is-today`:``}`,role:`gridcell`,dataset:{day:e}},I(`span`,{class:`dw-db-c__num`},String(Number(e.slice(8)))),(c.get(e)??[]).map(g));if(this.editable&&n.type===`date`){let r=I(`button`,{type:`button`,class:`dw-db-c__add`,"aria-label":`${t.newRow} ${e}`,title:t.newRow},kz(`plus`,12));r.addEventListener(`click`,()=>this.addRow({[n.id]:e},!0)),i.append(r)}r&&(i.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-row-date`)&&(e.preventDefault(),i.classList.add(`is-drop`))}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop`)),i.addEventListener(`drop`,t=>{i.classList.remove(`is-drop`);let r=t.dataTransfer?.getData(`application/x-docwell-row-date`);r&&(t.preventDefault(),this.host.store?.setCell(r,n.id,e))})),_.append(i)}let v=[m,_];l.length&&v.push(I(`details`,{class:`dw-db-c__undated`},I(`summary`,{},LR(t.noDate,l.length)),I(`div`,{class:`dw-db-c__chips`},l.slice(0,this.limit).map(g)))),this.body.replaceChildren(I(`div`,{class:`dw-db-c`},v))}},WB={id:``,name:``,type:`table`,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:null,dateColumn:null,widths:{}};function GB(e){return Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`):[]}var KB=`[A-Za-z0-9]{1,32}`,qB=(e,t)=>`#r-${e}-${t}`;function JB(e){let t=RegExp(`^#?r-(${KB})-(${KB})$`).exec(e);return t?{database:t[1],row:t[2]}:null}var YB=`dw-open-record`;function XB(e,t,n,r){let i=-1;if(e.state.doc.descendants((e,n)=>i>=0?!1:(e.type.name===`database`&&e.attrs.id===t&&(i=n),!0)),i<0)return!1;let a=e.view.nodeDOM(i);if(!(a instanceof HTMLElement))return!1;let o={row:n,...r};return a.dispatchEvent(new CustomEvent(YB,{detail:o})),!!o.found}async function ZB(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}var QB=e=>(e??BR).database;function $B(e){let t=QB(e);return{tableView:t.viewTable,columnName:e=>e===`title`?t.typeTitle:NR(t,e)}}var eV=e=>xw(e).content??[];function tV(e,t){let n=[];return e.forEach(e=>{e.type.name===`database`?n.push(t(e)):e.content.size?n.push(e.copy(tV(e.content,t))):n.push(e)}),s.from(n)}function nV(e){let t=!1;return e.descendants(e=>(e.type.name===`database`&&(t=!0),!t)),t}var rV=Jp.create({name:`database`,group:`block`,atom:!0,draggable:!0,selectable:!0,addOptions(){return{labels:null,doc:void 0,readOnlyDoc:!1,undoScope:!0,files:void 0,people:void 0,me:void 0,rowExtensions:void 0,notify:void 0,recordLink:void 0,onLinkCopied:void 0,linkedPages:void 0,pages:void 0,onNavigate:void 0,recordPage:void 0}},addAttributes(){return{id:{default:``,parseHTML:e=>e.getAttribute(`data-id`)??``,renderHTML:e=>({"data-id":e.id})},data:{default:null,parseHTML:e=>{try{let t=e.getAttribute(`data-db`);return t?JSON.parse(t):null}catch{return null}},renderHTML:e=>e.data?{"data-db":JSON.stringify(e.data)}:{}}}},parseHTML(){return[{tag:`div[data-type='database']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=A(t,{"data-type":`database`});if(!e.attrs.data)return[`div`,n];let r=qR(e.attrs.data),i=r.views[0],a=r.columns.filter(e=>e.type===`title`||!i?.hidden.includes(e.id));return[`div`,n,[`p`,{},[`strong`,{},r.title||QB(this.options.labels).untitled]],[`table`,{},[`tr`,{},...a.map(e=>[`th`,{},e.name])],...r.rows.map(e=>[`tr`,{},...a.map(t=>[`td`,{},iz(e,t)])])]]},renderText({node:e}){let t=e.attrs.data?qR(e.attrs.data):null;if(!t)return``;let n=ZR(t);return[t.title,...t.rows.map(e=>iz(e,n))].filter(Boolean).join(` -`)},onCreate(){let{doc:e,readOnlyDoc:t,undoScope:n}=this.options;e&&!t&&n&&(IS.getState(this.editor.state)?.undoManager)?.addToScope(iB(e))},addCommands(){let e=e=>{let t=WR(),{doc:n,readOnlyDoc:r}=this.options;return!n||r?{id:t,data:e}:(yB(n,t,e,(e,t)=>iV(this.editor,e,t)),{id:t,data:null})};return{insertDatabase:t=>({commands:n})=>n.insertContent([{type:this.name,attrs:e(t??mB($B(this.options.labels)))},{type:`paragraph`}]),groupAsDatabase:()=>({state:t,dispatch:n,commands:r})=>{let i=sV(t.selection.$from,t.selection.$to);if(!i)return!1;if(!n)return!0;let a=QB(this.options.labels),o={id:WR(),name:a.typeTitle,type:`title`},s=[o],c=i.checks?{id:WR(),name:a.done,type:`checkbox`}:null;c&&s.push(c);let l=Date.now(),u={title:``,columns:s,rows:i.items.map((e,t)=>({id:WR(),cells:{[o.id]:e.text,...c&&e.checked?{[c.id]:!0}:{}},createdAt:l+t,createdBy:this.options.me?.()??null,body:e.rest.length?e.rest:void 0})),views:[GR(`table`,a.viewTable,s)]},d=this.type.create(e(u));return r.command(({tr:e})=>(e.replaceWith(i.from,i.to,d),e.setSelection(E.create(e.doc,i.from)),!0))}}},addKeyboardShortcuts(){return{"Mod-g":()=>this.editor.commands.groupAsDatabase()}},addProseMirrorPlugins(){let{doc:e,readOnlyDoc:t}=this.options,n=e&&!t?e:null,r=this.editor;return[new D({key:new Un(`databaseClipboard`),props:{transformCopied:t=>!e||!nV(t.content)?t:new p(tV(t.content,t=>{let n=iB(e).get(String(t.attrs.id));return n instanceof Bb?t.type.create({...t.attrs,data:vB(n,eV)}):t}),t.openStart,t.openEnd),transformPasted:e=>nV(e.content)?new p(tV(e.content,e=>{let t=WR();if(!n)return e.type.create({...e.attrs,id:t});let i=e.attrs.data?qR(e.attrs.data):null,a=iB(n).get(String(e.attrs.id)),o=i??(a instanceof Bb?vB(a,eV):mB($B(this.options.labels)));return yB(n,t,oV(o),(e,t)=>iV(r,e,t)),e.type.create({id:t,data:null})}),e.openStart,e.openEnd):e},appendTransaction:(e,t,i)=>{if(!n||!e.some(e=>e.docChanged&&!e.getMeta(FS))||!e.some(e=>e.steps.some(e=>nV(e.slice?.content??s.empty))))return null;let a=new Set,o=[];if(i.doc.descendants((e,t)=>{if(e.type.name!==`database`)return;let n=String(e.attrs.id);return n&&a.has(n)&&o.push({pos:t,node:e}),a.add(n),!1}),!o.length)return null;let c=i.tr;for(let{pos:e,node:t}of o){let i=iB(n).get(String(t.attrs.id)),a=WR();i instanceof Bb&&yB(n,a,oV(vB(i,eV)),(e,t)=>iV(r,e,t)),c.setNodeMarkup(e,void 0,{...t.attrs,id:a,data:null})}return c}})]},addNodeView(){let e=this.options;return({node:t,editor:n,getPos:r})=>{let i=t,a=e.labels??BR,o=e.doc,s=()=>n.isEditable&&!!o&&!e.readOnlyDoc,c=null,l=null,u=null,d=null,f=I(`div`,{class:`dw-db-node`}),p=()=>String(i.attrs.id),m=()=>{let e=o?iB(o).get(p()):void 0;return e instanceof Bb?e:null},h=()=>{let t=m();return t?pB(t):i.attrs.data?qR(i.attrs.data):mB($B(e.labels))},g=e=>{let t=o?iB(o).get(e):void 0;if(t instanceof Bb)return pB(t);let r=null;return n.state.doc.descendants(t=>!r&&(t.type.name===`database`&&t.attrs.id===e&&t.attrs.data&&(r=qR(t.attrs.data)),!0)),r},_=new Map,v=t=>{let n=e.linkedPages;if(!n)return null;let r=_.get(t);if(!r){let e=n.open(t),i=e.onChange(re);e.doc.on(`update`,re),r={provider:e,stop:()=>{i(),e.doc.off(`update`,re),e.destroy()}},_.set(t,r)}return r.provider},y=t=>!t||t===e.linkedPages?.self,b=new Set,x=e=>{if(y(e.page))return b.add(e.database),e.database===p()?h():g(e.database);let t=v(e.page);if(!t?.synced)return null;let n=iB(t.doc).get(e.database);return n instanceof Bb?pB(n):null},S=(e,t,n)=>{let r=[],i=e=>{for(let a of e.toArray())if(a instanceof lx){if(a.nodeName===`database`){let e=String(a.getAttribute(`id`)??``);e&&r.push({page:t,database:e,title:n(e)?.title??``})}else i(a)}};return i(e),r},C=t=>{if(!s()||!o||!y(t.page))return null;if(t.database===p())return c;let n=iB(o).get(t.database);return n instanceof Bb?new gB(o,n,()=>e.me?.()??null):null},ee={local:()=>{let e=[];return n.state.doc.descendants(t=>(t.type.name===`database`&&t.attrs.id&&t.attrs.id!==p()&&e.push({page:``,database:String(t.attrs.id),title:g(String(t.attrs.id))?.title??``}),!0)),e},searchPages:e.pages?t=>e.pages.search(t).then(e=>e.filter(e=>!y(e.id)).map(e=>({id:e.id,title:e.title}))):void 0,databasesOn:e.linkedPages?e=>new Promise(t=>{let n=v(e),r=()=>{t(S(n.doc.getXmlFragment(`default`),e,e=>{let t=iB(n.doc).get(e);return t instanceof Bb?pB(t):null}))};if(n.synced)return r();let i=setTimeout(()=>{a(),t([])},8e3),a=n.onChange(()=>{n.synced&&(clearTimeout(i),a(),r())})}):void 0,read:x,pointsHere:(t,n)=>n.database===p()?y(t.page)?y(n.page):!!e.linkedPages?.self&&n.page===e.linkedPages.self:!1,writable:e=>!!C(e),link:(e,t,n,r)=>{let i=C(e),a=e.back;if(!i||!a)return!1;let o=i.snapshot().rows.find(e=>e.id===n);if(!o)return!1;let s=Cz(o.cells[a]).filter(e=>e!==t);return r&&s.push(t),i.setCell(n,a,s.length?s:null),!0},addBack:(e,t,n)=>{let r=C(e);return r?(r.tx(()=>{let e=r.addColumn(`relation`,n);r.setRelation(e,{page:``,database:p(),back:t})}),!0):!1},openRecord:(t,r)=>{y(t.page)?XB(n,t.database,r):e.onNavigate?.(`/p/${encodeURIComponent(t.page)}${qB(t.database,r)}`)}},te=e=>{for(let t of e)if((t.path.length?[String(t.path[0])]:[...t.keysChanged??[]]).some(e=>e!==p()&&b.has(e)))return re()};o&&iB(o).observeDeep(te);let ne;function re(){clearTimeout(ne),ne=setTimeout(()=>fe(),60)}let ie=()=>Oz(h(),x,a.database),ae=()=>({labels:a.database,colorNames:a.colors,locale:a.locale,files:e.files,people:e.people,store:c,linked:ee}),oe=(t,n)=>{let r=e.rowExtensions;if(!r)return null;let i=m(),o=null;if(i&&(o=c?c.rowBody(n.id):aV(i,n.id),!o))return t.append(I(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),null;let s=new Vp({element:t,editable:!!c,extensions:r(o),content:o?void 0:{type:`doc`,content:n.body??[{type:`paragraph`}]},editorProps:{attributes:{class:`dw-prose dw-db-peek__prose`}}});return!o&&!n.body?.length&&t.replaceChildren(I(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),()=>s.destroy()},se=e.recordLink,ce=se?t=>{let n=se(qB(p(),t));ZB(n).then(t=>t&&e.onLinkCopied?.(n))}:void 0;f.addEventListener(YB,e=>{let t=e.detail,n=ie();n.rows.some(e=>e.id===t.row)&&(t.found=!0,t.container||f.scrollIntoView?.({block:`start`}),de(t.row,n.rows.map(e=>e.id),t.container?{container:t.container,onLeave:t.onClose}:void 0))});let le=e.recordPage,ue,de=(e,t,n)=>{u?.close(!1),ue=n,u=new nB({ctx:{...ae()},mountBody:oe,copyLink:ce,openPage:le&&!n?e=>le(p(),e):void 0,page:n},ie(),e,t,()=>{u=null,ue=void 0})},fe=()=>{let e=ie();d?.update(e,{store:c}),u?.update(e,{store:c})},pe=()=>{if(l?.(),l=null,c=null,!o)return;let t=m();if(!t&&s()){let a=i.attrs.data?qR(i.attrs.data):mB($B(e.labels)),s=p()?p():WR();yB(o,s,a,(e,t)=>iV(n,e,t)),queueMicrotask(()=>{let e=typeof r==`function`?r():void 0;e!==void 0&&n.state.doc.nodeAt(e)?.type.name===`database`&&n.view.dispatch(n.state.tr.setNodeMarkup(e,void 0,{...i.attrs,id:s,data:null}).setMeta(`addToHistory`,!1))}),t=iB(o).get(s)}let a=iB(o),d=e=>{if(!e.keysChanged.has(p()))return;pe(),fe();let t=u?.row;t&&ie().rows.some(e=>e.id===t)&&de(t,[t],ue)};if(a.observe(d),t){s()&&(c=new gB(o,t,()=>e.me?.()??null));let n=t,r=()=>fe();n.observeDeep(r),l=()=>{a.unobserve(d),n.unobserveDeep(r)}}else l=()=>a.unobserve(d)};pe(),d=new UB({...ae(),openRow:de,undo:()=>n.commands.undo?.(),redo:()=>n.commands.redo?.(),notify:e.notify,copyLink:ce},ie()),f.append(d.dom);let me=s(),he=()=>{s()!==me&&(me=s(),pe(),fe())};return n.on(`update`,he),n.on(`transaction`,he),{dom:f,update(e){if(e.type!==i.type)return!1;let t=e.attrs.id!==i.attrs.id;return i=e,t&&pe(),fe(),!0},ignoreMutation:()=>!0,stopEvent:e=>e.type!==`dragstart`||e.target!==f,destroy(){l?.(),clearTimeout(ne),o&&iB(o).unobserveDeep(te);for(let e of _.values())e.stop();_.clear(),u?.close(!1),d?.destroy(),n.off(`update`,he),n.off(`transaction`,he)}}}}});function iV(e,t,n){try{Sw(e.schema,{type:`doc`,content:t},n)}catch{}}function aV(e,t){let n=e.get(`rows`);if(!(n instanceof Lb))return null;for(let e of n.toArray())if(e.get(`id`)===t){let t=e.get(`body`);return t instanceof sx&&t.length?t:null}return null}function oV(e){return{...e,rows:e.rows.map(e=>({...e,id:WR()}))}}function sV(e,t){for(let t=e.depth;t>0;t--){let n=e.node(t);if([`bulletList`,`orderedList`,`taskList`].includes(n.type.name)){let r=[];return n.forEach(e=>{let t=e.firstChild,n=[];e.forEach((e,t,r)=>{r>0&&n.push(e.toJSON())}),r.push({text:t?.textContent??``,checked:!!e.attrs.checked,rest:n})}),{from:e.before(t),to:e.after(t),checks:n.type.name===`taskList`,items:r}}}if(e.depth<1)return null;let n=e.before(1),r=t.after(Math.min(1,t.depth)||1),i=[];return e.doc.nodesBetween(n,r,(e,t)=>t=r?!1:(e.isTextblock&&e.textContent.trim()&&i.push({text:e.textContent,checked:!1,rest:[]}),!e.isTextblock)),i.length>1?{from:n,to:r,checks:!1,items:i}:null}function cV(e){let t=FS.getState(e);return t?.type&&t.binding&&t.doc?t:null}function lV(e,t){let n=cV(e);if(!n||!t?.from||!t.to)return null;try{let r=e=>PS(n.doc,n.type,fy(yg(e)),n.binding.mapping),i=r(t.from),a=r(t.to);return i===null||a===null||a<=i||a>e.doc.content.size?null:{from:i,to:a}}catch{return null}}var uV=new Un(`docwellComments`);function dV(e,t,n){let r=[];for(let i of t){let t=lV(e,i.anchor);t&&r.push(vs.inline(t.from,t.to,{class:i.id===n?`dw-comment is-active`:`dw-comment`,"data-comment":i.id}))}return xs.create(e.doc,r)}var fV=Tp.create({name:`commentHighlights`,addOptions(){return{onSelect:void 0}},addProseMirrorPlugins(){let e=()=>this.options.onSelect;return[new D({key:uV,state:{init:()=>({marks:[],active:``,decos:xs.empty}),apply(e,t,n,r){let i=e.getMeta(uV);if(i)return{...i,decos:dV(r,i.marks,i.active)};if(!e.docChanged||!t.marks.length)return t;let a=e.getMeta(FS)?.isChangeOrigin;return{...t,decos:a?dV(r,t.marks,t.active):t.decos.map(e.mapping,e.doc)}}},props:{decorations:e=>uV.getState(e)?.decos??xs.empty,handleClick(t,n,r){let i=r.target?.closest?.(`[data-comment]`)?.getAttribute(`data-comment`);return i&&e()?.(i),!1}}})]}}),pV=/^(\d{4})-(\d{2})-(\d{2})$/;function mV(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function hV(e){let t=pV.exec(e);if(!t)return null;let n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return mV(n)===e?n:null}function gV(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function _V(e,t){return Math.round((t.getTime()-e.getTime())/864e5)}function vV(e,t,n=new Date){let r=hV(e);if(!r)return e;let i=t.dates,a=_V(gV(n,0),r);return a===0?i.today:a===1?i.tomorrow:a===-1?i.yesterday:new Intl.DateTimeFormat(t.locale,{month:`short`,day:`numeric`,year:r.getFullYear()===n.getFullYear()?void 0:`numeric`}).format(r)}function yV(e,t){let n=hV(e);return n?new Intl.DateTimeFormat(t.locale,{dateStyle:`full`}).format(n):e}function bV(e,t,n,r=new Date){let i=t.dates,a=e.trim().toLowerCase(),o=!1;for(let e of new Set([i.remindWord.toLowerCase(),`remind`])){if(a.startsWith(e)){o=!0,a=a.slice(e.length).trim();break}if(a.length>=3&&e.startsWith(a)){o=!0,a=``;break}}if(o&&!n)return[];let s=gV(r,0);if(!a)return o?[1,0,7].map(e=>({date:mV(gV(s,e)),remind:o})):[{date:mV(s),remind:!1},...n?[{date:mV(gV(s,1)),remind:!0}]:[]];let c=[{words:[i.today,`today`],date:s},{words:[i.tomorrow,`tomorrow`],date:gV(s,1)},{words:[i.nextWeek,`next week`],date:gV(s,7)}];o||c.push({words:[i.yesterday,`yesterday`],date:gV(s,-1)});let l=e=>new Intl.DateTimeFormat(e,{weekday:`long`});for(let e=1;e<=7;e++){let n=gV(s,e);c.push({words:[l(t.locale).format(n),l(`en`).format(n)],date:n})}let u=[];hV(a)&&u.push({date:a,remind:o});for(let e of c)e.words.some(e=>e.toLowerCase().startsWith(a))&&u.push({date:mV(e.date),remind:o});return u.filter((e,t)=>u.findIndex(t=>t.date===e.date)===t).slice(0,5)}function xV(e,t){let n=e.toLowerCase().split(` `),r=[t.dates.remindWord,`remind`,t.dates.nextWeek.split(` `)[0]??``,`next`];return n.length>1&&n.length<=3&&r.some(e=>e&&e.toLowerCase()===n[0])}var SV=Jp.create({name:`dateMention`,group:`inline`,inline:!0,atom:!0,selectable:!0,addOptions(){return{labels:void 0,me:()=>void 0,onOpen:void 0}},addAttributes(){return{date:{default:``,parseHTML:e=>e.getAttribute(`data-date`)??``,renderHTML:e=>({"data-date":e.date})},remind:{default:``,parseHTML:e=>e.getAttribute(`data-remind`)??``,renderHTML:e=>e.remind?{"data-remind":e.remind}:{}},tz:{default:``,parseHTML:e=>e.getAttribute(`data-tz`)??``,renderHTML:e=>e.tz?{"data-tz":e.tz}:{}}}},parseHTML(){return[{tag:`span[data-type="date"]`}]},renderHTML({node:e,HTMLAttributes:t}){return[`span`,A({"data-type":`date`,class:`dw-date`},t),vV(e.attrs.date,this.options.labels)]},renderText({node:e}){return vV(e.attrs.date,this.options.labels)},addNodeView(){let{labels:e,me:t,onOpen:n}=this.options;return({node:r,editor:i,getPos:a})=>{let o=r,s=document.createElement(`span`);s.dataset.type=`date`,s.className=`dw-date`,s.contentEditable=`false`,s.classList.toggle(`is-link`,!!n);let c=null,l=()=>{let t=o.attrs.date,n=o.attrs.remind,r=!!hV(t)&&t{let t=typeof a==`function`?a():void 0;t!==void 0&&i.chain().command(({tr:n})=>(n.setNodeMarkup(t,void 0,{...o.attrs,...e}),!0)).run()};return s.addEventListener(`mousedown`,r=>{c||(i.isEditable?(r.preventDefault(),c=TV(s,i,o,e,t(),u,()=>c=null,n)):n&&hV(o.attrs.date)&&(r.preventDefault(),n(o.attrs.date)))}),{dom:s,update(e){return e.type===o.type&&(o=e,l(),!0)},ignoreMutation:()=>!0,stopEvent:e=>s.contains(e.target)&&e.type!==`mousedown`,destroy(){c?.()}}}}});function CV(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone??``}catch{return``}}function wV(e,t,n,r){let i={date:n.date,remind:n.remind&&r?r:``,tz:n.remind&&r?CV():``};e.chain().focus().insertContentAt(t,[{type:`dateMention`,attrs:i},{type:`text`,text:` `}]).run()}function TV(e,t,n,r,i,a,o,s){let c=r.dates,l=document.createElement(`div`);l.className=`dw-date-pop`,l.setAttribute(`role`,`dialog`),l.setAttribute(`aria-label`,c.edit);let u=document.createElement(`input`);u.type=`date`,u.className=`dw-input`,u.value=n.attrs.date,u.setAttribute(`aria-label`,c.edit),u.addEventListener(`change`,()=>{hV(u.value)&&a({date:u.value})}),l.append(u);let d=n.attrs.remind;if(d&&d!==i){let e=document.createElement(`p`);e.className=`dw-date-pop__note`,e.textContent=c.someoneElse,l.append(e)}else if(i){let e=document.createElement(`label`);e.className=`dw-date-pop__check`;let t=document.createElement(`input`);t.type=`checkbox`,t.checked=d===i,t.addEventListener(`change`,()=>a(t.checked?{remind:i,tz:CV()}:{remind:``,tz:``})),e.append(t,document.createTextNode(c.remindMe));let n=document.createElement(`span`);n.className=`dw-date-pop__note`,n.textContent=c.reminderAt,l.append(e,n)}if(s){let e=document.createElement(`button`);e.type=`button`,e.className=`dw-date-pop__open`,e.textContent=c.openJournal??`Open journal`,e.addEventListener(`click`,()=>{let e=n.attrs.date;h(),hV(e)&&s(e)}),l.append(e)}document.body.append(l);let f=jj(e,l,()=>{Fj(e,l,{placement:`bottom-start`,strategy:`fixed`,middleware:[Mj(6),Pj(),Nj({padding:8})]}).then(({x:e,y:t})=>Object.assign(l.style,{left:`${e}px`,top:`${t}px`}))}),p=t=>{!l.contains(t.target)&&!e.contains(t.target)&&h()},m=e=>{e.key===`Escape`&&(e.preventDefault(),h(),t.commands.focus())};function h(){f(),l.remove(),document.removeEventListener(`mousedown`,p,!0),document.removeEventListener(`keydown`,m,!0),o()}return document.addEventListener(`mousedown`,p,!0),document.addEventListener(`keydown`,m,!0),u.focus(),h}function EV(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=kf(t),l=RegExp(`\\s${c}$`),u=a?`^`:``,d=r?``:c,f=RegExp(s?`${u}${c}.*?(?=\\s${d}|$)`:`${u}(?:^)?${c}[^\\s${d}]*`,`gm`),p=o.nodeBefore?.isText&&o.nodeBefore.text;if(!p)return null;let m=o.pos-p.length,h=Array.from(p.matchAll(f)).pop();if(!h||h.input===void 0||h.index===void 0)return null;let g=h.input.slice(Math.max(0,h.index-1),h.index),_=RegExp(`^[${i?.map(kf).join(``)}\0]?$`).test(g);if(i!==null&&!_)return null;let v=m+h.index,y=v+h[0].length;return s&&l.test(p.slice(y-1,y+1))&&(h[0]+=` `,y+=1),v=o.pos?{range:{from:v,to:y},query:h[0].slice(t.length),text:h[0]}:null}function DV(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,` -`);return/\s/.test(n)}):!1}function OV(e){return()=>{let t=e.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=e.view.coordsAtPos(t);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}}}function kV(e,t,n,r){return n?()=>{let n=r.getState(e.state)?.decorationId;return t.dom.querySelector(`[data-decoration-id="${n}"]`)?.getBoundingClientRect()||null}:OV(e)}function AV({match:e,dismissedRange:t,state:n,transaction:r,editor:i,shouldResetDismissed:a,effectiveAllowSpaces:o}){return a?.({editor:i,state:n,range:t,match:e,transaction:r,allowSpaces:o})?!1:o?e.range.from===t.from:e.range.from===t.from&&!DV(r)}function jV({view:e,pluginKeyRef:t}){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}function MV({pluginKey:e,decorationTag:t,decorationClass:n,decorationContent:r,decorationEmptyClass:i,renderer:a,dispatchExit:o}){return{handleKeyDown(t,n){var r;let i=e.getState(t.state);if(!i.active)return!1;if(n.key===`Escape`||n.key===`Esc`){var s;return a==null||(s=a.onKeyDown)==null||s.call(a,{view:t,event:n,range:i.range}),o(t),!0}return(a==null||(r=a.onKeyDown)==null?void 0:r.call(a,{view:t,event:n,range:i.range}))||!1},decorations(a){let{active:o,range:s,decorationId:c,query:l}=e.getState(a);if(!o)return null;let u=!l?.length,d=[n];return u&&d.push(i),xs.create(a.doc,[vs.inline(s.from,s.to,{nodeName:t,class:d.join(` `),"data-decoration-id":c||void 0,"data-decoration-content":r})])}}}function NV({editor:e,char:t,effectiveAllowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,findSuggestionMatch:o,allow:s,shouldShow:c,shouldKeepDismissed:l,pluginKey:u}){return{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(d,f,p,m){let{isEditable:h}=e,{composing:g}=e.view,{selection:_}=d,{empty:v,from:y}=_,b={...f},x=d.getMeta(u);if(x&&x.exit)return b.active=!1,b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null,b.dismissedRange=f.active?{...f.range}:f.dismissedRange,b;if(b.composing=g,d.docChanged&&b.dismissedRange!==null&&(b.dismissedRange={from:d.mapping.map(b.dismissedRange.from),to:d.mapping.map(b.dismissedRange.to)}),h&&(v||e.view.composing)){(yf.range.to)&&!g&&!f.composing&&(b.active=!1);let u=o({char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:_.$from}),p=`id_${Math.floor(Math.random()*4294967295)}`;u&&s({editor:e,state:m,range:u.range,isActive:f.active})&&(!c||c({editor:e,range:u.range,query:u.query,text:u.text,transaction:d}))?(b.dismissedRange!==null&&!l({match:u,dismissedRange:b.dismissedRange,state:m,transaction:d})&&(b.dismissedRange=null),b.dismissedRange===null?(b.active=!0,b.decorationId=f.decorationId||p,b.range=u.range,b.query=u.query,b.text=u.text):b.active=!1):(u||(b.dismissedRange=null),b.active=!1)}else b.active=!1;return b.active||(b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null),b}}}function PV({editor:e,items:t}){let n=null,r=null,i=null,a=()=>{r!==null&&(clearTimeout(r),r=null),i?.(),i=null},o=e=>new Promise(t=>{i=t,r=setTimeout(()=>{r=null;let e=i;i=null,e?.()},e)}),s=()=>{n?.abort(),a(),n=null};return{abort:s,fetch:async(r,i)=>{s(),n=new AbortController;let a=n;if(i>0&&await o(i),n!==a||a.signal.aborted)return{status:`aborted`};try{let i=await t({editor:e,query:r,signal:a.signal});return n!==a||a.signal.aborted?{status:`aborted`}:{status:`resolved`,items:i}}catch{return n!==a||a.signal.aborted?{status:`aborted`}:{status:`error`}}}}}function FV({placement:e,offset:t,flip:n,floatingUi:r}){var i;let a=[Mj({mainAxis:t.mainAxis??4,crossAxis:t.crossAxis??0})];return n&&a.push(Pj()),r!=null&&(i=r.middleware)!=null&&i.length&&a.push(...r.middleware),{placement:e,strategy:r?.strategy??`absolute`,middleware:a}}function IV(e){if(e instanceof HTMLElement)return e;if(typeof e==`string`)try{let t=document.querySelector(e);if(t)return t}catch{return document.body}return document.body}function LV({getReferenceRect:e,contextElement:t,config:n,container:r,dismissOnOutsideClick:i,dismiss:a}){return(o,s={})=>{let c={getBoundingClientRect:()=>e()??new DOMRect,contextElement:t},l=!1,u=!o.isConnected;u&&IV(r).appendChild(o),s.onPosition||(o.style.visibility=`hidden`,o.style.width=`max-content`);let d=jj(c,o,()=>{Fj(c,o,{placement:n.placement,strategy:n.strategy,middleware:n.middleware}).then(({x:e,y:t,placement:n,strategy:r})=>{s.onPosition?s.onPosition({x:e,y:t,placement:n,strategy:r}):(Object.assign(o.style,{position:r,left:`${e}px`,top:`${t}px`}),l||(l=!0,o.style.visibility=``))})},s.autoUpdate),f;return i&&(f=e=>{let n=e.target;!(n instanceof Node)||o.contains(n)||t.contains(n)||a()},document.addEventListener(`pointerdown`,f,!0)),()=>{d(),f&&document.removeEventListener(`pointerdown`,f,!0),u&&o.remove()}}}function RV({editor:e,pluginKey:t,items:n,renderer:r,minQueryLength:i,debounce:a,initialItems:o,placement:s,offset:c,container:l,flip:u,floatingUi:d,dismissOnOutsideClick:f,command:p,clientRectFor:m,dispatchExit:h}){let g,_=PV({editor:e,items:n}),v=FV({placement:s,offset:c,flip:u,floatingUi:d});function y(e,t){switch(e){case`started`:var n;r==null||(n=r.onStart)==null||n.call(r,t);break;case`updated`:var i;r==null||(i=r.onUpdate)==null||i.call(r,t);break;case`stopped`:var a;r==null||(a=r.onExit)==null||a.call(r,t)}}return{update:async(n,d)=>{let b=t.getState(d),x=t.getState(n.state);if(!b||!x)return;let S=null,C=b.query!==x.query,ee=b.text!==x.text,te=b.range.from!==x.range.from||b.range.to!==x.range.to,ne=C||ee||te;if(!b.active&&x.active)S=`started`;else if(b.active&&!x.active)S=`stopped`;else if(x.active&&ne)S=`updated`;else return;let re=S===`stopped`?b:x,ie=n.dom.querySelector(`[data-decoration-id="${re.decorationId}"]`),ae=m(n,ie),oe=i===0||(re.query?re.query.length>=i:!1),se=(S===`started`||S===`updated`)&&oe;if(g={editor:e,range:re.range,query:re.query||``,text:re.text||``,items:o??[],command:t=>p({editor:e,range:re.range,props:t}),decorationNode:ie,clientRect:ae,loading:se,placement:s,offset:{mainAxis:c.mainAxis??4,crossAxis:c.crossAxis??0},container:l,flip:u,floatingUi:v,mount:LV({getReferenceRect:ae,contextElement:n.dom,config:v,container:l,dismissOnOutsideClick:f,dismiss:()=>h(e.view)})},S===`started`){var ce;r==null||(ce=r.onBeforeStart)==null||ce.call(r,g)}if(S===`updated`){var le;r==null||(le=r.onBeforeUpdate)==null||le.call(r,g)}if(S===`started`&&y(S,g),S===`started`||S===`updated`){if(!se)_.abort(),g={...g,items:o??[],loading:!1};else{g={...g,items:o??[],loading:!0},S=`updated`,y(S,g);let e=await _.fetch(re.query||``,a);if(e.status===`aborted`)return;if(!t.getState(n.state)?.active){_.abort();return}g=e.status===`resolved`?{...g,items:e.items,loading:!1}:{...g,loading:!1}}}S===`stopped`?(_.abort(),y(S,g),g=void 0):S===`updated`&&y(S,g)},destroy:()=>{var e;_.abort(),g&&(r==null||(e=r.onExit)==null||e.call(r,g))}}}var zV=new Un(`suggestion`);function BV({pluginKey:e=zV,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],minQueryLength:p=0,debounce:m=0,initialItems:h,placement:g=`bottom-start`,offset:_={},container:v,flip:y=!0,floatingUi:b,dismissOnOutsideClick:x=!0,render:S=()=>({}),allow:C=()=>!0,findSuggestionMatch:ee=EV,shouldShow:te,shouldResetDismissed:ne}){let re=S?.(),ie=r&&!i,ae=(n,r)=>kV(t,n,r,e);function oe(e){return AV({...e,editor:t,shouldResetDismissed:ne,effectiveAllowSpaces:ie})}let se=t=>jV({view:t,pluginKeyRef:e});return new D({key:e,view:()=>RV({editor:t,pluginKey:e,items:f,renderer:re,minQueryLength:p,debounce:m,initialItems:h,placement:g,offset:_,container:v,flip:y,floatingUi:b,dismissOnOutsideClick:x,command:d,clientRectFor:ae,dispatchExit:se}),state:NV({editor:t,char:n,effectiveAllowSpaces:ie,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,findSuggestionMatch:ee,allow:C,shouldShow:te,shouldKeepDismissed:oe,pluginKey:e}),props:MV({pluginKey:e,decorationTag:s,decorationClass:c,decorationContent:l,decorationEmptyClass:u,renderer:re,dispatchExit:se})})}var VV=BV,HV=e=>`/p/${encodeURIComponent(e)}`,UV=/^\/p\/([A-Za-z0-9_-]+)\/?(?:[?#].*)?$/;function WV(e){return UV.exec(e)?.[1]??``}function GV(e,t,n,r=`Untitled`){let i=`${n.icon?`${n.icon} `:``}${n.title||r}`;e.chain().focus().deleteRange(t).insertContent([{type:`text`,text:i,marks:[{type:`link`,attrs:{href:HV(n.id)}}]},{type:`text`,text:` `}]).run()}async function KV(e,t,n){if(!t.create)return;let{from:r,to:i,empty:a}=e.state.selection,o=a?``:e.state.doc.textBetween(r,i,` `).trim().slice(0,200),s=await t.create(o);a||!o?GV(e,{from:r,to:r},s,n):e.chain().focus().setTextSelection({from:r,to:i}).setLink({href:HV(s.id)}).run()}var qV=Tp.create({name:`pageLinks`,addOptions(){return{host:void 0,labels:null,onNavigate:void 0}},addProseMirrorPlugins(){let{host:e,onNavigate:t}=this.options,n=this.options.labels,r=[];return e&&r.push(VV({editor:this.editor,pluginKey:new Un(`pageLinks`),char:`[[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Uj({label:n.pageLinks,empty:n.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>GV(e.editor,e.range,t)})})),t&&r.push(new D({key:new Un(`pageLinkClicks`),props:{handleClick:(e,n,r)=>{let i=(r.target?.closest?.(`a[href]`))?.getAttribute(`href`)??``;return!WV(i)||e.editable&&!(r.ctrlKey||r.metaKey)?!1:(r.preventDefault(),t(i),!0)}}})),r}});function JV(e,t,n){e.chain().focus().deleteRange(t).insertSyncedPage(n).run()}var YV=Jp.create({name:`syncedPage`,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,pages:void 0,labels:null,onNavigate:void 0,nested:void 0}},addAttributes(){return{page:{default:``,parseHTML:e=>e.getAttribute(`data-page`)??``,renderHTML:e=>({"data-page":e.page})},title:{default:``,parseHTML:e=>e.getAttribute(`data-title`)??``,renderHTML:e=>e.title?{"data-title":e.title}:{}},icon:{default:``,parseHTML:e=>e.getAttribute(`data-icon`)??``,renderHTML:e=>e.icon?{"data-icon":e.icon}:{}},folded:{default:!1,parseHTML:e=>e.hasAttribute(`data-folded`),renderHTML:e=>e.folded?{"data-folded":``}:{}}}},parseHTML(){return[{tag:`div[data-type='syncedPage']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=`${e.attrs.icon?`${e.attrs.icon} `:``}${e.attrs.title||`…`}`;return[`div`,A(t,{"data-type":`syncedPage`}),[`a`,{href:HV(String(e.attrs.page))},n]]},addCommands(){return{insertSyncedPage:e=>({commands:t})=>t.insertContent([{type:this.name,attrs:{page:e.id,title:e.title,icon:e.icon??``}},{type:`paragraph`}])}},addProseMirrorPlugins(){let{pages:e}=this.options,t=this.options.labels;return e?[VV({editor:this.editor,pluginKey:new Un(`syncedPages`),char:`![[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Uj({label:t.blocks.syncedPage,empty:t.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>JV(e.editor,e.range,t)})})]:[]},addNodeView(){let{host:e,onNavigate:t,nested:n}=this.options,r=this.options.labels.blocks;return({node:i,editor:a,getPos:o})=>{let s=i,c=String(s.attrs.page),l=document.createElement(`div`);l.className=`dw-synced`,l.dataset.type=`syncedPage`,l.contentEditable=`false`;let u=document.createElement(`div`);u.className=`dw-synced__head`;let d=document.createElement(`a`);d.className=`dw-synced__title`,d.href=HV(c);let f=Hj(`copy`,14);f.classList.add(`dw-synced__badge`);let p=document.createElement(`button`);p.type=`button`,p.className=`dw-synced__btn`;let m=document.createElement(`button`);m.type=`button`,m.className=`dw-synced__btn`,m.textContent=r.syncedOpen,u.append(f,d,p,m);let h=document.createElement(`div`);h.className=`dw-synced__body`,l.append(u,h);let g=e=>{e.preventDefault(),t?t(HV(c)):window.location.assign(HV(c))};d.addEventListener(`click`,g),m.addEventListener(`click`,g);let _=e=>{let t=typeof o==`function`?o():void 0;t!==void 0&&a.view.dispatch(a.state.tr.setNodeMarkup(t,void 0,{...s.attrs,...e}))},v=null,y=()=>v??!!s.attrs.folded;p.addEventListener(`click`,()=>{a.isEditable?_({folded:!s.attrs.folded}):(v=!y(),ne())});let b=null,x=null,S=null,C=e=>{let t=document.createElement(`p`);t.className=`dw-synced__note`,t.textContent=e,h.replaceChildren(t)},ee=()=>{S?.(),x?.destroy(),b?.destroy(),S=null,x=null,b=null},te=()=>{if(x||!e||!n)return;if(c===e.self)return C(r.syncedSelf);b=e.open(c),C(r.syncedLoading);let t=b,i=()=>{t.status===`denied`?(ee(),C(r.syncedDenied)):t.synced&&!x&&(h.replaceChildren(),x=new Vp({element:h,editable:!1,extensions:n(t.doc),editorProps:{attributes:{class:`dw-prose`}}}))};S=t.onChange(i),i()};function ne(){let t=s.attrs.title;d.textContent=`${s.attrs.icon?`${s.attrs.icon} `:``}${t||r.syncedPage}`;let n=y();l.classList.toggle(`is-folded`,n),p.textContent=n?r.syncedUnfold:r.syncedFold,p.setAttribute(`aria-expanded`,String(!n)),n?(ee(),h.replaceChildren()):e?te():h.replaceChildren()}return ne(),e?.meta(c).then(e=>{e?a.isEditable&&(e.title!==s.attrs.title||e.icon!==s.attrs.icon)?_({title:e.title,icon:e.icon}):d.textContent=`${e.icon?`${e.icon} `:``}${e.title||r.syncedPage}`:y()||C(r.syncedDenied)}),{dom:l,update(e){return e.type!==s.type||String(e.attrs.page)!==c?!1:(s=e,ne(),!0)},ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof globalThis.Node&&(u.contains(e.target)||h.contains(e.target)),destroy:ee}}}});function XV(e){let t=document.createElement(`div`);t.className=`dw-diagram-editor`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`),t.setAttribute(`aria-label`,e);let n=document.createElement(`p`);n.className=`dw-diagram-editor__status`,t.append(n),document.body.append(t);let r=document.body.style.overflow;return document.body.style.overflow=`hidden`,{root:t,status:e=>{n.textContent=e,n.hidden=!e},close:()=>{t.remove(),document.body.style.overflow=r}}}async function ZV(e,t){let n=await fetch(e.resolve(t));if(!n.ok)throw Error(`loading the drawing failed (${n.status})`);return n.text()}function QV(e,t){return new File([e],t,{type:`image/svg+xml`})}function $V(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n)}function eH(e,t,n){return new Promise(r=>{let i=XV(n.slash.drawio?.label??`Draw.io`),a=document.createElement(`iframe`),o=new URL(e);for(let[e,t]of Object.entries({embed:`1`,proto:`json`,spin:`1`,saveAndExit:`1`,noExitBtn:`0`}))o.searchParams.set(e,t);a.src=o.toString(),a.className=`dw-diagram-editor__frame`,a.title=n.slash.drawio?.label??`Draw.io`;let s=document.createElement(`div`);s.className=`dw-diagram-editor__bar`;let c=document.createElement(`button`);c.type=`button`,c.className=`dw-source__btn`,c.textContent=n.blocks.cancel,c.addEventListener(`click`,()=>d(null)),s.append(c),i.root.append(s,a),i.status(``);let l=e=>a.contentWindow?.postMessage(JSON.stringify(e),o.origin),u=!1,d=e=>{window.removeEventListener(`message`,f),i.close(),r(e)},f=e=>{if(e.source!==a.contentWindow||e.origin!==o.origin||typeof e.data!=`string`)return;let n;try{n=JSON.parse(e.data)}catch{return}switch(n.event){case`init`:l({action:`load`,autosave:0,xml:t?`data:image/svg+xml;base64,${$V(t)}`:``});break;case`save`:u=!0,l({action:`export`,format:`xmlsvg`,spinKey:`saving`});break;case`export`:{let e=n.data??``,t=e.indexOf(`,`),r=e.slice(0,t),i=e.slice(t+1),a=r.includes(`;base64`)?new TextDecoder().decode(Uint8Array.from(atob(i),e=>e.charCodeAt(0))):decodeURIComponent(i);d(u?a:null);break}case`exit`:d(null)}};window.addEventListener(`message`,f)})}async function tH(e,t,n){let r=XV(n.slash.excalidraw?.label??`Excalidraw`);r.status(``);try{let{openExcalidraw:i}=await e();return await i(r.root,t,n)}finally{r.close()}}var nH=!1;function rH(e){return Jp.create({name:e,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,loadExcalidraw:void 0,labels:null,drawioUrl:void 0,onError:void 0}},addAttributes(){return{src:{default:``},alt:{default:``}}},parseHTML(){return[{tag:`figure[data-type='${e}']`,getAttrs:e=>({src:e.querySelector(`img`)?.getAttribute(`src`)??``})}]},renderHTML({node:t,HTMLAttributes:n}){return[`figure`,A(n,{"data-type":e}),[`img`,{src:String(t.attrs.src),alt:String(t.attrs.alt||e)}]]},addCommands(){return{insertDiagram:e=>({commands:t})=>(nH=!0,t.insertContent({type:e,attrs:{src:``}}))}},addNodeView(){return({node:t,editor:n,getPos:r})=>{let i=this.options,a=i.labels,o=document.createElement(`figure`);o.className=`dw-diagram dw-diagram--${e}`,o.setAttribute(`data-type`,e);let s=document.createElement(`img`);s.className=`dw-diagram__img`;let c=document.createElement(`p`);c.className=`dw-diagram__empty`,c.textContent=e===`drawio`?a.blocks.emptyDrawio:a.blocks.emptyExcalidraw;let l=document.createElement(`button`);l.type=`button`,l.className=`dw-diagram__edit`,l.textContent=a.blocks.edit,o.append(s,c,l);let u=``,d=t=>{u=String(t.attrs.src??``),s.hidden=!u,c.hidden=!!u,u&&(s.src=i.host?i.host.resolve(u):u,s.alt=String(t.attrs.alt||a.slash[e]?.label||e))};d(t);let f=!1,p=async()=>{if(!f&&m()&&i.host?.upload){f=!0;try{let t=u?await ZV(i.host,u):``,o=e===`drawio`?await eH(i.drawioUrl||`https://embed.diagrams.net`,t,a):await tH(i.loadExcalidraw,t,a);if(o===null)return;let s=await i.host.upload(QV(o,`${e===`drawio`?`diagram.drawio`:`drawing.excalidraw`}.svg`)),c=typeof r==`function`?r():void 0;c!==void 0&&iH(n,c,e,s.url)}catch(e){i.onError?.(e)}finally{f=!1}}},m=()=>n.isEditable&&!!i.host?.upload&&(e===`drawio`||!!i.loadExcalidraw),h=()=>l.hidden=!m()||!u;return h(),n.on(`update`,h),o.addEventListener(`dblclick`,()=>void p()),c.addEventListener(`click`,()=>void p()),l.addEventListener(`click`,()=>void p()),nH&&(nH=!1,queueMicrotask(()=>void p())),{dom:o,update:t=>t.type.name===e&&(d(t),h(),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target===l||e.target===c,destroy:()=>n.off(`update`,h)}}}})}function iH(e,t,n,r){e.chain().setNodeSelection(t).updateAttributes(n,{src:r}).run()}var aH=rH(`drawio`),oH=rH(`excalidraw`),sH=null;function cH(e){sH?.();let t=document.createElement(`div`);t.className=`dw-source`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-label`,e.label);let n=document.createElement(e.multiline?`textarea`:`input`);n.className=`dw-source__field`+(e.monospace?` dw-source__field--mono`:``),n.value=e.value,n.setAttribute(`aria-label`,e.label),n.spellcheck=!1,n instanceof HTMLTextAreaElement&&(n.rows=Math.min(16,Math.max(4,e.value.split(` -`).length+1)));let r=document.createElement(`div`);r.className=`dw-source__actions`;let i=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`dw-source__btn ${t}`,r.textContent=e,r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`click`,n),r};e.onRemove&&r.append(i(e.labels.remove,`dw-source__btn--danger`,()=>{u(!0),e.onRemove()}));let a=document.createElement(`span`);a.style.flex=`1`,r.append(a,i(e.labels.cancel,``,()=>u()),i(e.labels.done,`dw-source__btn--primary`,()=>o())),t.append(n,r),document.body.append(t);let o=()=>{let t=n.value;u(!0),e.onSave(t)};n.addEventListener(`input`,()=>e.onInput?.(n.value)),n.addEventListener(`keydown`,t=>{let n=t;n.key===`Escape`?(n.preventDefault(),u()):n.key===`Enter`&&(n.ctrlKey||n.metaKey||!e.multiline)&&(n.preventDefault(),o()),n.stopPropagation()});let s=n=>{!t.contains(n.target)&&!e.anchor.contains(n.target)&&u()};setTimeout(()=>document.addEventListener(`mousedown`,s),0);let c=jj(e.anchor,t,()=>{Fj(e.anchor,t,{placement:`bottom-start`,middleware:[Mj(6),Pj(),Nj({padding:8})]}).then(({x:e,y:n})=>Object.assign(t.style,{left:`${e}px`,top:`${n}px`}))}),l=!1;function u(n=!1){l||(l=!0,c(),document.removeEventListener(`mousedown`,s),t.remove(),sH===d&&(sH=null),n||e.onCancel?.())}let d=()=>u();return sH=d,n.focus(),e.multiline||n.select(),d}var lH={open:`green`,started:`yellow`,draft:`gray`,merged:`purple`,done:`blue`,closed:`red`,canceled:`gray`},uH=[{pattern:/^https:\/\/(?:www\.|m\.)?youtube\.com\/(?:watch\?(?:.*&)?v=|shorts\/|embed\/|live\/)([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/youtu\.be\/([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?vimeo\.com\/(?:video\/)?(\d+)/,src:e=>`https://player.vimeo.com/video/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/([\da-f]{32})/,src:e=>`https://www.loom.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?figma\.com\/(?:file|design|proto|board|slides)\/[\w-]+/,src:(e,t)=>`https://www.figma.com/embed?embed_host=docwell&url=${encodeURIComponent(t.href)}`},{pattern:/^https:\/\/codepen\.io\/([\w-]+)\/(?:pen|embed)\/([\w-]+)/,src:e=>`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result`},{pattern:/^https:\/\/open\.spotify\.com\/(?:embed\/)?(track|album|playlist|episode|show)\/(\w+)/,src:e=>`https://open.spotify.com/embed/${e[1]}/${e[2]}`,ratio:`audio`},{pattern:/^https:\/\/docs\.google\.com\/(document|spreadsheets|presentation)\/d\/([\w-]+)/,src:e=>`https://docs.google.com/${e[1]}/d/${e[2]}/preview`,ratio:`tall`},{pattern:/^https:\/\/(?:www\.)?google\.com\/maps\/embed\?/,src:(e,t)=>t.href}];function dH(e){let t;try{t=new URL(e.trim())}catch{return null}for(let e of uH){let n=e.pattern.exec(t.href);if(n)return{src:e.src(n,t),ratio:e.ratio??`video`}}return null}function fH(e){try{let t=new URL(e.trim());return t.protocol===`https:`||t.protocol===`http:`?t.href:``}catch{return``}}var pH=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}};function mH(e,t,n){let{node:r}=e.view.domAtPos(e.state.selection.from),i=r instanceof HTMLElement?r:r.parentElement??e.view.dom;return new Promise(e=>{let r=t.blocks;cH({anchor:i,value:`https://`,label:n,labels:{done:r.done,cancel:r.cancel,remove:r.remove},onSave:t=>e(fH(t)),onCancel:()=>e(``)})})}async function hH(e,t,n,r){let i=await mH(e,t,t.blocks.embedUrl);i&&(dH(i)?e.chain().focus().insertEmbed(i).run():await _H(e,i,n,r))}async function gH(e,t,n,r){let i=await mH(e,t,t.blocks.linkUrl);i&&await _H(e,i,n,r)}async function _H(e,t,n,r){let i={url:t};if(n)try{i={...await n.preview(t),url:t}}catch(e){r?.(e)}e.chain().focus().insertLinkCard(i).run()}var vH=Jp.create({name:`embed`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{url:{default:``,parseHTML:e=>e.getAttribute(`data-url`)??``,renderHTML:e=>({"data-url":e.url})}}},parseHTML(){return[{tag:`div[data-type='embed']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=fH(String(e.attrs.url));return[`div`,A(t,{"data-type":`embed`}),[`a`,{href:n},n]]},addCommands(){return{insertEmbed:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e}})}},addNodeView(){return({node:e})=>{let t=this.options.labels.blocks,n=document.createElement(`figure`);n.className=`dw-embed`,n.setAttribute(`data-type`,`embed`),n.contentEditable=`false`;let r=e=>{let r=fH(e),i=dH(r);if(n.replaceChildren(),!i){let e=document.createElement(`a`);e.href=r,e.target=`_blank`,e.rel=`noopener noreferrer`,e.textContent=r||t.embedInvalid,n.append(e);return}n.dataset.ratio=i.ratio;let a=document.createElement(`iframe`);a.className=`dw-embed__frame`,a.src=i.src,a.title=`${t.embed}: ${pH(r)}`,a.loading=`lazy`,a.allow=`fullscreen; picture-in-picture; encrypted-media; clipboard-write`,a.referrerPolicy=`strict-origin-when-cross-origin`,a.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`);let o=document.createElement(`figcaption`);o.className=`dw-embed__caption`;let s=document.createElement(`a`);s.href=r,s.target=`_blank`,s.rel=`noopener noreferrer`,s.textContent=pH(r),o.append(s),n.append(a,o)},i=String(e.attrs.url);return r(i),{dom:n,update:e=>e.type.name===`embed`&&(e.attrs.url!==i&&r(i=String(e.attrs.url)),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`)}}}}),yH=Jp.create({name:`linkCard`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){let e=e=>({default:``,parseHTML:t=>t.getAttribute(`data-${e}`)??``,renderHTML:t=>({[`data-${e}`]:t[e]})});return{url:e(`url`),title:e(`title`),description:e(`description`),image:e(`image`),site:e(`site`),kind:e(`kind`),status:e(`status`),state:e(`state`),meta:e(`meta`)}},parseHTML(){return[{tag:`div[data-type='link-card']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=fH(String(e.attrs.url));return[`div`,A(t,{"data-type":`link-card`}),[`a`,{href:n},String(e.attrs.title||n)]]},addCommands(){return{insertLinkCard:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e.url,title:e.title??``,description:e.description??``,image:e.image??``,site:e.site??``,kind:e.kind??``,status:e.status??``,state:e.state??``,meta:e.meta??``}})}},addNodeView(){return({node:e})=>{let t=document.createElement(`a`);t.className=`dw-linkcard`,t.setAttribute(`data-type`,`link-card`),t.contentEditable=`false`,t.target=`_blank`,t.rel=`noopener noreferrer`;let n=e=>{let n=fH(String(e.url));t.href=n,t.replaceChildren();let r=document.createElement(`span`);r.className=`dw-linkcard__text`;let i=document.createElement(`span`);i.className=`dw-linkcard__title`,i.textContent=String(e.title||``)||pH(n);let a=String(e.kind||``);if(t.dataset.kind=a,e.status){let t=document.createElement(`span`);t.className=`dw-linkcard__head`;let n=document.createElement(`span`);n.className=`dw-linkcard__status`,n.dataset.color=lH[String(e.state)]??`gray`,n.textContent=String(e.status),t.append(n,i),r.append(t)}else r.append(i);if(e.description){let t=document.createElement(`span`);t.className=`dw-linkcard__desc`,t.textContent=String(e.description),r.append(t)}let o=document.createElement(`span`);o.className=`dw-linkcard__site`,o.textContent=[String(e.site||``)||pH(n),String(e.meta||``)].filter(Boolean).join(` · `),r.append(o),t.append(r);let s=fH(String(e.image||``));if(s.startsWith(`https:`)){let e=document.createElement(`img`);e.className=a.startsWith(`github.`)?`dw-linkcard__image dw-linkcard__image--avatar`:`dw-linkcard__image`,e.src=s,e.alt=``,e.loading=`lazy`,e.referrerPolicy=`no-referrer`,e.onerror=()=>e.remove(),t.append(e)}},r=e;return n(e.attrs),t.addEventListener(`click`,e=>{this.editor.view.editable&&!(e.ctrlKey||e.metaKey)&&e.preventDefault()}),{dom:t,update:e=>e.type.name===`linkCard`&&(e.attrs!==r.attrs&&n(e.attrs),r=e,!0),ignoreMutation:()=>!0}}}}),bH=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,xH=Jp.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,A(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize,i=new Set([`src`,`width`,`height`]);return({node:a,getPos:o,HTMLAttributes:s,editor:c})=>{let l=document.createElement(`img`);l.draggable=!1;let u=A(this.options.HTMLAttributes,s);Object.entries(u).forEach(([e,t])=>{if(t!=null)switch(e){case`src`:case`width`:case`height`:break;default:l.setAttribute(e,t)}}),u.src!==null&&(l.src=u.src);let d={...s},f=e=>{typeof e==`string`&&e!==``?l.getAttribute(`src`)!==e&&(l.src=e):(l.hasAttribute(`src`)&&l.removeAttribute(`src`),l.src!==``&&(l.src=``))};f(s.src);let p=new qp({element:l,editor:c,node:a,getPos:o,onResize:(e,t)=>{l.style.width=`${e}px`,l.style.height=`${t}px`},onCommit:(e,t)=>{let n=o();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:e=>{if(e.type!==a.type)return!1;let t=Lu(e,c.extensionManager.attributes.filter(t=>t.type===e.type.name));return Object.keys(d).forEach(e=>{!i.has(e)&&!(e in t)&&l.removeAttribute(e)}),Object.entries(t).forEach(([e,t])=>{i.has(e)||(t==null?l.removeAttribute(e):l.setAttribute(e,t))}),f(t.src),d=t,!0},options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),m=p.dom,h=()=>{m.style.visibility=``,m.style.pointerEvents=``};return m.style.visibility=`hidden`,m.style.pointerEvents=`none`,l.complete&&l.naturalWidth>0?h():(l.onload=h,l.onerror=h),p}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[Up({find:bH,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});function SH(e,t){return/^(audio|video)\//.test(e)||/\.(mp3|mp4|mpeg|mpga|m4a|wav|webm|ogg|oga|flac|aac|opus|mov)$/i.test(t)}async function CH(e,t,n,r){if(t.upload)for(let i of n){let n=await t.upload(i),a=n.mime.startsWith(`image/`)?{type:`image`,attrs:{src:n.url,alt:n.name}}:{type:`fileAttachment`,attrs:{url:n.url,name:n.name,size:n.size,mime:n.mime,view:Rj(n.mime,n.name)?`preview`:`card`}};e.chain().focus().insertContentAt(r??e.state.selection.to,a).run(),r=void 0}}var wH=xH.extend({addOptions(){return{...this.parent(),host:void 0,inline:!1,allowBase64:!1}},addNodeView(){return({node:e})=>{let t=document.createElement(`img`),n=e=>{let n=String(e.attrs.src??``);t.src=this.options.host?this.options.host.resolve(n):n,t.alt=String(e.attrs.alt??``),e.attrs.title&&(t.title=String(e.attrs.title))};return n(e),t.draggable=!0,{dom:t,update:t=>t.type===e.type&&(n(t),!0)}}}});function TH(e){if(!e)return``;let t=[`B`,`KB`,`MB`,`GB`],n=0,r=e;for(;r>=1024&&n({editor:e,commands:t})=>{let n=e.getAttributes(this.name);return!e.isActive(this.name)||!Rj(n.mime,n.name)?!1:t.updateAttributes(this.name,{view:n.view===`preview`?`card`:`preview`})}}},parseHTML(){return[{tag:`div[data-type=file]`,getAttrs:e=>({url:e.getAttribute(`data-url`)??``,name:e.getAttribute(`data-name`)??e.textContent??`file`,size:Number(e.getAttribute(`data-size`)??0),mime:e.getAttribute(`data-mime`)??``,view:e.getAttribute(`data-view`)===`preview`?`preview`:`card`})}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,A(t,{"data-type":`file`,"data-url":e.attrs.url,"data-name":e.attrs.name,"data-size":e.attrs.size,"data-mime":e.attrs.mime,"data-view":e.attrs.view}),[`a`,{href:e.attrs.url,download:e.attrs.name},e.attrs.name]]},addNodeView(){return({node:e,editor:t,getPos:n})=>{let{host:r,loadPdf:i,labels:a}=this.options,o=document.createElement(`div`);o.className=`dw-file-block`,o.setAttribute(`data-type`,`file`);let s=document.createElement(`div`);s.className=`dw-file`;let c=document.createElement(`a`);c.className=`dw-file__name`,c.target=`_blank`,c.rel=`noopener`;let l=document.createElement(`span`);l.className=`dw-file__size`,s.append(c,l),o.append(s);let u=null,d=null,f=e,p=async()=>{let e=r?.transcribe;if(e&&u&&a){u.disabled=!0,u.textContent=a.blocks.transcribing,d&&(d.textContent=``);try{let r=await e(String(f.attrs.url??``),String(f.attrs.name??`file`)),i=typeof n==`function`?n():void 0;i!==void 0&&r&&t.chain().insertContentAt(i+f.nodeSize,r).run()}catch(e){d&&(d.textContent=e instanceof Error&&e.message?e.message:a.blocks.transcribeFailed)}finally{u&&(u.disabled=!1,u.textContent=a.blocks.transcribe)}}},m=null,h=null,g=``,_=e=>{let n=String(e.attrs.url??``),_=r?r.resolve(n):n;c.href=_,c.textContent=String(e.attrs.name??`file`),l.textContent=TH(Number(e.attrs.size??0)),f=e;let v=!!r?.transcribe&&!!a&&t.isEditable&&SH(String(e.attrs.mime??``),String(e.attrs.name??``));v&&!u&&a?(u=document.createElement(`button`),u.type=`button`,u.className=`dw-file__action`,u.textContent=a.blocks.transcribe,u.title=a.blocks.transcribeHint,u.setAttribute(`data-testid`,`file-transcribe`),u.addEventListener(`click`,()=>void p()),d=document.createElement(`span`),d.className=`dw-file__status`,d.setAttribute(`role`,`status`),s.append(u),o.append(d)):!v&&u&&(u.remove(),d?.remove(),u=d=null),!(e.attrs.view===`preview`&&Rj(e.attrs.mime,e.attrs.name)&&n)||!i||!a?(h?.(),h=null,m?.remove(),m=null,g=``):g!==_&&(h?.(),m||(m=document.createElement(`div`),m.className=`dw-pdf`,m.tabIndex=0,m.setAttribute(`role`,`document`),o.append(m)),m.setAttribute(`aria-label`,String(e.attrs.name??`PDF`)),g=_,h=zj(m,_,i,a))};return _(e),{dom:o,update:t=>t.type===e.type&&(_(t),!0),stopEvent:e=>!!u&&u.contains(e.target)||!!m&&m.contains(e.target)&&e.type!==`mousedown`,ignoreMutation:()=>!0,destroy:()=>h?.()}}}}),DH=Tp.create({name:`fileDrop`,addOptions(){return{host:void 0,onError:void 0}},addProseMirrorPlugins(){let e=this.options.host;return e?[OH(()=>this.editor,e,this.options.onError)]:[]}});function OH(e,t,n){let r=(r,i)=>{let a=e();return!a||!r.length||!t.upload?!1:(CH(a,t,r,i).catch(n),!0)};return new D({key:new Un(`docwellFileDrop`),props:{handlePaste(e,t){return r([...t.clipboardData?.files??[]])},handleDrop(e,t){let n=[...t.dataTransfer?.files??[]];if(!n.length)return!1;let i=e.posAtCoords({left:t.clientX,top:t.clientY});return t.preventDefault(),r(n,i?.pos)}}})}var kH=new Un(`dwFind`),AH=``;function jH(e,t,n=!1){if(!t)return[];let r=n?t:t.toLowerCase(),i=[];return e.descendants((e,t)=>{if(!e.isTextblock)return!0;let a=``,o=[];e.forEach((e,n)=>{let r=t+1+n;if(e.isText){let t=e.text??``;for(let e=0;ee.from>=r);return a===-1&&(a=i.length?0:-1),{term:t,caseSensitive:n,matches:i,current:a}}function NH(e,t){return t&&e.setSelection(T.create(e.doc,t.from,t.to)).scrollIntoView(),e}var PH=Tp.create({name:`findReplace`,addCommands(){return{setFind:(e,t=!1)=>({state:n,tr:r,dispatch:i})=>{let a=MH(n.doc,e,t,n.selection.from);return r.setMeta(kH,{term:e,caseSensitive:t,near:n.selection.from}),i&&i(NH(r,a.matches[a.current])),!0},findStep:e=>({state:t,tr:n,dispatch:r})=>{let i=kH.getState(t);if(!i?.matches.length)return!1;let a=(i.current+e+i.matches.length)%i.matches.length;return n.setMeta(kH,{current:a}),r&&r(NH(n,i.matches[a])),!0},replaceCurrent:e=>({state:t,tr:n,dispatch:r})=>{let i=kH.getState(t),a=i?.matches[i.current];if(!i||!a)return!1;if(r){n.insertText(e,a.from,a.to),n.setMeta(kH,{term:i.term,caseSensitive:i.caseSensitive,near:a.from+e.length});let t=MH(n.doc,i.term,i.caseSensitive,a.from+e.length);r(NH(n,t.matches[t.current]))}return!0},replaceAll:e=>({state:t,tr:n,dispatch:r})=>{let i=kH.getState(t);if(!i?.matches.length)return!1;if(r){for(let t of[...i.matches].reverse())n.insertText(e,t.from,t.to);n.setMeta(kH,{term:i.term,caseSensitive:i.caseSensitive,near:0}),r(n)}return!0},clearFind:()=>({tr:e,dispatch:t})=>(t&&t(e.setMeta(kH,{clear:!0})),!0)}},addProseMirrorPlugins(){let e={term:``,caseSensitive:!1,matches:[],current:-1};return[new D({key:kH,state:{init:()=>e,apply(t,n,r,i){let a=t.getMeta(kH);if(a&&`clear`in a)return e;if(a&&`term`in a)return MH(i.doc,a.term,a.caseSensitive,a.near);if(a&&`current`in a)return{...n,current:a.current};if(!n.term||!t.docChanged)return n;let o=n.matches[n.current]?.from??0;return MH(i.doc,n.term,n.caseSensitive,t.mapping.map(o))}},props:{decorations(e){let t=kH.getState(e);return t?.matches.length?xs.create(e.doc,t.matches.map((e,n)=>vs.inline(e.from,e.to,{class:n===t.current?`dw-find dw-find-current`:`dw-find`}))):null}}})]}}),L=class e extends Error{constructor(t,n){var r=`KaTeX parse error: `+t,i,a,o=n&&n.loc;if(o&&o.start<=o.end){var s=o.lexer.input;i=o.start,a=o.end,i===s.length?r+=` at end of input: `:r+=` at position `+(i+1)+`: `;var c=s.slice(i,a).replace(/[^]/g,`$&̲`),l=i>15?`…`+s.slice(i-15,i):s.slice(0,i),u=a+15e.replace(FH,`-$1`).toLowerCase(),LH={"&":`&`,">":`>`,"<":`<`,'"':`"`,"'":`'`},RH=/[&><"']/g,zH=e=>String(e).replace(RH,e=>LH[e]),BH=e=>e.type===`ordgroup`||e.type===`color`?e.body.length===1?BH(e.body[0]):e:e.type===`font`?BH(e.body):e,VH=new Set([`mathord`,`textord`,`atom`]),HH=e=>VH.has(BH(e).type),UH=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(e);return t?t[2]!==`:`||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():`_relative`},WH={displayMode:{type:`boolean`,description:`Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.`,cli:`-d, --display-mode`},output:{type:{enum:[`htmlAndMathml`,`html`,`mathml`]},description:`Determines the markup language of the output.`,cli:`-F, --format `},leqno:{type:`boolean`,description:`Render display math in leqno style (left-justified tags).`},fleqn:{type:`boolean`,description:`Render display math flush left.`},throwOnError:{type:`boolean`,default:!0,cli:`-t, --no-throw-on-error`,cliDescription:`Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error.`},errorColor:{type:`string`,default:`#cc0000`,cli:`-c, --error-color `,cliDescription:`A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.`,cliProcessor:e=>`#`+e},macros:{type:`object`,cli:`-m, --macro `,cliDescription:`Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).`,cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:`number`,description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:`--min-rule-thickness `,cliProcessor:parseFloat},colorIsTextColor:{type:`boolean`,description:`Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.`,cli:`-b, --color-is-text-color`},strict:{type:[{enum:[`warn`,`ignore`,`error`]},`boolean`,`function`],description:`Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.`,cli:`-S, --strict`,cliDefault:!1},trust:{type:[`boolean`,`function`],description:`Trust the input, enabling all HTML features such as \\url.`,cli:`-T, --trust`},maxSize:{type:`number`,default:1/0,description:`If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large`,processor:e=>Math.max(0,e),cli:`-s, --max-size `,cliProcessor:parseInt},maxExpand:{type:`number`,default:1e3,description:`Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.`,processor:e=>Math.max(0,e),cli:`-e, --max-expand `,cliProcessor:e=>e===`Infinity`?1/0:parseInt(e)},globalGroup:{type:`boolean`,cli:!1}};function GH(e){if(typeof e!=`string`)return e.enum[0];switch(e){case`boolean`:return!1;case`string`:return``;case`number`:return 0;case`object`:return{};default:throw Error(`Unexpected schema type; settings must declare an explicit default.`)}}function KH(e){return Object.prototype.hasOwnProperty.call(e,`default`)&&e.default!==void 0?e.default:GH(Array.isArray(e.type)?e.type[0]:e.type)}function qH(e,t,n,r){var i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0,a=Object.prototype.hasOwnProperty.call(r,`processor`)?r.processor:void 0;e[t]=i===void 0?KH(r):a?a(i):i}var JH=class{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e||={};for(var t of Object.keys(WH)){var n=WH[t];n&&qH(this,t,e,n)}}reportNonstrict(e,t,n){var r=this.strict;if(typeof r==`function`&&(r=r(e,t,n)),r&&r!==`ignore`){if(r===!0||r===`error`)throw new L(`LaTeX-incompatible input and strict mode is set to 'error': `+(t+` [`+e+`]`),n);r===`warn`?typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)):typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`))}}useStrictBehavior(e,t,n){var r=this.strict;if(typeof r==`function`)try{r=r(e,t,n)}catch{r=`error`}return!r||r===`ignore`?!1:r===!0||r===`error`?!0:r===`warn`?(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)),!1):(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`)),!1)}isTrusted(e){if(`url`in e&&e.url&&!e.protocol){var t=UH(e.url);if(t==null)return!1;e.protocol=t}return!!(typeof this.trust==`function`?this.trust(e):this.trust)}},YH=class{constructor(e,t,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=t,this.cramped=n}sup(){return iU[aU[this.id]]}sub(){return iU[oU[this.id]]}fracNum(){return iU[sU[this.id]]}fracDen(){return iU[cU[this.id]]}cramp(){return iU[lU[this.id]]}text(){return iU[uU[this.id]]}isTight(){return this.size>=2}},XH=0,ZH=1,QH=2,$H=3,eU=4,tU=5,nU=6,rU=7,iU=[new YH(XH,0,!1),new YH(ZH,0,!0),new YH(QH,1,!1),new YH($H,1,!0),new YH(eU,2,!1),new YH(tU,2,!0),new YH(nU,3,!1),new YH(rU,3,!0)],aU=[eU,tU,eU,tU,nU,rU,nU,rU],oU=[tU,tU,tU,tU,rU,rU,rU,rU],sU=[QH,$H,eU,tU,nU,rU,nU,rU],cU=[$H,$H,tU,tU,rU,rU,rU,rU],lU=[ZH,ZH,$H,$H,tU,tU,rU,rU],uU=[XH,ZH,QH,$H,QH,$H,QH,$H],R={DISPLAY:iU[XH],TEXT:iU[QH],SCRIPT:iU[eU],SCRIPTSCRIPT:iU[nU]},dU=[{name:`latin`,blocks:[[256,591],[768,879]]},{name:`cyrillic`,blocks:[[1024,1279]]},{name:`armenian`,blocks:[[1328,1423]]},{name:`brahmic`,blocks:[[2304,4255]]},{name:`georgian`,blocks:[[4256,4351]]},{name:`cjk`,blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:`hangul`,blocks:[[44032,55215]]}];function fU(e){for(var t=0;t=i[0]&&e<=i[1])return n.name}return null}var pU=[];dU.forEach(e=>e.blocks.forEach(e=>pU.push(...e)));function mU(e){for(var t=0;t=pU[t]&&e<=pU[t+1])return!0;return!1}var hU=e=>e+` `+e,gU=80,_U=function(e,t){return`M95,`+(622+e+t)+` +`&&o++):i+=e,o++}return(i!==``||r.length)&&(r.push(i),n.push(r)),n}function nV(e,t){return e.includes(t)||/["\r\n]/.test(e)||/^\s|\s$/.test(e)?`"${e.replace(/"/g,`""`)}"`:e}function rV(e,t=`,`){return e.map(e=>e.map(e=>nV(e,t)).join(t)).join(`\r +`)}function iV(e,t,n){return rV([t.map(e=>e.name),...n.map(e=>t.map(t=>uz(e,t)))])}function aV(e){let t=e.map(e=>e.trim()).filter(Boolean);if(!t.length)return`text`;if(t.every(e=>cz(e)!==null))return`number`;if(t.every(e=>/^\d{4}-\d{2}-\d{2}/.test(e)))return`date`;if(t.every(e=>/^(true|false|yes|no)$/i.test(e)))return`checkbox`;if(t.every(e=>/^https?:\/\/\S+$/.test(e)))return`link`;let n=new Set(t.map(e=>e.toLowerCase()));return t.length>=4&&n.size<=Math.max(2,t.length/3)&&t.every(e=>e.length<=40)?`select`:`text`}function oV(e,t,n){let r=e.trim();if(!r)return null;let i=e=>{let t=n.find(t=>t.name.toLowerCase()===e.toLowerCase());return t||(t={id:qR(),name:e,color:xz(n)},n.push(t)),t.id};switch(t.type){case`number`:return cz(r);case`progress`:{let e=cz(r.replace(`%`,``));return e===null?null:Math.max(0,Math.min(100,Math.round(e)))}case`checkbox`:return/^(true|yes|1|x|✓|done)$/i.test(r);case`date`:return oz(r)||null;case`select`:return i(r);case`multiSelect`:return[...new Set(r.split(/[,;]/).map(e=>e.trim()).filter(Boolean).map(i))];case`member`:case`attachment`:case`createdBy`:case`createdTime`:return null;default:return r}}function sV(e,t=`,`){let n=tV(e,t).filter(e=>e.some(e=>e.trim())),r=n[0]??[],i=n.slice(1),a=r.map((e,t)=>({id:qR(),name:e.trim()||`${t+1}`,type:t===0?`title`:aV(i.map(e=>e[t]??``))}));for(let e of a)e.type===`select`&&(e.options=[]);return{columns:a,rows:i.map(e=>{let t={};return a.forEach((n,r)=>{let i=oV(e[r]??``,n,n.options??[]);i!==null&&(!Array.isArray(i)||i.length)&&(t[n.id]=i)}),t})}}function cV(e,t){let n=[];return{index:e.map(e=>{let r=t.find(t=>t.name.trim().toLowerCase()===e.trim().toLowerCase());return!r&&e.trim()&&n.push(e.trim()),r??null}),missing:n}}function lV(e,t,n,r){let i=L(`select`,{class:`dw-db-select`,"aria-label":n});for(let n of t){let t=L(`option`,{value:n.value},n.label);n.value===e&&(t.selected=!0),i.append(t)}return i.addEventListener(`change`,()=>r(i.value)),i.addEventListener(`keydown`,e=>e.stopPropagation()),i}var uV=e=>e.map(e=>({value:e.id,label:e.name||`…`}));function dV(e,t,n,r){let i=e.labels;if(!fz(n.op))return null;if(t.type===`select`||t.type===`multiSelect`)return lV(typeof n.value==`string`?n.value:``,[{value:``,label:`—`},...(t.options??[]).map(e=>({value:e.id,label:e.name}))],i.value,r);let a=t.type===`date`||t.type===`createdTime`?`date`:t.type===`number`||t.type===`progress`?`number`:`text`,o=L(`input`,{class:`dw-db-input dw-db-input--small`,type:a,"aria-label":i.value,placeholder:i.value});return o.value=n.value===void 0||n.value===null?``:String(n.value),o.addEventListener(`keydown`,e=>e.stopPropagation()),o.addEventListener(`change`,()=>r(a===`number`?o.value===``?null:Number(o.value):o.value)),o}function fV(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.filters),s=()=>r?.updateView(n.id,{filters:o}),c=()=>{t.replaceChildren(),o.length>1&&t.append(lV(n.filterMode,[{value:`and`,label:i.matchAll},{value:`or`,label:i.matchAny}],i.filter,e=>{n.filterMode=e,r?.updateView(n.id,{filterMode:n.filterMode})})),o.length||t.append(L(`p`,{class:`dw-db-pop__empty`},i.noFilters)),o.forEach((n,r)=>{let l=a.find(e=>e.id===n.column);if(!l)return;let u=dz(l.type),d=L(`div`,{class:`dw-db-pop__line`},lV(n.column,uV(a),i.filter,e=>{let t=a.find(t=>t.id===e);o[r]={column:e,op:dz(t.type)[0]},s(),c()}),lV(n.op,u.map(e=>({value:e,label:PR(i,e)})),i.filter,e=>{o[r]={...n,op:e},fz(e)||delete o[r].value,s(),c()}),dV(e,l,n,e=>{o[r]={...o[r],value:e},s()}),bV(i.remove,()=>{o.splice(r,1),s(),c()}));t.append(d)}),r&&t.append(xV(i.addFilter,()=>{let e=a.find(e=>e.type!==`title`)??a[0];o.push({column:e.id,op:dz(e.type)[0]}),s(),c()}))};c()}function pV(e,t,n){let r=e.store,i=e.labels,a=e.db.columns,o=structuredClone(n.sorts),s=()=>r?.updateView(n.id,{sorts:o}),c=()=>{t.replaceChildren(),o.length||t.append(L(`p`,{class:`dw-db-pop__empty`},i.noSorts)),o.forEach((e,n)=>{t.append(L(`div`,{class:`dw-db-pop__line`},lV(e.column,uV(a),i.sort,t=>{o[n]={...e,column:t},s()}),lV(e.desc?`desc`:`asc`,[{value:`asc`,label:i.ascending},{value:`desc`,label:i.descending}],i.sort,t=>{o[n]={...e,desc:t===`desc`},s()}),bV(i.remove,()=>{o.splice(n,1),s(),c()})))}),r&&t.append(xV(i.addSort,()=>{let e=new Set(o.map(e=>e.column)),t=a.find(t=>!e.has(t.id))??a[0];o.push({column:t.id,desc:!1}),s(),c()}))};c()}function mV(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>QR.includes(e.type)),o=a.map(e=>({value:e.id,label:e.name||MR(i,e.type)}));n.type!==`kanban`&&o.unshift({value:``,label:i.noGrouping}),t.append(L(`label`,{class:`dw-db-pop__label`},i.groupBy),a.length||n.type!==`kanban`?lV(n.groupBy??``,o,i.groupBy,e=>r?.updateView(n.id,{groupBy:e||null})):L(`p`,{class:`dw-db-pop__empty`},i.noGroupColumn))}function hV(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>e.type===`date`||e.type===`createdTime`);t.append(L(`label`,{class:`dw-db-pop__label`},i.dateColumn),a.length?lV(n.dateColumn??``,[{value:``,label:`—`},...a.map(e=>({value:e.id,label:e.name||MR(i,e.type)}))],i.dateColumn,e=>r?.updateView(n.id,{dateColumn:e||null})):L(`p`,{class:`dw-db-pop__empty`},i.noDateColumn))}function gV(e,t,n){let r=e.store,i=e.labels,a={...n.chart},o=L(`div`,{class:`dw-db-pop__chart`});t.append(o);let s=e=>{a={...a,...e},r?.updateView(n.id,{chart:a}),d()},c=e.db.columns.filter(e=>YR.includes(e.type)),l=e.db.columns.filter(e=>XR.includes(e.type)),u=e=>e.name||MR(i,e.type),d=()=>{o.replaceChildren(L(`label`,{class:`dw-db-pop__label`},i.chartType),lV(a.type,WR.map(e=>({value:e,label:e===`bar`?i.chartBar:e===`line`?i.chartLine:i.chartDonut})),i.chartType,e=>s({type:e})),L(`label`,{class:`dw-db-pop__label`},i.chartX),c.length?lV(a.x??``,[{value:``,label:`—`},...c.map(e=>({value:e.id,label:u(e)}))],i.chartX,e=>s({x:e||null})):L(`p`,{class:`dw-db-pop__empty`},i.noChartAxis),L(`label`,{class:`dw-db-pop__label`},i.chartMeasure),lV(a.op,GR.filter(e=>e===`count`||l.length).map(e=>({value:e,label:e===`count`?i.chartCount:e===`sum`?i.chartSum:i.chartAvg})),i.chartMeasure,e=>s({op:e,y:e===`count`?null:a.y??l[0]?.id??null}))),a.op!==`count`&&l.length&&o.append(lV(a.y??``,l.map(e=>({value:e.id,label:u(e)})),i.chartValue,e=>s({y:e||null})))};d()}function _V(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>e.type===`date`&&e.id!==n.dateColumn);t.append(L(`label`,{class:`dw-db-pop__label`},i.endColumn),lV(n.endColumn??``,[{value:``,label:i.sameDay},...a.map(e=>({value:e.id,label:e.name||MR(i,e.type)}))],i.endColumn,e=>r?.updateView(n.id,{endColumn:e||null})))}function vV(e,t,n){let r=e.store,i=e.labels,a=e.db.columns.filter(e=>e.type===`attachment`);t.append(L(`label`,{class:`dw-db-pop__label`},i.cover),lV(n.cover??``,[{value:``,label:i.noCover},...a.map(e=>({value:e.id,label:e.name||MR(i,e.type)}))],i.cover,e=>r?.updateView(n.id,{cover:e||null})))}function yV(e,t,n){let r=e.store,i=e.labels,a=[...n.hidden],o=()=>r?.updateView(n.id,{hidden:a}),s=L(`div`,{class:`dw-db-pop__props`});t.append(s);let c=()=>{s.replaceChildren();let t=e.db.columns.filter(e=>e.type!==`title`);if(r&&t.length){let e=L(`button`,{type:`button`,class:`dw-db__btn`},a.length?i.showAll:i.hideAll);e.addEventListener(`click`,()=>{a=a.length?[]:t.map(e=>e.id),o(),c()}),s.append(L(`div`,{class:`dw-db-pop__row dw-db-pop__row--end`},e))}for(let t of e.db.columns){let e=t.type===`title`||!a.includes(t.id),n=L(`button`,{type:`button`,class:`dw-db-pop__item`,role:`switch`,"aria-checked":String(e),disabled:t.type===`title`||!r},L(`span`,{class:`dw-db-pop__check`},uB(EB[t.type],14)),L(`span`,{class:`dw-db-pop__grow`},t.name||MR(i,t.type)),L(`span`,{class:e?`dw-db-switch is-on`:`dw-db-switch`}));n.addEventListener(`click`,()=>{a=e?[...a,t.id]:a.filter(e=>e!==t.id),o(),c()}),s.append(n)}};c()}function bV(e,t){let n=L(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--icon`,"aria-label":e,title:e},uB(`close`,14));return n.addEventListener(`click`,t),n}function xV(e,t){let n=L(`button`,{type:`button`,class:`dw-db__btn dw-db-pop__add`},uB(`plus`,14),L(`span`,{},e));return n.addEventListener(`click`,t),n}var SV=6,CV=48;function wV(e,t){e.classList.add(`dw-db-touch-handle`);let n=!1,r=-1,i=0,a=0,o=0,s=0,c=0,l=null,u=null,d=0,f,p=0,m=()=>document.elementFromPoint(o,s),h=()=>{clearTimeout(f),cancelAnimationFrame(d),u&&(u.remove(),u=null,t.end()),t.source.classList.remove(`is-held`,`is-dragging`),n=!1,r=-1,p=Date.now()},g=()=>{if(!u)return;let e=oinnerWidth-CV),n=sinnerHeight-CV),r=!1;for(let[i,a]of[[`x`,e],[`y`,n]]){if(!a)continue;let e=TV(t.source,i)??(i===`y`?document.scrollingElement:null);if(!e)continue;let n=i===`x`?`scrollLeft`:`scrollTop`,o=e[n];e[n]+=a*12,r||=e[n]!==o}r&&t.over(m(),o,s),d=requestAnimationFrame(g)},_=e=>[...e.changedTouches].find(e=>e.identifier===r);e.addEventListener(`touchstart`,u=>{if(n||u.touches.length!==1)return;let d=u.changedTouches[0],p=u.target.closest(`input, textarea, select, [contenteditable='true']`);p&&e.contains(p)||(u.preventDefault(),n=!0,r=d.identifier,i=o=d.clientX,a=s=d.clientY,c=Date.now(),l=u.target,f=setTimeout(()=>{t.source.classList.add(`is-held`),navigator.vibrate?.(10)},500))},{passive:!1}),e.addEventListener(`touchmove`,e=>{let r=n&&_(e);if(r){if(e.preventDefault(),o=r.clientX,s=r.clientY,!u){if(Math.hypot(o-i,s-a)<=SV)return;clearTimeout(f),t.source.classList.remove(`is-held`),u=t.ghost();let e=t.source.getBoundingClientRect();Object.assign(u.style,{position:`fixed`,left:`${e.left}px`,top:`${e.top}px`,width:`${Math.max(80,Math.min(e.width,innerWidth-Math.max(e.left,0)-8))}px`,margin:`0`,pointerEvents:`none`,zIndex:`1000`}),u.classList.add(`dw-db-ghost`),document.body.append(u),t.source.classList.add(`is-dragging`),d=requestAnimationFrame(g)}u.style.transform=`translate(${o-i}px, ${s-a}px)`,t.over(m(),o,s)}},{passive:!1}),e.addEventListener(`touchend`,e=>{if(!n||!_(e))return;e.preventDefault();let r=u!==null,i=Date.now()-c>=500,a=l;r&&t.drop(m(),o,s),h(),r||(i&&t.hold?t.hold():a instanceof HTMLElement&&a.click())}),e.addEventListener(`touchcancel`,e=>{n&&_(e)&&h()});for(let t of[`contextmenu`,`dragstart`])e.addEventListener(t,e=>{(n||Date.now()-p<800)&&(e.preventDefault(),e.stopPropagation())},!0)}function TV(e,t){for(let n=e.parentElement;n;n=n.parentElement){let e=getComputedStyle(n),r=t===`x`?e.overflowX:e.overflowY;if((t===`x`?n.scrollWidth>n.clientWidth:n.scrollHeight>n.clientHeight)&&(r===`auto`||r===`scroll`))return n}return null}function EV(e,t,n,r){let i=e.store;if(!i)return;let a=e.labels;pB(t,(t,r)=>{let o=L(`textarea`,{class:`dw-db-input dw-db-formula__input`,rows:3,spellcheck:!1,"aria-label":a.typeFormula,placeholder:`if(prop("Done"), "✓", prop("Points") * 2)`});o.value=n.formula??``;let s=L(`div`,{class:`dw-db-formula__check`,role:`status`,"aria-live":`polite`}),c=L(`button`,{type:`button`,class:`dw-db__btn dw-db__btn--primary`},a.formulaSave),l=e=>{let t=o.selectionStart??o.value.length,n=o.selectionEnd??t;o.value=o.value.slice(0,t)+e+o.value.slice(n),o.focus(),o.setSelectionRange(t+e.length,t+e.length),f()},u=e.db.columns.filter(e=>e.id!==n.id),d=L(`div`,{class:`dw-db-formula__props`,role:`group`,"aria-label":a.formulaInsert},u.map(e=>{let t=e.name||MR(a,e.type),n=L(`button`,{type:`button`,class:`dw-db-tag`,dataset:{color:`gray`},title:a.formulaInsert},t);return n.addEventListener(`click`,()=>l(`prop("${t.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}")`)),n})),f=()=>{s.classList.remove(`is-error`);let t=o.value;try{qz(t)}catch(e){s.classList.add(`is-error`),s.textContent=e instanceof Uz?e.message:String(e),c.disabled=!0;return}c.disabled=!1;let r=e.db.rows[0];if(!r){s.textContent=``;return}let i=lB({...e.db,columns:e.db.columns.map(e=>e.id===n.id?{...e,formula:t}:e),rows:[r]}).rows[0]?.computed?.[n.id];i?.error?(s.classList.add(`is-error`),s.textContent=i.error):s.textContent=`${a.formulaPreview}: ${i?.text||`—`}`},p=()=>{c.disabled||(i.setFormula(n.id,o.value.trim()),r())};o.addEventListener(`input`,f),o.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),p())}),c.addEventListener(`click`,p),t.append(L(`label`,{class:`dw-db-pop__label`},n.name||a.typeFormula),o,s,L(`div`,{class:`dw-db-pop__label`},a.formulaInsert),d,L(`p`,{class:`dw-db-formula__help`},a.formulaHelp),L(`div`,{class:`dw-db-pop__row dw-db-pop__row--end`},c)),f(),queueMicrotask(()=>o.focus())},{class:`dw-db-pop--panel dw-db-formula`,label:a.editFormula,onClose:r})}var DV=200,OV=class{host;dom=L(`div`,{class:`dw-db`,dataset:{type:`database`},contentEditable:`false`});db;viewId=null;search=``;editing=0;pending=!1;limit=DV;collapsed=new Set;sel=null;anchor=null;picked=new Set;month;tlFrom=``;tlScale=null;titleEl=L(`div`,{class:`dw-db__title`});tabs=L(`div`,{class:`dw-db__tabs`,role:`tablist`});tools=L(`div`,{class:`dw-db__tools`});body=L(`div`,{class:`dw-db__body`});bulk=L(`div`,{class:`dw-db__bulk`});searchInput;buttons;constructor(e,t){this.host=e,this.db=t;let n=new Date;this.month={y:n.getFullYear(),m:n.getMonth()};let r=e.labels;this.searchInput=L(`input`,{class:`dw-db-input dw-db__search`,placeholder:r.search,"aria-label":r.search,hidden:!0}),this.searchInput.addEventListener(`input`,()=>{this.search=this.searchInput.value,this.limit=DV,this.drawBody()}),this.searchInput.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&(this.searchInput.value=``,this.search=``,this.searchInput.hidden=!0,this.drawBody())}),this.buttons={search:dB(`search`,r.search,()=>{this.searchInput.hidden=!this.searchInput.hidden,this.searchInput.hidden||this.searchInput.focus()}),filter:dB(`filter`,r.filter,e=>this.panel(e,`filter`),r.filter),sort:dB(`sort`,r.sort,e=>this.panel(e,`sort`),r.sort),group:dB(`layers`,r.group,e=>this.panel(e,`group`),r.group),props:dB(`sliders`,r.properties,e=>this.panel(e,`props`)),more:dB(`more`,r.more,()=>this.moreMenu()),add:dB(`plus`,r.newRow,()=>this.addRow(),r.newRow)},this.buttons.add.classList.add(`dw-db__btn--primary`);let i=L(`div`,{class:`dw-db__head`},this.titleEl),a=L(`div`,{class:`dw-db__bar`},this.tabs,this.tools);this.tools.append(this.searchInput,this.buttons.search,this.buttons.filter,this.buttons.sort,this.buttons.group,this.buttons.props,this.buttons.more,this.buttons.add),this.dom.append(i,a,this.bulk,this.body),this.draw()}get labels(){return this.host.labels}get editable(){return!!this.host.store}get view(){return this.db.views.find(e=>e.id===this.viewId)??this.db.views[0]??kV}ctx(){return{...this.host,db:this.db,openRow:e=>this.openRow(e),setEditing:e=>{this.editing=Math.max(0,this.editing+(e?1:-1)),!this.editing&&this.pending&&(this.pending=!1,this.draw())}}}update(e,t){this.db=e,t&&(this.host={...this.host,...t}),this.editing?this.pending=!0:this.draw()}destroy(){mB()}draw(){this.drawTitle(),this.drawTabs(),this.drawTools(),this.drawBody()}drawTitle(){let e=this.labels,t=this.db.title;if(this.titleEl.querySelector(`input`)===document.activeElement)return;if(!this.editable){this.titleEl.replaceChildren(L(`span`,{class:t?``:`is-empty`},t||e.untitled));return}let n=L(`input`,{class:`dw-db__title-input`,placeholder:e.untitled,"aria-label":e.untitled});n.value=t,n.addEventListener(`keydown`,e=>{e.stopPropagation(),(e.key===`Enter`||e.key===`Escape`)&&n.blur()}),n.addEventListener(`change`,()=>this.host.store?.setTitle(n.value)),this.titleEl.replaceChildren(n)}drawTabs(){let e=this.labels,t=this.view;if(this.tabs.replaceChildren(...this.db.views.map(n=>{let r=L(`button`,{type:`button`,class:n.id===t.id?`dw-db__tab is-active`:`dw-db__tab`,role:`tab`,"aria-selected":String(n.id===t.id)},uB(AV[n.type],14),L(`span`,{},n.name||IR(e,n.type)));return r.addEventListener(`click`,()=>{if(n.id===t.id&&this.editable)return this.viewMenu(r,n);this.viewId=n.id,this.sel=null,this.limit=DV,this.draw()}),r.addEventListener(`contextmenu`,e=>{this.editable&&(e.preventDefault(),this.viewMenu(r,n))}),r})),this.editable){let t=dB(`plus`,e.addView,()=>Gj(t,UR.map(t=>({id:t,label:IR(e,t),icon:AV[t],run:()=>{this.showView(this.host.store.addView(t,IR(e,t)))}})),e.addView));this.tabs.append(t)}}drawTools(){let e=this.view,t=this.buttons,n=(e,t)=>{e.classList.toggle(`is-on`,t>0);let n=e.querySelector(`span`);n&&(n.textContent=t?`${e.title} ${t}`:e.title)};n(t.filter,e.filters.length),n(t.sort,e.sorts.length),t.sort.hidden=e.type===`calendar`||e.type===`chart`,t.group.classList.toggle(`is-on`,!!e.groupBy&&MV.includes(e.type)),t.group.hidden=e.type===`calendar`||e.type===`timeline`||e.type===`chart`,t.add.hidden=!this.editable,this.drawBulk()}drawBulk(){let e=[...this.picked].filter(e=>this.db.rows.some(t=>t.id===e));if(this.picked=new Set(e),this.bulk.hidden=!e.length||!this.editable,this.bulk.hidden)return this.bulk.replaceChildren();let t=this.labels;this.bulk.replaceChildren(L(`span`,{},LR(t.selected,e.length)),dB(`trash`,t.deleteRows,()=>{this.host.store?.deleteRows(e),this.picked.clear()},t.deleteRows),dB(`close`,t.close,()=>{this.picked.clear(),this.draw()}))}panel(e,t){let n=e.currentTarget;pB(n,e=>{let n=this.ctx(),r=this.view;t===`filter`?fV(n,e,r):t===`sort`?pV(n,e,r):t===`group`?mV(n,e,r):((r.type===`calendar`||r.type===`timeline`)&&hV(n,e,r),r.type===`timeline`&&_V(n,e,r),r.type===`chart`&&gV(n,e,r),r.type===`kanban`&&mV(n,e,r),r.type===`gallery`&&vV(n,e,r),yV(n,e,r))},{class:`dw-db-pop--panel`,label:n.title,placement:`bottom-end`})}viewMenu(e,t){let n=this.labels,r=this.host.store,i=[{id:`rename`,label:n.renameView,icon:`pencil`,run:()=>{let e=window.prompt(n.viewName,t.name)?.trim();e&&r.updateView(t.id,{name:e})}},{id:`layout`,label:n.layout,icon:`grid`,children:UR.map(e=>({id:e,label:IR(n,e),icon:e===t.type?`check`:AV[e],run:()=>this.setLayout(t,e)}))},{id:`duplicate`,label:n.duplicateView,icon:`copy`,run:()=>{this.showView(r.duplicateView(t.id,`${t.name||IR(n,t.type)} 2`))}}];this.db.views.length>1&&i.push({id:`delete`,label:n.deleteView,icon:`trash`,danger:!0,run:()=>r.deleteView(t.id)}),Gj(e,i,n.layout)}showView(e){e&&(this.viewId=e,this.sel=null,this.limit=DV,this.draw())}setLayout(e,t){let n={type:t},r=this.db.columns;t===`kanban`&&!e.groupBy&&(n.groupBy=r.find(e=>[`select`,`multiSelect`,`checkbox`,`member`].includes(e.type))?.id??null),t===`chart`&&!e.chart.x&&(n.chart={...e.chart,x:r.find(e=>YR.includes(e.type))?.id??null}),t===`gallery`&&!e.cover&&(n.cover=r.find(e=>e.type===`attachment`)?.id??null);let i=t===`calendar`||t===`timeline`;if(i&&!e.dateColumn&&(n.dateColumn=r.find(e=>e.type===`date`)?.id??null),t===`timeline`&&!e.endColumn){let t=n.dateColumn??e.dateColumn;n.endColumn=r.find(e=>e.type===`date`&&e.id!==t)?.id??null}i&&!n.dateColumn&&!e.dateColumn&&this.host.store&&(n.dateColumn=this.host.store.addColumn(`date`,this.labels.typeDate)),this.host.store?.updateView(e.id,n)}moreMenu(){let e=this.labels,t=this.view,n=[{id:`csv`,label:e.exportCsv,icon:`download`,run:()=>{let n=gz(this.db,t);gB(`${(this.db.title||e.untitled).replace(/[\\/:*?"<>|]+/g,` `).trim()}.csv`,`\uFEFF${iV(this.db,n,hz(this.db,t,this.search))}`,`text/csv`)}}];this.editable&&(n.push({id:`import`,label:e.importCsv,icon:`upload`,run:()=>void this.importCsv()}),n.push({id:`view`,label:e.layout,icon:`grid`,run:()=>this.viewMenu(this.buttons.more,t)})),Gj(this.buttons.more,n,e.more)}async importCsv(){let e=this.host.store,t=await _B(`.csv,text/csv,.tsv,text/tab-separated-values`);if(!e||!t)return;let n=await t.text(),r=t.name.endsWith(`.tsv`)?` `:`,`,i=tV(n,r).filter(e=>e.some(e=>e.trim()));i.length<2||e.tx(()=>{if(this.db.rows.every(e=>!uz(e,rz(this.db)))){let t=sV(n,r);e.deleteRows(this.db.rows.map(e=>e.id));let i=rz(this.db),[a,...o]=t.columns,s=new Map;a&&(e.renameColumn(i.id,a.name),s.set(a.id,i.id));for(let t of o){let n=this.db.columns.find(e=>e.name.toLowerCase()===t.name.toLowerCase()&&e.type!==`title`);n&&e.deleteColumn(n.id);let r=e.addColumn(t.type,t.name);t.options&&e.setOptions(r,t.options),s.set(t.id,r)}e.addRows(t.rows.map(e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[s.get(e)??e,t])))),this.host.notify?.(LR(this.labels.imported,t.rows.length));return}let{index:t,missing:a}=cV(i[0],this.db.columns),o=new Map(a.map(t=>[t,e.addColumn(`text`,t)])),s=i[0].map((e,n)=>{let r=t[n];if(r)return r;let i=o.get(e.trim());return i?{id:i,name:e,type:`text`}:null}),c=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),l=i.slice(1).map(e=>{let t={};return s.forEach((n,r)=>{if(!n)return;let i=oV(e[r]??``,n,c.get(n.id)??[]);i!==null&&(t[n.id]=i)}),t});for(let t of this.db.columns){let n=c.get(t.id);n&&n.length!==(t.options?.length??0)&&e.setOptions(t.id,n)}e.addRows(l),this.host.notify?.(LR(this.labels.imported,l.length))})}addRow(e={},t=!1,n){let r=this.host.store;if(!r)return;let i=this.view;for(let t of i.filters){let n=this.db.columns.find(e=>e.id===t.column);!n||t.column in e||(t.op===`is`&&(n.type===`select`||n.type===`text`)&&t.value&&(e[n.id]=t.value),t.op===`contains`&&n.type===`multiSelect`&&t.value&&(e[n.id]=[t.value]),t.op===`checked`&&(e[n.id]=!0))}let a=r.addRow(e,n);t||i.type!==`table`?this.openRow(a):(this.sel={row:a,col:rz(this.db).id},queueMicrotask(()=>this.startEdit()))}openRow(e){let t=hz(this.db,this.view,this.search).map(e=>e.id);this.host.openRow(e,t)}drawBody(){let e=this.view;e.type===`kanban`?this.drawKanban(e):e.type===`calendar`?this.drawCalendar(e):e.type===`list`||e.type===`gallery`?this.drawItems(e):e.type===`timeline`?this.drawTimeline(e):e.type===`chart`?this.drawChart(e):this.drawTable(e)}tableRows=[];tableCols=[];grid=null;drawTable(e){let t=this.labels,n=gz(this.db,e),r=hz(this.db,e,this.search),i=e.groupBy?this.db.columns.find(t=>t.id===e.groupBy):void 0,a=i?_z(r,i,t.noValue,t.checked,t.unchecked).filter(e=>e.rows.length||e.key!==``):[{key:``,label:``,rows:r}];this.tableCols=n,this.tableRows=[];let o=this.editable,s=e.sorts.length>0,c=L(`colgroup`,{},L(`col`,{class:`dw-db-t__gutter-col`}),n.map(t=>L(`col`,{style:{width:`${e.widths[t.id]??(t.type===`title`?240:160)}px`}})),o?L(`col`,{class:`dw-db-t__add-col`}):null),l=L(`table`,{class:`dw-db-t`},c,L(`thead`,{},L(`tr`,{},L(`th`,{class:`dw-db-t__gutter`,"aria-hidden":`true`}),n.map((e,t)=>this.headerCell(e,t,c.children[t+1])),o?L(`th`,{class:`dw-db-t__add`},dB(`plus`,t.addColumn,e=>this.addColumnMenu(e.currentTarget))):null))),u=0;for(let r of a){let a=L(`tbody`,{}),c=`${e.id}:${r.key}`;if(i){let e=!this.collapsed.has(c),t=L(`button`,{type:`button`,class:`dw-db-t__group`,"aria-expanded":String(e)},uB(e?`chevron-down`:`chevron-right`,14),r.key&&i.type!==`checkbox`&&i.type!==`member`&&i.type!==`createdBy`?L(`span`,{class:`dw-db-tag`,dataset:{color:r.color??`gray`}},r.label):L(`span`,{},r.label),L(`span`,{class:`dw-db-t__count`},String(r.rows.length)));if(t.addEventListener(`click`,()=>{e?this.collapsed.add(c):this.collapsed.delete(c),this.drawBody()}),a.append(L(`tr`,{class:`dw-db-t__group-row`},L(`td`,{colSpan:n.length+2},t))),!e){l.append(a);continue}}for(let e of r.rows){if(u>=this.limit)break;u++,this.tableRows.push(e),a.append(this.tableRow(e,n,o&&!s))}if(o&&u{let e={};i&&r.key?e[i.id]=bz({id:``,cells:{},createdAt:0,createdBy:null},i,``,r.key,r.rows.flatMap(e=>NV(iz(e,i)))):i?.type===`checkbox`&&(e[i.id]=r.key===`true`),this.addRow(e)}),a.append(L(`tr`,{class:`dw-db-t__new-row`},L(`td`,{colSpan:n.length+2},e)))}l.append(a)}let d=[],f=L(`div`,{class:`dw-db-t__wrap`,role:`grid`,tabIndex:0,"aria-label":this.db.title||t.database},l);if(d.push(f),r.length||d.push(L(`p`,{class:`dw-db__empty`},this.db.rows.length?t.noMatches:t.noRows)),r.length>u&&u>=this.limit){let e=L(`button`,{type:`button`,class:`dw-db__btn dw-db__more`},`${t.more} (${r.length-u})`);e.addEventListener(`click`,()=>{this.limit+=DV,this.drawBody()}),d.push(e)}this.grid=f,f.addEventListener(`keydown`,e=>this.onGridKey(e)),f.addEventListener(`copy`,e=>this.onCopy(e)),f.addEventListener(`paste`,e=>this.onPaste(e));let p=this.body.querySelector(`.dw-db-t__wrap`)?.scrollLeft??0,m=this.body.contains(document.activeElement);this.body.replaceChildren(...d),f.scrollLeft=p,this.markSelection(),m&&this.sel&&f.focus({preventScroll:!0})}headerCell(e,t,n){let r=this.labels,i=L(`span`,{class:`dw-db-t__name`},e.name||MR(r,e.type)),a=L(`button`,{type:`button`,class:`dw-db-t__head`,"aria-haspopup":`menu`,draggable:this.editable},uB(EB[e.type],14),i),o=L(`th`,{dataset:{col:e.id}},a);if(a.addEventListener(`click`,()=>this.columnMenu(a,e,t)),this.editable){a.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-column`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),o.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-column`)&&(e.preventDefault(),o.classList.add(`is-drop`))}),o.addEventListener(`dragleave`,()=>o.classList.remove(`is-drop`)),o.addEventListener(`drop`,t=>{o.classList.remove(`is-drop`);let n=t.dataTransfer?.getData(`application/x-docwell-column`);n&&n!==e.id&&(t.preventDefault(),this.host.store?.moveColumn(n,this.db.columns.findIndex(t=>t.id===e.id)))});let t=L(`span`,{class:`dw-db-t__resize`,title:r.resize,"aria-hidden":`true`});t.addEventListener(`pointerdown`,r=>{r.preventDefault(),r.stopPropagation();let i=r.clientX,a=n.getBoundingClientRect().width||160,o=a;t.setPointerCapture(r.pointerId);let s=e=>{o=Math.max(72,Math.round(a+e.clientX-i)),n.style.width=`${o}px`},c=()=>{t.removeEventListener(`pointermove`,s),t.removeEventListener(`pointerup`,c);let n=this.view;o!==a&&this.host.store?.updateView(n.id,{widths:{...n.widths,[e.id]:o}})};t.addEventListener(`pointermove`,s),t.addEventListener(`pointerup`,c)}),o.append(t)}return o}columnMenu(e,t,n){let r=this.labels,i=this.host.store,a=this.view,o=e=>({id:e?`desc`:`asc`,label:e?r.sortDescending:r.sortAscending,icon:e?`arrow-down`:`arrow-up`,run:()=>i?.updateView(a.id,{sorts:[{column:t.id,desc:e}]})});if(!i){Gj(e,[o(!1),o(!0)],t.name);return}let s=this.db.columns,c=s.findIndex(e=>e.id===t.id),l=[{id:`rename`,label:r.rename,icon:`pencil`,run:()=>this.renameColumn(t)}];t.type!==`title`&&l.push({id:`type`,label:r.type,icon:EB[t.type],children:HR.map(n=>({id:n,label:MR(r,n),icon:n===t.type?`check`:EB[n],run:()=>{i.changeType(t.id,n),(n===`relation`||n===`rollup`||n===`formula`)&&queueMicrotask(()=>this.linkSettings(e,t.id))}}))}),t.type===`relation`&&l.push({id:`relationTo`,label:r.relationTo,icon:`relation`,run:()=>this.linkSettings(e,t.id)}),t.type===`rollup`&&l.push({id:`rollup`,label:r.rollupSettings,icon:`rollup`,run:()=>this.linkSettings(e,t.id)}),t.type===`formula`&&l.push({id:`formula`,label:r.editFormula,icon:`sigma`,run:()=>this.linkSettings(e,t.id)}),l.push(o(!1),o(!0),{id:`filter`,label:r.filterBy,icon:`filter`,run:()=>{i.updateView(a.id,{filters:[...a.filters,{column:t.id,op:dz(t.type)[0]}]}),this.buttons.filter.click()}}),t.type!==`title`&&l.push({id:`hide`,label:r.hide,icon:`close`,run:()=>i.updateView(a.id,{hidden:[...a.hidden,t.id]})}),l.push({id:`left`,label:r.insertLeft,icon:`plus`,run:()=>this.insertColumn(c)},{id:`right`,label:r.insertRight,icon:`plus`,run:()=>this.insertColumn(c+1)}),c>0&&l.push({id:`moveLeft`,label:r.moveLeft,icon:`arrow-up`,run:()=>i.moveColumn(t.id,c-1)}),ci.moveColumn(t.id,c+1)}),t.type!==`title`&&l.push({id:`duplicate`,label:r.duplicate,icon:`copy`,run:()=>i.duplicateColumn(t.id,`${t.name} 2`)},{id:`delete`,label:r.deleteColumn,icon:`trash`,danger:!0,run:()=>i.deleteColumn(t.id)}),Gj(e,l,t.name||MR(r,t.type))}linkSettings(e,t){let n=this.db.columns.find(e=>e.id===t),r=e.isConnected?e:this.dom.querySelector(`[data-col="${t}"]`)??this.dom;n?.type===`relation`?SB(this.ctx(),r,n):n?.type===`rollup`?wB(this.ctx(),r,n):n?.type===`formula`&&EV(this.ctx(),r,n)}insertColumn(e){let t=this.host.store;if(!t)return;let n=t.addColumn(`text`,this.labels.typeText,e);queueMicrotask(()=>{let e=this.db.columns.find(e=>e.id===n);e&&this.renameColumn(e)})}addColumnMenu(e){let t=this.labels;Gj(e,HR.map(n=>({id:n,label:MR(t,n),icon:EB[n],run:()=>{let r=this.host.store?.addColumn(n,MR(t,n));queueMicrotask(()=>{let t=this.db.columns.find(e=>e.id===r);t?.type===`formula`?this.linkSettings(e,t.id):t&&this.renameColumn(t)})}})),t.addColumn)}renameColumn(e){let t=this.body.querySelector(`th[data-col="${CSS.escape(e.id)}"]`),n=this.host.store;if(!n)return;if(!t){let t=window.prompt(this.labels.columnName,e.name)?.trim();t&&n.renameColumn(e.id,t);return}let r=this.ctx();r.setEditing(!0);let i=hB(e.name,{class:`dw-db-t__name-input`,label:this.labels.columnName,onCommit:t=>{t.trim()&&t.trim()!==e.name&&n.renameColumn(e.id,t.trim()),r.setEditing(!1),this.drawBody()},onCancel:()=>{r.setEditing(!1),this.drawBody()}});t.replaceChildren(i),i.focus(),i.select()}tableRow(e,t,n){let r=this.labels,i=L(`tr`,{dataset:{row:e.id},class:this.picked.has(e.id)?`is-picked`:``}),a=L(`td`,{class:`dw-db-t__gutter`});if(this.editable){let t=L(`input`,{type:`checkbox`,class:`dw-db-t__pick`,"aria-label":r.selectRow,checked:this.picked.has(e.id)});if(t.addEventListener(`change`,()=>{t.checked?this.picked.add(e.id):this.picked.delete(e.id),i.classList.toggle(`is-picked`,t.checked),this.drawBulk()}),a.append(t),n){let t=L(`span`,{class:`dw-db-t__grip`,draggable:!0,title:r.dragRow,"aria-hidden":`true`},uB(`grip`,14));t.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`),t.dataTransfer?.setDragImage(i,0,0)}),a.append(t),i.addEventListener(`dragover`,e=>{if(!e.dataTransfer?.types.includes(`application/x-docwell-row`))return;e.preventDefault();let t=e.clientY>i.getBoundingClientRect().top+i.offsetHeight/2;i.classList.toggle(`is-drop-below`,t),i.classList.toggle(`is-drop-above`,!t)}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop-below`,`is-drop-above`)),i.addEventListener(`drop`,t=>{let n=i.classList.contains(`is-drop-below`);i.classList.remove(`is-drop-below`,`is-drop-above`);let r=t.dataTransfer?.getData(`application/x-docwell-row`);r&&r!==e.id&&this.host.store&&(t.preventDefault(),this.moveRowBeside(r,e.id,n))});let n=null,o=()=>n?.classList.remove(`is-drop-below`,`is-drop-above`),s=e=>{let t=e?.closest(`tr[data-row]`);return t&&t.parentElement===i.parentElement&&t!==i?t:null},c=(e,t)=>t>e.getBoundingClientRect().top+e.offsetHeight/2;wV(t,{source:i,ghost:()=>L(`div`,{class:`dw-db-ghost--row`},uz(e,rz(this.db))||r.untitledRow),over:(e,t,r)=>{o(),n=s(e),n&&n.classList.add(c(n,r)?`is-drop-below`:`is-drop-above`)},drop:(t,n,r)=>{let i=s(t);i?.dataset.row&&this.moveRowBeside(e.id,i.dataset.row,c(i,r))},end:o,hold:()=>this.rowMenu(i,e)})}}i.append(a);for(let n of t){let t=L(`td`,{dataset:{col:n.id},class:`dw-db-t__cell dw-db-t__cell--${n.type}`,role:`gridcell`},MB(this.ctx(),e,n));if(n.type===`title`){let n=L(`button`,{type:`button`,class:`dw-db-t__open`,title:r.openRow},uB(`open`,13),L(`span`,{},r.openRow));n.addEventListener(`click`,t=>{t.stopPropagation(),this.openRow(e.id)}),t.append(n)}t.addEventListener(`mousedown`,t=>{t.target.closest(`input, button, a`)||(this.anchor=t.shiftKey&&this.sel?this.anchor??this.sel:null,this.sel={row:e.id,col:n.id},t.shiftKey||(this.anchor=null),this.markSelection(),t.preventDefault(),this.grid?.focus({preventScroll:!0}))});let a=!1;t.addEventListener(`pointerdown`,e=>a=e.pointerType===`touch`),t.addEventListener(`click`,e=>{e.target.closest(`input, button, a`)||e.shiftKey||(n.type===`checkbox`||a)&&this.startEdit()}),t.addEventListener(`dblclick`,()=>this.startEdit()),i.append(t)}return this.editable&&i.append(L(`td`,{class:`dw-db-t__add`})),i.addEventListener(`contextmenu`,t=>{(this.editable||this.host.copyLink)&&(t.preventDefault(),this.rowMenu(i,e))}),i}moveRowBeside(e,t,n){let r=this.host.store;if(!r||e===t)return;let i=r.rowIndex(e),a=r.rowIndex(t)+ +!!n;ithis.openRow(t.id)}];if(i&&a.push({id:`link`,label:n.copyLink,icon:`link`,run:()=>i(t.id)}),r){let e=r.rowIndex(t.id);a.push({id:`above`,label:n.insertAbove,icon:`arrow-up`,run:()=>r.addRow({},e)},{id:`below`,label:n.insertBelow,icon:`arrow-down`,run:()=>r.addRow({},e+1)},{id:`duplicate`,label:n.duplicateRow,icon:`copy`,run:()=>r.duplicateRow(t.id)},{id:`delete`,label:n.deleteRow,icon:`trash`,danger:!0,run:()=>r.deleteRows([t.id])})}Gj(e,a,n.openRow)}range(){if(!this.sel)return null;let e=e=>this.tableRows.findIndex(t=>t.id===e),t=e=>this.tableCols.findIndex(t=>t.id===e),n=this.anchor??this.sel,[r,i,a,o]=[e(n.row),e(this.sel.row),t(n.col),t(this.sel.col)];if(i<0||o<0)return null;let s=r<0?i:r,c=a<0?o:a;return{r0:Math.min(s,i),r1:Math.max(s,i),c0:Math.min(c,o),c1:Math.max(c,o)}}markSelection(){if(!this.grid)return;for(let e of this.grid.querySelectorAll(`.is-selected, .is-in-range`))e.classList.remove(`is-selected`,`is-in-range`);let e=this.range();if(!e||!this.sel)return;for(let t=e.r0;t<=e.r1;t++)for(let n=e.c0;n<=e.c1;n++)this.cellEl(this.tableRows[t].id,this.tableCols[n].id)?.classList.add(`is-in-range`);let t=this.cellEl(this.sel.row,this.sel.col);t?.classList.add(`is-selected`),t?.scrollIntoView({block:`nearest`,inline:`nearest`})}cellEl(e,t){return this.grid?.querySelector(`tr[data-row="${CSS.escape(e)}"] td[data-col="${CSS.escape(t)}"]`)??null}startEdit(e){if(!this.sel||!this.host.store)return;let t=this.db.rows.find(e=>e.id===this.sel.row),n=this.db.columns.find(e=>e.id===this.sel.col),r=this.cellEl(this.sel.row,this.sel.col);t&&n&&r&&NB(this.ctx(),r,t,n,{initial:e,onDone:e=>{e&&this.moveSel(+(e===`down`),e===`right`?1:e===`left`?-1:0,!1),this.drawBody(),this.grid?.focus({preventScroll:!0})}})}moveSel(e,t,n){let r=this.tableRows,i=this.tableCols;if(!r.length||!i.length)return;if(!this.sel)return this.sel={row:r[0].id,col:i[0].id},this.markSelection();this.anchor=n?this.anchor??{...this.sel}:null;let a=Math.max(0,Math.min(r.length-1,r.findIndex(e=>e.id===this.sel.row)+e)),o=Math.max(0,Math.min(i.length-1,i.findIndex(e=>e.id===this.sel.col)+t));this.sel={row:r[a].id,col:i[o].id},this.markSelection()}onGridKey(e){if(e.target.closest(`input, select, textarea`))return;let t=e.ctrlKey||e.metaKey;if(t&&e.key.toLowerCase()===`z`)return e.preventDefault(),e.shiftKey?this.host.redo():this.host.undo();if(t&&e.key.toLowerCase()===`y`)return e.preventDefault(),this.host.redo();if(t)return;let n={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(n)return e.preventDefault(),this.moveSel(n[0],n[1],e.shiftKey);if(this.sel){if(e.key===`Tab`)return e.preventDefault(),this.moveSel(0,e.shiftKey?-1:1,!1);if(e.key===`Escape`)this.sel=null,this.anchor=null,this.markSelection();else{if(e.key===`Enter`||e.key===`F2`)return e.preventDefault(),this.startEdit();if(e.key===` `)return e.preventDefault(),this.db.columns.find(e=>e.id===this.sel.col)?.type===`title`?this.openRow(this.sel.row):this.startEdit();if((e.key===`Delete`||e.key===`Backspace`)&&this.host.store){e.preventDefault();let t=this.range();if(!t)return;let n=[];for(let e=t.r0;e<=t.r1;e++)for(let r=t.c0;r<=t.c1;r++){let t=this.tableCols[r];!OB.includes(t.type)&&!Mz(t)&&n.push({row:this.tableRows[e].id,col:t.id,value:null})}this.host.store.setCells(n)}else if(e.key.length===1&&this.host.store){let t=this.db.columns.find(e=>e.id===this.sel.col);t&&(DB.includes(t.type)||t.type===`select`||t.type===`multiSelect`)&&(e.preventDefault(),this.startEdit(e.key))}}}}onCopy(e){if(e.target.closest(`input, textarea`))return;let t=this.range();if(!t||!e.clipboardData)return;e.preventDefault();let n=[];for(let e=t.r0;e<=t.r1;e++){let r=[];for(let n=t.c0;n<=t.c1;n++)r.push(uz(this.tableRows[e],this.tableCols[n]));n.push(r)}e.clipboardData.setData(`text/plain`,rV(n,` `)),this.host.notify?.(LR(this.labels.copyNotice,(t.r1-t.r0+1)*(t.c1-t.c0+1)))}onPaste(e){if(e.target.closest(`input, textarea`))return;let t=this.host.store,n=e.clipboardData?.getData(`text/plain`);if(!t||!n||!this.sel)return;e.preventDefault();let r=tV(n.replace(/\r?\n$/,``),(n.includes(` `),` `)),i=this.tableRows.findIndex(e=>e.id===this.sel.row),a=this.tableCols.findIndex(e=>e.id===this.sel.col);if(i<0||a<0)return;let o=new Map(this.db.columns.map(e=>[e.id,[...e.options??[]]])),s=[],c=[];r.forEach((e,t)=>{let n=this.tableRows[i+t],r={};e.forEach((e,t)=>{let i=this.tableCols[a+t];if(!i||OB.includes(i.type)||Mz(i))return;let c=oV(e,i,o.get(i.id)??[]);n?s.push({row:n.id,col:i.id,value:c}):c!==null&&(r[i.id]=c)}),n||c.push(r)}),t.tx(()=>{for(let e of this.db.columns){let n=o.get(e.id);n&&n.length!==(e.options?.length??0)&&t.setOptions(e.id,n)}t.setCells(s),c.length&&t.addRows(c)})}drawKanban(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.groupBy);if(!n){this.body.replaceChildren(L(`p`,{class:`dw-db__empty`},t.noGroupColumn));return}let r=hz(this.db,e,this.search),i=_z(r,n,t.noValue,t.checked,t.unchecked),a=gz(this.db,e).filter(e=>e.type!==`title`&&e.id!==n.id),o=rz(this.db),s=r.flatMap(e=>NV(iz(e,n))),c=L(`div`,{class:`dw-db-k`}),l=(t,r,i,a)=>{let o=this.host.store,c=this.db.rows.find(e=>e.id===t);o&&c&&o.tx(()=>{if(r!==i&&o.setCell(t,n.id,bz(c,n,r,i,s)),a&&a!==t&&!e.sorts.length){let e=o.rowIndex(t),n=o.rowIndex(a);ee||n.type===`checkbox`?{[n.id]:bz(d,n,``,e,s)}:{};for(let r of i){if(!r.key&&!r.rows.length&&n.type!==`checkbox`&&(n.options?.length??0)>0)continue;let i=L(`div`,{class:`dw-db-k__cards`,dataset:{group:r.key}}),s=n.options?.find(e=>e.id===r.key),d=L(`div`,{class:`dw-db-k__head`},s?L(`span`,{class:`dw-db-k__dot`,dataset:{color:s.color},"aria-hidden":`true`}):n.type===`checkbox`?L(`span`,{class:r.key===`true`?`dw-db-check is-on`:`dw-db-check`,"aria-hidden":`true`},r.key===`true`?uB(`check`,12):null):null,L(`span`,{class:`dw-db-k__label`,title:r.label},r.label),L(`span`,{class:`dw-db-k__count`},String(r.rows.length)));if(this.editable){let i=L(`span`,{class:`dw-db-k__tools`});u&&s&&i.append(dB(`more`,t.groupMenu,e=>this.groupMenu(e.currentTarget,n,s.id))),i.append(dB(`plus`,t.newRow,()=>{let t=this.host.store,n=r.rows.length&&!e.sorts.length&&t?t.rowIndex(r.rows[0].id):void 0;this.addRow(f(r.key),!0,n)})),d.append(i)}for(let e of r.rows.slice(0,this.limit)){let t=L(`div`,{class:`dw-db-k__card`,tabIndex:0,role:`button`,draggable:this.editable&&!OB.includes(n.type),dataset:{row:e.id}},L(`div`,{class:`dw-db-k__title`},MB(this.ctx(),e,o)),a.flatMap(t=>uz(e,t)===``||t.type===`checkbox`&&iz(e,t)!==!0?[]:[L(`div`,{class:`dw-db-k__prop`,title:t.name},MB(this.ctx(),e,t))]));if(t.addEventListener(`click`,()=>this.openRow(e.id)),t.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),this.openRow(e.id))}),t.addEventListener(`dragstart`,n=>{n.dataTransfer?.setData(`application/x-docwell-card`,JSON.stringify({row:e.id,from:r.key})),n.dataTransfer&&(n.dataTransfer.effectAllowed=`move`),t.classList.add(`is-dragging`)}),t.addEventListener(`dragend`,()=>t.classList.remove(`is-dragging`)),t.draggable){let n=L(`span`,{class:`dw-db-k__grip`,"aria-hidden":`true`},uB(`grip`,14));t.append(n);let i=null,a=e=>{let t=e?.closest(`.dw-db-k__cards`);return t&&c.contains(t)?t:null};wV(n,{source:t,ghost:()=>t.cloneNode(!0),over:e=>{i?.classList.remove(`is-drop`),i=a(e),i?.classList.add(`is-drop`)},drop:t=>{let n=a(t);n&&l(e.id,r.key,n.dataset.group??``,t?.closest(`.dw-db-k__card`)?.dataset.row)},end:()=>i?.classList.remove(`is-drop`)})}i.append(t)}if(this.editable){let e=L(`button`,{type:`button`,class:`dw-db-t__new`},uB(`plus`,14),L(`span`,{},t.newRow));e.addEventListener(`click`,()=>this.addRow(f(r.key),!0)),i.append(e),i.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-card`)&&(e.preventDefault(),i.classList.add(`is-drop`))}),i.addEventListener(`dragleave`,e=>{i.contains(e.relatedTarget)||i.classList.remove(`is-drop`)}),i.addEventListener(`drop`,e=>{i.classList.remove(`is-drop`);let t=e.dataTransfer?.getData(`application/x-docwell-card`),n=this.host.store;if(!t||!n)return;e.preventDefault();let{row:a,from:o}=JSON.parse(t);l(a,o,r.key,e.target.closest(`.dw-db-k__card`)?.dataset.row)})}let p=L(`section`,{class:`dw-db-k__col`,"aria-label":r.label,dataset:{group:r.key}},d,i);u&&s&&this.reorderableGroup(p,d,n,s.id),c.append(p)}u&&c.append(this.newGroupColumn(n)),this.body.replaceChildren(c)}groupMenu(e,t,n){let r=this.labels,i=this.host.store,a=t.options??[],o=a.find(e=>e.id===n);if(!i||!o)return;let s=e=>i.setOptions(t.id,a.map(t=>t.id===n?{...t,...e}:t));Gj(e,[{id:`rename`,label:r.renameOption,icon:`pencil`,run:()=>{let e=window.prompt(r.renameOption,o.name)?.trim();e&&s({name:e})}},{id:`color`,label:r.optionColor,icon:`palette`,children:PP.map(e=>({id:e,label:this.host.colorNames[e]??e,icon:e===o.color?`check`:`drop`,run:()=>s({color:e})}))},{id:`delete`,label:r.deleteOption,icon:`trash`,danger:!0,run:()=>{window.confirm(LR(r.deleteGroupConfirm,o.name))&&i.setOptions(t.id,a.filter(e=>e.id!==n))}}],r.groupMenu)}reorderableGroup(e,t,n,r){let i=`application/x-docwell-group`;t.draggable=!0,t.addEventListener(`dragstart`,t=>{t.target.closest?.(`button`)||(t.dataTransfer?.setData(i,r),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`),e.classList.add(`is-dragging`))}),t.addEventListener(`dragend`,()=>e.classList.remove(`is-dragging`)),e.addEventListener(`dragover`,t=>{t.dataTransfer?.types.includes(i)&&(t.preventDefault(),e.classList.add(`is-drop-col`))}),e.addEventListener(`dragleave`,t=>{e.contains(t.relatedTarget)||e.classList.remove(`is-drop-col`)}),e.addEventListener(`drop`,t=>{e.classList.remove(`is-drop-col`);let a=t.dataTransfer?.getData(i),o=this.host.store;if(!a||a===r||!o)return;t.preventDefault();let s=n.options??[],c=s.find(e=>e.id===a);if(!c)return;let l=s.filter(e=>e.id!==a),u=e.getBoundingClientRect(),d=l.findIndex(e=>e.id===r)+ +(t.clientX>u.left+u.width/2);l.splice(d,0,c),o.setOptions(n.id,l)})}newGroupColumn(e){let t=this.labels,n=L(`div`,{class:`dw-db-k__add`}),r=L(`button`,{type:`button`,class:`dw-db-t__new`},uB(`plus`,14),L(`span`,{},t.newGroup));return r.addEventListener(`click`,()=>{let i=hB(``,{placeholder:t.newGroupPlaceholder,onCommit:t=>{let i=t.trim(),a=e.options??[];i&&this.host.store?this.host.store.setOptions(e.id,[...a,{id:qR(),name:i,color:xz(a)}]):n.replaceChildren(r)},onCancel:()=>n.replaceChildren(r)});n.replaceChildren(i),i.focus()}),n.append(r),n}drawItems(e){let t=this.labels,n=e.type===`gallery`,r=hz(this.db,e,this.search),i=e.groupBy?this.db.columns.find(t=>t.id===e.groupBy):void 0,a=i?_z(r,i,t.noValue,t.checked,t.unchecked).filter(e=>e.rows.length||e.key!==``):[{key:``,label:``,rows:r}],o=rz(this.db),s=gz(this.db,e).filter(t=>t.type!==`title`&&t.id!==e.cover),c=n?this.db.columns.find(t=>t.id===e.cover&&t.type===`attachment`):void 0,l=this.ctx(),u=e=>s.flatMap(t=>uz(e,t)===``||t.type===`checkbox`&&iz(e,t)!==!0?[]:[L(`span`,{class:`dw-db-i__prop`,title:t.name},MB(l,e,t))]),d=e=>{let t=[];if(n){let n=c?wz(iz(e,c)):``;t.push(L(`div`,{class:n?`dw-db-i__cover`:`dw-db-i__cover is-empty`,"aria-hidden":`true`},n?L(`img`,{src:l.files?l.files.resolve(n):n,alt:``,loading:`lazy`,draggable:!1}):null))}t.push(L(`div`,{class:`dw-db-i__title`},MB(l,e,o)),L(`div`,{class:`dw-db-i__props`},u(e)));let r=L(`div`,{class:`dw-db-i__item`,tabIndex:0,role:`button`,dataset:{row:e.id}},t);return r.addEventListener(`click`,t=>{t.target.closest(`a`)||this.openRow(e.id)}),r.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),this.openRow(e.id))}),r},f=L(`div`,{class:n?`dw-db-i dw-db-i--gallery`:`dw-db-i dw-db-i--list`}),p=0;for(let n of a){let r=`${e.id}:${n.key}`,a=L(`section`,{class:`dw-db-i__group`,"aria-label":n.label||void 0});if(i){let e=!this.collapsed.has(r),t=L(`button`,{type:`button`,class:`dw-db-t__group`,"aria-expanded":String(e)},uB(e?`chevron-down`:`chevron-right`,14),n.key&&i.type!==`checkbox`&&i.type!==`member`&&i.type!==`createdBy`?L(`span`,{class:`dw-db-tag`,dataset:{color:n.color??`gray`}},n.label):L(`span`,{},n.label),L(`span`,{class:`dw-db-t__count`},String(n.rows.length)));if(t.addEventListener(`click`,()=>{e?this.collapsed.add(r):this.collapsed.delete(r),this.drawBody()}),a.append(t),!e){f.append(a);continue}}let o=L(`div`,{class:`dw-db-i__items`});for(let e of n.rows){if(p>=this.limit)break;p++,o.append(d(e))}if(this.editable&&p{let e={};if(i&&(n.key||i.type===`checkbox`)){let t={id:``,cells:{},createdAt:0,createdBy:null};e[i.id]=bz(t,i,``,n.key,n.rows.flatMap(e=>NV(iz(e,i))))}this.addRow(e,!0)}),o.append(e)}a.append(o),f.append(a)}let m=[f];if(r.length||m.push(L(`p`,{class:`dw-db__empty`},this.db.rows.length?t.noMatches:t.noRows)),r.length>p&&p>=this.limit){let e=L(`button`,{type:`button`,class:`dw-db__btn dw-db__more`},`${t.more} (${r.length-p})`);e.addEventListener(`click`,()=>{this.limit+=DV,this.drawBody()}),m.push(e)}this.body.replaceChildren(...m)}drawChart(e){let t=this.labels,n=hz(this.db,e,this.search),r=Az(this.db,e.chart,n,t.noValue,t.checked,t.unchecked);if(!r){this.body.replaceChildren(L(`p`,{class:`dw-db__empty`},t.noChartAxis));return}if(!r.length||r.every(e=>e.value===0)){this.body.replaceChildren(L(`p`,{class:`dw-db__empty`},n.length?t.noChartData:this.db.rows.length?t.noMatches:t.noRows));return}let i=this.host.locale,a=new Intl.NumberFormat(i,{maximumFractionDigits:2}),o=e=>new Date(`${e}-15T12:00:00Z`).toLocaleDateString(i,{month:`short`,year:`numeric`,timeZone:`UTC`}),s=e=>/^\d{4}-\d{2}$/.test(e.key)&&e.key===e.label?o(e.key):e.label,c=t=>`${s(t)}: ${a.format(t.value)}${e.chart.op===`count`?``:` (${t.count})`}`,l=e.chart.type===`donut`?this.donut(r,s,c,a):this.axes(e.chart.type,r,s,c,a);this.body.replaceChildren(L(`div`,{class:`dw-db-ch`},l))}axes(e,t,n,r,i){let a=Math.max(320,44+t.length*56+8),o=jz(Math.max(...t.map(e=>e.value))),s=Math.min(0,...t.map(e=>e.value)),c=o-s||1,l=e=>196-(e-s)/c*180,u=jV(`svg`,{class:`dw-db-ch__svg`,viewBox:`0 0 ${a} 240`,width:String(a),height:`240`,role:`img`,"aria-label":this.db.title||this.labels.viewChart});for(let e=0;e<=4;e++){let t=s+c*e/4,n=l(t);u.append(jV(`line`,{class:`dw-db-ch__grid`,x1:`44`,x2:String(a-4),y1:String(n),y2:String(n)}),jV(`text`,{class:`dw-db-ch__tick`,x:`38`,y:String(n+4),"text-anchor":`end`},i.format(t)))}let d=e=>44+e*56+28;return e===`line`&&u.append(jV(`polyline`,{class:`dw-db-ch__line`,points:t.map((e,t)=>`${d(t)},${l(e.value)}`).join(` `)})),t.forEach((t,a)=>{let o=d(a),s=l(t.value),c=l(0),f=e===`bar`?jV(`rect`,{class:`dw-db-ch__bar`,x:String(o-17.92),y:String(Math.min(s,c)),width:`35.84`,height:String(Math.max(Math.abs(c-s),1)),rx:`3`,"data-color":t.color??``}):jV(`circle`,{class:`dw-db-ch__dot`,cx:String(o),cy:String(s),r:`4`});f.append(jV(`title`,{},r(t)));let p=n(t);u.append(f,jV(`text`,{class:`dw-db-ch__value`,x:String(o),y:String(Math.min(s,c)-5),"text-anchor":`middle`},i.format(t.value)),jV(`text`,{class:`dw-db-ch__label`,x:String(o),y:`214`,"text-anchor":`middle`},p.length>9?`${p.slice(0,8)}…`:p,jV(`title`,{},p)))}),L(`div`,{class:`dw-db-ch__scroll`},u)}donut(e,t,n,r){let i=e.filter(e=>e.value>0),a=i.reduce((e,t)=>e+t.value,0),o=2*Math.PI*70,s=jV(`svg`,{class:`dw-db-ch__svg dw-db-ch__donut`,viewBox:`0 0 200 200`,width:`200`,height:`200`,role:`img`,"aria-label":this.db.title||this.labels.viewChart}),c=[`blue`,`green`,`orange`,`purple`,`teal`,`pink`,`yellow`,`red`,`gray`],l=(e,t)=>e.color??c[t%c.length],u=0;return i.forEach((e,t)=>{let r=e.value/a*o,i=jV(`circle`,{class:`dw-db-ch__slice`,cx:`100`,cy:`100`,r:`70`,"stroke-dasharray":`${r} ${o-r}`,"stroke-dashoffset":String(-u),transform:`rotate(-90 100 100)`,"data-color":l(e,t)});i.append(jV(`title`,{},n(e))),s.append(i),u+=r}),s.append(jV(`text`,{class:`dw-db-ch__total`,x:`100`,y:`108`,"text-anchor":`middle`},r.format(a))),L(`div`,{class:`dw-db-ch__pie`},s,L(`ul`,{class:`dw-db-ch__legend`},i.map((e,i)=>L(`li`,{title:n(e)},L(`span`,{class:`dw-db-ch__swatch`,dataset:{color:l(e,i)},"aria-hidden":`true`}),L(`span`,{class:`dw-db-ch__name`},t(e)),L(`span`,{class:`dw-db-ch__num`},`${r.format(e.value)} · ${Math.round(e.value/a*100)}%`)))))}drawTimeline(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.dateColumn);if(!n){this.body.replaceChildren(L(`p`,{class:`dw-db__empty`},t.noStartColumn));return}let r=this.db.columns.find(t=>t.id===e.endColumn&&t.type===`date`),i=this.tlScale??e.scale,{px:a,days:o,step:s}=Oz[i],c=sz(new Date),l=this.tlFrom||kz(c,i),u=Ez(l,o-1),d=this.editable&&n.type===`date`,f=rz(this.db),p=hz(this.db,e,this.search),m=[],h=[];for(let e of p){let t=Dz(e,n,r);t?m.push({r:e,span:t}):h.push(e)}let g=this.host.locale,_=(e,t)=>new Date(`${e}T12:00:00Z`).toLocaleDateString(g,{...t,timeZone:`UTC`}),v=e=>{this.tlFrom=Ez(l,e),this.drawBody()},y=L(`div`,{class:`dw-db-tl__zoom`,role:`group`});for(let n of KR){let r=n===`day`?t.scaleDay:n===`week`?t.scaleWeek:t.scaleMonth,a=L(`button`,{type:`button`,class:n===i?`dw-db__btn is-on`:`dw-db__btn`,"aria-pressed":String(n===i)},r);a.addEventListener(`click`,()=>{this.tlFrom=``,this.editable&&this.host.store?(this.tlScale=null,this.host.store.updateView(e.id,{scale:n})):(this.tlScale=n,this.drawBody())}),y.append(a)}let b=L(`div`,{class:`dw-db-c__nav`},L(`strong`,{class:`dw-db-c__month`},`${_(l,{day:`numeric`,month:`short`})} – ${_(u,{day:`numeric`,month:`short`,year:`numeric`})}`),dB(`chevron-left`,t.earlier,()=>v(-s)),dB(`chevron-right`,t.later,()=>v(s)),dB(`calendar`,t.today,()=>{this.tlFrom=``,this.drawBody()},t.today),y),x=o*a,S=L(`div`,{class:`dw-db-tl__ticks`,style:{width:`${x}px`}});for(let e=0;e=5&&i!==`month`;if(!r&&!o)continue;let s=L(`span`,{class:`dw-db-tl__tick${r?``:` is-blank`}${o?` is-weekend`:``}`,style:{left:`${e*a}px`,width:`${a}px`}},r);S.append(s)}let C=Tz(l,c),ee=()=>{let e=[];return C>=0&&Cthis.openRow(e.id));let u=L(`div`,{class:`dw-db-tl__track`},...ee()),p=Tz(l,i.from),m=Tz(l,i.to)+1;if(m>0&&po?` is-cut-end`:``}${d?` is-movable`:``}`,style:{left:`${c*a}px`,width:`${Math.max((l-c)*a,4)}px`},role:`button`,tabIndex:0,title:`${s}: ${i.from===i.to?i.from:`${i.from} – ${i.to}`}`,dataset:{row:e.id}},L(`span`,{class:`dw-db-tl__bar-text`},s));f.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),this.openRow(e.id))});let h=d&&r&&m<=o?L(`span`,{class:`dw-db-tl__handle`,title:t.dragEnd,"aria-hidden":`true`}):null;h&&f.append(h),this.dragBar(f,h,a,(t,a)=>{let o=this.host.store;if(o){if(!t&&!a)return this.openRow(e.id);o.tx(()=>{if(a){let t=Ez(i.to,a);r&&o.setCell(e.id,r.id,tthis.addRow(n.type===`date`?{[n.id]:c}:{},!0)),te.append(L(`div`,{class:`dw-db-tl__row dw-db-tl__row--new`},e))}let ne=[b,L(`div`,{class:`dw-db-tl__scroll`},te)];if(p.length||ne.push(L(`p`,{class:`dw-db__empty`},this.db.rows.length?t.noMatches:t.noRows)),m.length>this.limit){let e=L(`button`,{type:`button`,class:`dw-db__btn dw-db__more`},`${t.more} (${m.length-this.limit})`);e.addEventListener(`click`,()=>{this.limit+=DV,this.drawBody()}),ne.push(e)}if(h.length){let e=h.slice(0,this.limit).map(e=>{let n=L(`button`,{type:`button`,class:`dw-db-c__chip`},uz(e,f)||t.untitledRow);return n.addEventListener(`click`,()=>this.openRow(e.id)),n});ne.push(L(`details`,{class:`dw-db-c__undated`},L(`summary`,{},LR(t.noDate,h.length)),L(`div`,{class:`dw-db-c__chips`},e)))}this.body.replaceChildren(L(`div`,{class:`dw-db-tl`},ne))}dragBar(e,t,n,r,i){e.addEventListener(`dragstart`,e=>{e.preventDefault(),e.stopPropagation()}),e.addEventListener(`pointerdown`,a=>{if(a.button!==0)return;a.pointerType===`mouse`&&a.preventDefault(),a.stopPropagation();let o=!!t&&a.target===t,s=a.clientX,c=a.clientY,l=e.offsetWidth,u=0,d=!1;try{e.setPointerCapture(a.pointerId)}catch{}let f=t=>{let r=t.clientX-s;!d&&Math.abs(r)<4?Math.abs(t.clientY-c)>8&&p():i&&(d=!0,u=Math.round(r/n),e.classList.add(`is-dragging`),o?e.style.width=`${Math.max(l+u*n,n)}px`:e.style.transform=`translateX(${u*n}px)`)},p=()=>{e.removeEventListener(`pointermove`,f),e.removeEventListener(`pointerup`,m),e.removeEventListener(`pointercancel`,h),e.hasPointerCapture(a.pointerId)&&e.releasePointerCapture(a.pointerId)},m=()=>{p(),e.classList.remove(`is-dragging`),e.style.transform=``,o&&(e.style.width=`${l}px`),d?u&&r(o?0:u,o?u:0):r(0,0)},h=()=>{p(),e.classList.remove(`is-dragging`),e.style.transform=``,e.style.width=`${l}px`};e.addEventListener(`pointermove`,f),e.addEventListener(`pointerup`,m),e.addEventListener(`pointercancel`,h)})}drawCalendar(e){let t=this.labels,n=this.db.columns.find(t=>t.id===e.dateColumn);if(!n){this.body.replaceChildren(L(`p`,{class:`dw-db__empty`},t.noDateColumn));return}let r=this.editable&&n.type===`date`,{y:i,m:a}=this.month,o=Cz(i,a),s=hz(this.db,e,this.search),c=new Map,l=[];for(let e of s){let t=oz(iz(e,n));t?c.set(t,[...c.get(t)??[],e]):l.push(e)}let u=rz(this.db),d=sz(new Date),f=new Date(i,a,1).toLocaleDateString(this.host.locale,{month:`long`,year:`numeric`}),p=e=>{let t=new Date(i,a+e,1);this.month={y:t.getFullYear(),m:t.getMonth()},this.drawBody()},m=L(`div`,{class:`dw-db-c__nav`},L(`strong`,{class:`dw-db-c__month`},f),dB(`chevron-left`,t.previousMonth,()=>p(-1)),dB(`chevron-right`,t.nextMonth,()=>p(1)),dB(`calendar`,t.today,()=>{let e=new Date;this.month={y:e.getFullYear(),m:e.getMonth()},this.drawBody()},t.today)),h=o.slice(0,7).map(e=>{let[t,n,r]=e.split(`-`).map(Number);return L(`div`,{class:`dw-db-c__wd`},new Date(t,n-1,r).toLocaleDateString(this.host.locale,{weekday:`short`}))}),g=e=>{let i=L(`button`,{type:`button`,class:`dw-db-c__chip`,draggable:r,dataset:{row:e.id}},uz(e,u)||t.untitledRow);if(i.addEventListener(`click`,()=>this.openRow(e.id)),i.addEventListener(`dragstart`,t=>{t.dataTransfer?.setData(`application/x-docwell-row-date`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),r){let t=null,r=e=>{let t=e?.closest(`.dw-db-c__day`);return t&&this.body.contains(t)?t:null};wV(i,{source:i,ghost:()=>i.cloneNode(!0),over:e=>{t?.classList.remove(`is-drop`),t=r(e),t?.classList.add(`is-drop`)},drop:t=>{let i=r(t)?.dataset.day;i&&this.host.store?.setCell(e.id,n.id,i)},end:()=>t?.classList.remove(`is-drop`)})}return i},_=L(`div`,{class:`dw-db-c__grid`,role:`grid`},h);for(let e of o){let i=L(`div`,{class:`dw-db-c__day${Number(e.slice(5,7))===a+1?``:` is-out`}${e===d?` is-today`:``}`,role:`gridcell`,dataset:{day:e}},L(`span`,{class:`dw-db-c__num`},String(Number(e.slice(8)))),(c.get(e)??[]).map(g));if(this.editable&&n.type===`date`){let r=L(`button`,{type:`button`,class:`dw-db-c__add`,"aria-label":`${t.newRow} ${e}`,title:t.newRow},uB(`plus`,12));r.addEventListener(`click`,()=>this.addRow({[n.id]:e},!0)),i.append(r)}r&&(i.addEventListener(`dragover`,e=>{e.dataTransfer?.types.includes(`application/x-docwell-row-date`)&&(e.preventDefault(),i.classList.add(`is-drop`))}),i.addEventListener(`dragleave`,()=>i.classList.remove(`is-drop`)),i.addEventListener(`drop`,t=>{i.classList.remove(`is-drop`);let r=t.dataTransfer?.getData(`application/x-docwell-row-date`);r&&(t.preventDefault(),this.host.store?.setCell(r,n.id,e))})),_.append(i)}let v=[m,_];l.length&&v.push(L(`details`,{class:`dw-db-c__undated`},L(`summary`,{},LR(t.noDate,l.length)),L(`div`,{class:`dw-db-c__chips`},l.slice(0,this.limit).map(g)))),this.body.replaceChildren(L(`div`,{class:`dw-db-c`},v))}},kV={id:``,name:``,type:`table`,hidden:[],filters:[],filterMode:`and`,sorts:[],groupBy:null,dateColumn:null,cover:null,endColumn:null,scale:`week`,chart:{type:`bar`,x:null,op:`count`,y:null},widths:{}},AV={table:`table`,kanban:`cards`,calendar:`calendar`,list:`list`,gallery:`grid`,timeline:`timeline`,chart:`chart`};function jV(e,t,...n){let r=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,n]of Object.entries(t))n!==``&&r.setAttribute(e,n);return r.append(...n),r}var MV=[`table`,`list`,`gallery`];function NV(e){return Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`):[]}var PV=`[A-Za-z0-9]{1,32}`,FV=(e,t)=>`#r-${e}-${t}`;function IV(e){let t=RegExp(`^#?r-(${PV})-(${PV})$`).exec(e);return t?{database:t[1],row:t[2]}:null}var LV=`dw-open-record`;function RV(e,t,n,r){let i=-1;if(e.state.doc.descendants((e,n)=>i>=0?!1:(e.type.name===`database`&&e.attrs.id===t&&(i=n),!0)),i<0)return!1;let a=e.view.nodeDOM(i);if(!(a instanceof HTMLElement))return!1;let o={row:n,...r};return a.dispatchEvent(new CustomEvent(LV,{detail:o})),!!o.found}async function zV(e){try{return await navigator.clipboard.writeText(e),!0}catch{return!1}}var BV=e=>(e??BR).database;function VV(e){let t=BV(e);return{tableView:t.viewTable,columnName:e=>e===`title`?t.typeTitle:MR(t,e)}}var HV=e=>bw(e).content??[];function UV(e,t){let n=[];return e.forEach(e=>{e.type.name===`database`?n.push(t(e)):e.content.size?n.push(e.copy(UV(e.content,t))):n.push(e)}),s.from(n)}function WV(e){let t=!1;return e.descendants(e=>(e.type.name===`database`&&(t=!0),!t)),t}var GV=qp.create({name:`database`,group:`block`,atom:!0,draggable:!0,selectable:!0,addOptions(){return{labels:null,doc:void 0,readOnlyDoc:!1,undoScope:!0,files:void 0,people:void 0,me:void 0,rowExtensions:void 0,notify:void 0,recordLink:void 0,onLinkCopied:void 0,linkedPages:void 0,pages:void 0,onNavigate:void 0,recordPage:void 0}},addAttributes(){return{id:{default:``,parseHTML:e=>e.getAttribute(`data-id`)??``,renderHTML:e=>({"data-id":e.id})},data:{default:null,parseHTML:e=>{try{let t=e.getAttribute(`data-db`);return t?JSON.parse(t):null}catch{return null}},renderHTML:e=>e.data?{"data-db":JSON.stringify(e.data)}:{}}}},parseHTML(){return[{tag:`div[data-type='database']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=j(t,{"data-type":`database`});if(!e.attrs.data)return[`div`,n];let r=$R(e.attrs.data),i=r.views[0],a=r.columns.filter(e=>e.type===`title`||!i?.hidden.includes(e.id));return[`div`,n,[`p`,{},[`strong`,{},r.title||BV(this.options.labels).untitled]],[`table`,{},[`tr`,{},...a.map(e=>[`th`,{},e.name])],...r.rows.map(e=>[`tr`,{},...a.map(t=>[`td`,{},uz(e,t)])])]]},renderText({node:e}){let t=e.attrs.data?$R(e.attrs.data):null;if(!t)return``;let n=rz(t);return[t.title,...t.rows.map(e=>uz(e,n))].filter(Boolean).join(` +`)},onCreate(){let{doc:e,readOnlyDoc:t,undoScope:n}=this.options;e&&!t&&n&&(FS.getState(this.editor.state)?.undoManager)?.addToScope(zB(e))},addCommands(){let e=e=>{let t=qR(),{doc:n,readOnlyDoc:r}=this.options;return!n||r?{id:t,data:e}:(eV(n,t,e,(e,t)=>KV(this.editor,e,t)),{id:t,data:null})};return{insertDatabase:t=>({commands:n})=>n.insertContent([{type:this.name,attrs:e(t??YB(VV(this.options.labels)))},{type:`paragraph`}]),groupAsDatabase:()=>({state:t,dispatch:n,commands:r})=>{let i=YV(t.selection.$from,t.selection.$to);if(!i)return!1;if(!n)return!0;let a=BV(this.options.labels),o={id:qR(),name:a.typeTitle,type:`title`},s=[o],c=i.checks?{id:qR(),name:a.done,type:`checkbox`}:null;c&&s.push(c);let l=Date.now(),u={title:``,columns:s,rows:i.items.map((e,t)=>({id:qR(),cells:{[o.id]:e.text,...c&&e.checked?{[c.id]:!0}:{}},createdAt:l+t,createdBy:this.options.me?.()??null,body:e.rest.length?e.rest:void 0})),views:[JR(`table`,a.viewTable,s)]},d=this.type.create(e(u));return r.command(({tr:e})=>(e.replaceWith(i.from,i.to,d),e.setSelection(E.create(e.doc,i.from)),!0))}}},addKeyboardShortcuts(){return{"Mod-g":()=>this.editor.commands.groupAsDatabase()}},addProseMirrorPlugins(){let{doc:e,readOnlyDoc:t}=this.options,n=e&&!t?e:null,r=this.editor;return[new D({key:new O(`databaseClipboard`),props:{transformCopied:t=>!e||!WV(t.content)?t:new p(UV(t.content,t=>{let n=zB(e).get(String(t.attrs.id));return n instanceof zb?t.type.create({...t.attrs,data:$B(n,HV)}):t}),t.openStart,t.openEnd),transformPasted:e=>WV(e.content)?new p(UV(e.content,e=>{let t=qR();if(!n)return e.type.create({...e.attrs,id:t});let i=e.attrs.data?$R(e.attrs.data):null,a=zB(n).get(String(e.attrs.id)),o=i??(a instanceof zb?$B(a,HV):YB(VV(this.options.labels)));return eV(n,t,JV(o),(e,t)=>KV(r,e,t)),e.type.create({id:t,data:null})}),e.openStart,e.openEnd):e},appendTransaction:(e,t,i)=>{if(!n||!e.some(e=>e.docChanged&&!e.getMeta(PS))||!e.some(e=>e.steps.some(e=>WV(e.slice?.content??s.empty))))return null;let a=new Set,o=[];if(i.doc.descendants((e,t)=>{if(e.type.name!==`database`)return;let n=String(e.attrs.id);return n&&a.has(n)&&o.push({pos:t,node:e}),a.add(n),!1}),!o.length)return null;let c=i.tr;for(let{pos:e,node:t}of o){let i=zB(n).get(String(t.attrs.id)),a=qR();i instanceof zb&&eV(n,a,JV($B(i,HV)),(e,t)=>KV(r,e,t)),c.setNodeMarkup(e,void 0,{...t.attrs,id:a,data:null})}return c}})]},addNodeView(){let e=this.options;return({node:t,editor:n,getPos:r})=>{let i=t,a=e.labels??BR,o=e.doc,s=()=>n.isEditable&&!!o&&!e.readOnlyDoc,c=null,l=null,u=null,d=null,f=L(`div`,{class:`dw-db-node`}),p=()=>String(i.attrs.id),m=()=>{let e=o?zB(o).get(p()):void 0;return e instanceof zb?e:null},h=()=>{let t=m();return t?JB(t):i.attrs.data?$R(i.attrs.data):YB(VV(e.labels))},g=e=>{let t=o?zB(o).get(e):void 0;if(t instanceof zb)return JB(t);let r=null;return n.state.doc.descendants(t=>!r&&(t.type.name===`database`&&t.attrs.id===e&&t.attrs.data&&(r=$R(t.attrs.data)),!0)),r},_=new Map,v=t=>{let n=e.linkedPages;if(!n)return null;let r=_.get(t);if(!r){let e=n.open(t),i=e.onChange(re);e.doc.on(`update`,re),r={provider:e,stop:()=>{i(),e.doc.off(`update`,re),e.destroy()}},_.set(t,r)}return r.provider},y=t=>!t||t===e.linkedPages?.self,b=new Set,x=e=>{if(y(e.page))return b.add(e.database),e.database===p()?h():g(e.database);let t=v(e.page);if(!t?.synced)return null;let n=zB(t.doc).get(e.database);return n instanceof zb?JB(n):null},S=(e,t,n)=>{let r=[],i=e=>{for(let a of e.toArray())if(a instanceof cx){if(a.nodeName===`database`){let e=String(a.getAttribute(`id`)??``);e&&r.push({page:t,database:e,title:n(e)?.title??``})}else i(a)}};return i(e),r},C=t=>{if(!s()||!o||!y(t.page))return null;if(t.database===p())return c;let n=zB(o).get(t.database);return n instanceof zb?new ZB(o,n,()=>e.me?.()??null):null},ee={local:()=>{let e=[];return n.state.doc.descendants(t=>(t.type.name===`database`&&t.attrs.id&&t.attrs.id!==p()&&e.push({page:``,database:String(t.attrs.id),title:g(String(t.attrs.id))?.title??``}),!0)),e},searchPages:e.pages?t=>e.pages.search(t).then(e=>e.filter(e=>!y(e.id)).map(e=>({id:e.id,title:e.title}))):void 0,databasesOn:e.linkedPages?e=>new Promise(t=>{let n=v(e),r=()=>{t(S(n.doc.getXmlFragment(`default`),e,e=>{let t=zB(n.doc).get(e);return t instanceof zb?JB(t):null}))};if(n.synced)return r();let i=setTimeout(()=>{a(),t([])},8e3),a=n.onChange(()=>{n.synced&&(clearTimeout(i),a(),r())})}):void 0,read:x,pointsHere:(t,n)=>n.database===p()?y(t.page)?y(n.page):!!e.linkedPages?.self&&n.page===e.linkedPages.self:!1,writable:e=>!!C(e),link:(e,t,n,r)=>{let i=C(e),a=e.back;if(!i||!a)return!1;let o=i.snapshot().rows.find(e=>e.id===n);if(!o)return!1;let s=Lz(o.cells[a]).filter(e=>e!==t);return r&&s.push(t),i.setCell(n,a,s.length?s:null),!0},addBack:(e,t,n)=>{let r=C(e);return r?(r.tx(()=>{let e=r.addColumn(`relation`,n);r.setRelation(e,{page:``,database:p(),back:t})}),!0):!1},openRecord:(t,r)=>{y(t.page)?RV(n,t.database,r):e.onNavigate?.(`/p/${encodeURIComponent(t.page)}${FV(t.database,r)}`)}},te=e=>{for(let t of e)if((t.path.length?[String(t.path[0])]:[...t.keysChanged??[]]).some(e=>e!==p()&&b.has(e)))return re()};o&&zB(o).observeDeep(te);let ne;function re(){clearTimeout(ne),ne=setTimeout(()=>fe(),60)}let ie=()=>lB(Hz(h(),e=>{let t=x(e);return t&&lB(t)},a.database)),ae=()=>({labels:a.database,colorNames:a.colors,locale:a.locale,files:e.files,people:e.people,store:c,linked:ee}),oe=(t,n)=>{let r=e.rowExtensions;if(!r)return null;let i=m(),o=null;if(i&&(o=c?c.rowBody(n.id):qV(i,n.id),!o))return t.append(L(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),null;let s=new Bp({element:t,editable:!!c,extensions:r(o),content:o?void 0:{type:`doc`,content:n.body??[{type:`paragraph`}]},editorProps:{attributes:{class:`dw-prose dw-db-peek__prose`}}});return!o&&!n.body?.length&&t.replaceChildren(L(`p`,{class:`dw-db-peek__note`},a.database.bodyReadOnly)),()=>s.destroy()},se=e.recordLink,ce=se?t=>{let n=se(FV(p(),t));zV(n).then(t=>t&&e.onLinkCopied?.(n))}:void 0;f.addEventListener(LV,e=>{let t=e.detail,n=ie();n.rows.some(e=>e.id===t.row)&&(t.found=!0,t.container||f.scrollIntoView?.({block:`start`}),de(t.row,n.rows.map(e=>e.id),t.container?{container:t.container,onLeave:t.onClose}:void 0))});let le=e.recordPage,ue,de=(e,t,n)=>{u?.close(!1),ue=n,u=new LB({ctx:{...ae()},mountBody:oe,copyLink:ce,openPage:le&&!n?e=>le(p(),e):void 0,page:n},ie(),e,t,()=>{u=null,ue=void 0})},fe=()=>{let e=ie();d?.update(e,{store:c}),u?.update(e,{store:c})},pe=()=>{if(l?.(),l=null,c=null,!o)return;let t=m();if(!t&&s()){let a=i.attrs.data?$R(i.attrs.data):YB(VV(e.labels)),s=p()?p():qR();eV(o,s,a,(e,t)=>KV(n,e,t)),queueMicrotask(()=>{let e=typeof r==`function`?r():void 0;e!==void 0&&n.state.doc.nodeAt(e)?.type.name===`database`&&n.view.dispatch(n.state.tr.setNodeMarkup(e,void 0,{...i.attrs,id:s,data:null}).setMeta(`addToHistory`,!1))}),t=zB(o).get(s)}let a=zB(o),d=e=>{if(!e.keysChanged.has(p()))return;pe(),fe();let t=u?.row;t&&ie().rows.some(e=>e.id===t)&&de(t,[t],ue)};if(a.observe(d),t){s()&&(c=new ZB(o,t,()=>e.me?.()??null));let n=t,r=()=>fe();n.observeDeep(r),l=()=>{a.unobserve(d),n.unobserveDeep(r)}}else l=()=>a.unobserve(d)};pe(),d=new OV({...ae(),openRow:de,undo:()=>n.commands.undo?.(),redo:()=>n.commands.redo?.(),notify:e.notify,copyLink:ce},ie()),f.append(d.dom);let me=s(),he=()=>{s()!==me&&(me=s(),pe(),fe())};return n.on(`update`,he),n.on(`transaction`,he),{dom:f,update(e){if(e.type!==i.type)return!1;let t=e.attrs.id!==i.attrs.id;return i=e,t&&pe(),fe(),!0},ignoreMutation:()=>!0,stopEvent:e=>e.type!==`dragstart`||e.target!==f,destroy(){l?.(),clearTimeout(ne),o&&zB(o).unobserveDeep(te);for(let e of _.values())e.stop();_.clear(),u?.close(!1),d?.destroy(),n.off(`update`,he),n.off(`transaction`,he)}}}}});function KV(e,t,n){try{xw(e.schema,{type:`doc`,content:t},n)}catch{}}function qV(e,t){let n=e.get(`rows`);if(!(n instanceof Ib))return null;for(let e of n.toArray())if(e.get(`id`)===t){let t=e.get(`body`);return t instanceof ox&&t.length?t:null}return null}function JV(e){return{...e,rows:e.rows.map(e=>({...e,id:qR()}))}}function YV(e,t){for(let t=e.depth;t>0;t--){let n=e.node(t);if([`bulletList`,`orderedList`,`taskList`].includes(n.type.name)){let r=[];return n.forEach(e=>{let t=e.firstChild,n=[];e.forEach((e,t,r)=>{r>0&&n.push(e.toJSON())}),r.push({text:t?.textContent??``,checked:!!e.attrs.checked,rest:n})}),{from:e.before(t),to:e.after(t),checks:n.type.name===`taskList`,items:r}}}if(e.depth<1)return null;let n=e.before(1),r=t.after(Math.min(1,t.depth)||1),i=[];return e.doc.nodesBetween(n,r,(e,t)=>t=r?!1:(e.isTextblock&&e.textContent.trim()&&i.push({text:e.textContent,checked:!1,rest:[]}),!e.isTextblock)),i.length>1?{from:n,to:r,checks:!1,items:i}:null}function XV(e){let t=PS.getState(e);return t?.type&&t.binding&&t.doc?t:null}function ZV(e,t){let n=XV(e);if(!n||!t?.from||!t.to)return null;try{let r=e=>NS(n.doc,n.type,dy(vg(e)),n.binding.mapping),i=r(t.from),a=r(t.to);return i===null||a===null||a<=i||a>e.doc.content.size?null:{from:i,to:a}}catch{return null}}var QV=new O(`docwellComments`);function $V(e,t,n){let r=[];for(let i of t){let t=ZV(e,i.anchor);t&&r.push(_s.inline(t.from,t.to,{class:i.id===n?`dw-comment is-active`:`dw-comment`,"data-comment":i.id}))}return bs.create(e.doc,r)}var eH=wp.create({name:`commentHighlights`,addOptions(){return{onSelect:void 0}},addProseMirrorPlugins(){let e=()=>this.options.onSelect;return[new D({key:QV,state:{init:()=>({marks:[],active:``,decos:bs.empty}),apply(e,t,n,r){let i=e.getMeta(QV);if(i)return{...i,decos:$V(r,i.marks,i.active)};if(!e.docChanged||!t.marks.length)return t;let a=e.getMeta(PS)?.isChangeOrigin;return{...t,decos:a?$V(r,t.marks,t.active):t.decos.map(e.mapping,e.doc)}}},props:{decorations:e=>QV.getState(e)?.decos??bs.empty,handleClick(t,n,r){let i=r.target?.closest?.(`[data-comment]`)?.getAttribute(`data-comment`);return i&&e()?.(i),!1}}})]}}),tH=/^(\d{4})-(\d{2})-(\d{2})$/;function nH(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function rH(e){let t=tH.exec(e);if(!t)return null;let n=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]));return nH(n)===e?n:null}function iH(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t)}function aH(e,t){return Math.round((t.getTime()-e.getTime())/864e5)}function oH(e,t,n=new Date){let r=rH(e);if(!r)return e;let i=t.dates,a=aH(iH(n,0),r);return a===0?i.today:a===1?i.tomorrow:a===-1?i.yesterday:new Intl.DateTimeFormat(t.locale,{month:`short`,day:`numeric`,year:r.getFullYear()===n.getFullYear()?void 0:`numeric`}).format(r)}function sH(e,t){let n=rH(e);return n?new Intl.DateTimeFormat(t.locale,{dateStyle:`full`}).format(n):e}function cH(e,t,n,r=new Date){let i=t.dates,a=e.trim().toLowerCase(),o=!1;for(let e of new Set([i.remindWord.toLowerCase(),`remind`])){if(a.startsWith(e)){o=!0,a=a.slice(e.length).trim();break}if(a.length>=3&&e.startsWith(a)){o=!0,a=``;break}}if(o&&!n)return[];let s=iH(r,0);if(!a)return o?[1,0,7].map(e=>({date:nH(iH(s,e)),remind:o})):[{date:nH(s),remind:!1},...n?[{date:nH(iH(s,1)),remind:!0}]:[]];let c=[{words:[i.today,`today`],date:s},{words:[i.tomorrow,`tomorrow`],date:iH(s,1)},{words:[i.nextWeek,`next week`],date:iH(s,7)}];o||c.push({words:[i.yesterday,`yesterday`],date:iH(s,-1)});let l=e=>new Intl.DateTimeFormat(e,{weekday:`long`});for(let e=1;e<=7;e++){let n=iH(s,e);c.push({words:[l(t.locale).format(n),l(`en`).format(n)],date:n})}let u=[];rH(a)&&u.push({date:a,remind:o});for(let e of c)e.words.some(e=>e.toLowerCase().startsWith(a))&&u.push({date:nH(e.date),remind:o});return u.filter((e,t)=>u.findIndex(t=>t.date===e.date)===t).slice(0,5)}function lH(e,t){let n=e.toLowerCase().split(` `),r=[t.dates.remindWord,`remind`,t.dates.nextWeek.split(` `)[0]??``,`next`];return n.length>1&&n.length<=3&&r.some(e=>e&&e.toLowerCase()===n[0])}var uH=qp.create({name:`dateMention`,group:`inline`,inline:!0,atom:!0,selectable:!0,addOptions(){return{labels:void 0,me:()=>void 0,onOpen:void 0}},addAttributes(){return{date:{default:``,parseHTML:e=>e.getAttribute(`data-date`)??``,renderHTML:e=>({"data-date":e.date})},remind:{default:``,parseHTML:e=>e.getAttribute(`data-remind`)??``,renderHTML:e=>e.remind?{"data-remind":e.remind}:{}},tz:{default:``,parseHTML:e=>e.getAttribute(`data-tz`)??``,renderHTML:e=>e.tz?{"data-tz":e.tz}:{}}}},parseHTML(){return[{tag:`span[data-type="date"]`}]},renderHTML({node:e,HTMLAttributes:t}){return[`span`,j({"data-type":`date`,class:`dw-date`},t),oH(e.attrs.date,this.options.labels)]},renderText({node:e}){return oH(e.attrs.date,this.options.labels)},addNodeView(){let{labels:e,me:t,onOpen:n}=this.options;return({node:r,editor:i,getPos:a})=>{let o=r,s=document.createElement(`span`);s.dataset.type=`date`,s.className=`dw-date`,s.contentEditable=`false`,s.classList.toggle(`is-link`,!!n);let c=null,l=()=>{let t=o.attrs.date,n=o.attrs.remind,r=!!rH(t)&&t{let t=typeof a==`function`?a():void 0;t!==void 0&&i.chain().command(({tr:n})=>(n.setNodeMarkup(t,void 0,{...o.attrs,...e}),!0)).run()};return s.addEventListener(`mousedown`,r=>{c||(i.isEditable?(r.preventDefault(),c=pH(s,i,o,e,t(),u,()=>c=null,n)):n&&rH(o.attrs.date)&&(r.preventDefault(),n(o.attrs.date)))}),{dom:s,update(e){return e.type===o.type&&(o=e,l(),!0)},ignoreMutation:()=>!0,stopEvent:e=>s.contains(e.target)&&e.type!==`mousedown`,destroy(){c?.()}}}}});function dH(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone??``}catch{return``}}function fH(e,t,n,r){let i={date:n.date,remind:n.remind&&r?r:``,tz:n.remind&&r?dH():``};e.chain().focus().insertContentAt(t,[{type:`dateMention`,attrs:i},{type:`text`,text:` `}]).run()}function pH(e,t,n,r,i,a,o,s){let c=r.dates,l=document.createElement(`div`);l.className=`dw-date-pop`,l.setAttribute(`role`,`dialog`),l.setAttribute(`aria-label`,c.edit);let u=document.createElement(`input`);u.type=`date`,u.className=`dw-input`,u.value=n.attrs.date,u.setAttribute(`aria-label`,c.edit),u.addEventListener(`change`,()=>{rH(u.value)&&a({date:u.value})}),l.append(u);let d=n.attrs.remind;if(d&&d!==i){let e=document.createElement(`p`);e.className=`dw-date-pop__note`,e.textContent=c.someoneElse,l.append(e)}else if(i){let e=document.createElement(`label`);e.className=`dw-date-pop__check`;let t=document.createElement(`input`);t.type=`checkbox`,t.checked=d===i,t.addEventListener(`change`,()=>a(t.checked?{remind:i,tz:dH()}:{remind:``,tz:``})),e.append(t,document.createTextNode(c.remindMe));let n=document.createElement(`span`);n.className=`dw-date-pop__note`,n.textContent=c.reminderAt,l.append(e,n)}if(s){let e=document.createElement(`button`);e.type=`button`,e.className=`dw-date-pop__open`,e.textContent=c.openJournal??`Open journal`,e.addEventListener(`click`,()=>{let e=n.attrs.date;h(),rH(e)&&s(e)}),l.append(e)}document.body.append(l);let f=Aj(e,l,()=>{Pj(e,l,{placement:`bottom-start`,strategy:`fixed`,middleware:[jj(6),Nj(),Mj({padding:8})]}).then(({x:e,y:t})=>Object.assign(l.style,{left:`${e}px`,top:`${t}px`}))}),p=t=>{!l.contains(t.target)&&!e.contains(t.target)&&h()},m=e=>{e.key===`Escape`&&(e.preventDefault(),h(),t.commands.focus())};function h(){f(),l.remove(),document.removeEventListener(`mousedown`,p,!0),document.removeEventListener(`keydown`,m,!0),o()}return document.addEventListener(`mousedown`,p,!0),document.addEventListener(`keydown`,m,!0),u.focus(),h}function mH(e){let{char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:o}=e,s=n&&!r,c=Of(t),l=RegExp(`\\s${c}$`),u=a?`^`:``,d=r?``:c,f=RegExp(s?`${u}${c}.*?(?=\\s${d}|$)`:`${u}(?:^)?${c}[^\\s${d}]*`,`gm`),p=o.nodeBefore?.isText&&o.nodeBefore.text;if(!p)return null;let m=o.pos-p.length,h=Array.from(p.matchAll(f)).pop();if(!h||h.input===void 0||h.index===void 0)return null;let g=h.input.slice(Math.max(0,h.index-1),h.index),_=RegExp(`^[${i?.map(Of).join(``)}\0]?$`).test(g);if(i!==null&&!_)return null;let v=m+h.index,y=v+h[0].length;return s&&l.test(p.slice(y-1,y+1))&&(h[0]+=` `,y+=1),v=o.pos?{range:{from:v,to:y},query:h[0].slice(t.length),text:h[0]}:null}function hH(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!t?.content)return!1;let n=t.content.textBetween(0,t.content.size,` +`);return/\s/.test(n)}):!1}function gH(e){return()=>{let t=e.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=e.view.coordsAtPos(t);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}}}function _H(e,t,n,r){return n?()=>{let n=r.getState(e.state)?.decorationId;return t.dom.querySelector(`[data-decoration-id="${n}"]`)?.getBoundingClientRect()||null}:gH(e)}function vH({match:e,dismissedRange:t,state:n,transaction:r,editor:i,shouldResetDismissed:a,effectiveAllowSpaces:o}){return a?.({editor:i,state:n,range:t,match:e,transaction:r,allowSpaces:o})?!1:o?e.range.from===t.from:e.range.from===t.from&&!hH(r)}function yH({view:e,pluginKeyRef:t}){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}function bH({pluginKey:e,decorationTag:t,decorationClass:n,decorationContent:r,decorationEmptyClass:i,renderer:a,dispatchExit:o}){return{handleKeyDown(t,n){var r;let i=e.getState(t.state);if(!i.active)return!1;if(n.key===`Escape`||n.key===`Esc`){var s;return a==null||(s=a.onKeyDown)==null||s.call(a,{view:t,event:n,range:i.range}),o(t),!0}return(a==null||(r=a.onKeyDown)==null?void 0:r.call(a,{view:t,event:n,range:i.range}))||!1},decorations(a){let{active:o,range:s,decorationId:c,query:l}=e.getState(a);if(!o)return null;let u=!l?.length,d=[n];return u&&d.push(i),bs.create(a.doc,[_s.inline(s.from,s.to,{nodeName:t,class:d.join(` `),"data-decoration-id":c||void 0,"data-decoration-content":r})])}}}function xH({editor:e,char:t,effectiveAllowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,findSuggestionMatch:o,allow:s,shouldShow:c,shouldKeepDismissed:l,pluginKey:u}){return{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(d,f,p,m){let{isEditable:h}=e,{composing:g}=e.view,{selection:_}=d,{empty:v,from:y}=_,b={...f},x=d.getMeta(u);if(x&&x.exit)return b.active=!1,b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null,b.dismissedRange=f.active?{...f.range}:f.dismissedRange,b;if(b.composing=g,d.docChanged&&b.dismissedRange!==null&&(b.dismissedRange={from:d.mapping.map(b.dismissedRange.from),to:d.mapping.map(b.dismissedRange.to)}),h&&(v||e.view.composing)){(yf.range.to)&&!g&&!f.composing&&(b.active=!1);let u=o({char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:_.$from}),p=`id_${Math.floor(Math.random()*4294967295)}`;u&&s({editor:e,state:m,range:u.range,isActive:f.active})&&(!c||c({editor:e,range:u.range,query:u.query,text:u.text,transaction:d}))?(b.dismissedRange!==null&&!l({match:u,dismissedRange:b.dismissedRange,state:m,transaction:d})&&(b.dismissedRange=null),b.dismissedRange===null?(b.active=!0,b.decorationId=f.decorationId||p,b.range=u.range,b.query=u.query,b.text=u.text):b.active=!1):(u||(b.dismissedRange=null),b.active=!1)}else b.active=!1;return b.active||(b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null),b}}}function SH({editor:e,items:t}){let n=null,r=null,i=null,a=()=>{r!==null&&(clearTimeout(r),r=null),i?.(),i=null},o=e=>new Promise(t=>{i=t,r=setTimeout(()=>{r=null;let e=i;i=null,e?.()},e)}),s=()=>{n?.abort(),a(),n=null};return{abort:s,fetch:async(r,i)=>{s(),n=new AbortController;let a=n;if(i>0&&await o(i),n!==a||a.signal.aborted)return{status:`aborted`};try{let i=await t({editor:e,query:r,signal:a.signal});return n!==a||a.signal.aborted?{status:`aborted`}:{status:`resolved`,items:i}}catch{return n!==a||a.signal.aborted?{status:`aborted`}:{status:`error`}}}}}function CH({placement:e,offset:t,flip:n,floatingUi:r}){var i;let a=[jj({mainAxis:t.mainAxis??4,crossAxis:t.crossAxis??0})];return n&&a.push(Nj()),r!=null&&(i=r.middleware)!=null&&i.length&&a.push(...r.middleware),{placement:e,strategy:r?.strategy??`absolute`,middleware:a}}function wH(e){if(e instanceof HTMLElement)return e;if(typeof e==`string`)try{let t=document.querySelector(e);if(t)return t}catch{return document.body}return document.body}function TH({getReferenceRect:e,contextElement:t,config:n,container:r,dismissOnOutsideClick:i,dismiss:a}){return(o,s={})=>{let c={getBoundingClientRect:()=>e()??new DOMRect,contextElement:t},l=!1,u=!o.isConnected;u&&wH(r).appendChild(o),s.onPosition||(o.style.visibility=`hidden`,o.style.width=`max-content`);let d=Aj(c,o,()=>{Pj(c,o,{placement:n.placement,strategy:n.strategy,middleware:n.middleware}).then(({x:e,y:t,placement:n,strategy:r})=>{s.onPosition?s.onPosition({x:e,y:t,placement:n,strategy:r}):(Object.assign(o.style,{position:r,left:`${e}px`,top:`${t}px`}),l||(l=!0,o.style.visibility=``))})},s.autoUpdate),f;return i&&(f=e=>{let n=e.target;!(n instanceof Node)||o.contains(n)||t.contains(n)||a()},document.addEventListener(`pointerdown`,f,!0)),()=>{d(),f&&document.removeEventListener(`pointerdown`,f,!0),u&&o.remove()}}}function EH({editor:e,pluginKey:t,items:n,renderer:r,minQueryLength:i,debounce:a,initialItems:o,placement:s,offset:c,container:l,flip:u,floatingUi:d,dismissOnOutsideClick:f,command:p,clientRectFor:m,dispatchExit:h}){let g,_=SH({editor:e,items:n}),v=CH({placement:s,offset:c,flip:u,floatingUi:d});function y(e,t){switch(e){case`started`:var n;r==null||(n=r.onStart)==null||n.call(r,t);break;case`updated`:var i;r==null||(i=r.onUpdate)==null||i.call(r,t);break;case`stopped`:var a;r==null||(a=r.onExit)==null||a.call(r,t)}}return{update:async(n,d)=>{let b=t.getState(d),x=t.getState(n.state);if(!b||!x)return;let S=null,C=b.query!==x.query,ee=b.text!==x.text,te=b.range.from!==x.range.from||b.range.to!==x.range.to,ne=C||ee||te;if(!b.active&&x.active)S=`started`;else if(b.active&&!x.active)S=`stopped`;else if(x.active&&ne)S=`updated`;else return;let re=S===`stopped`?b:x,ie=n.dom.querySelector(`[data-decoration-id="${re.decorationId}"]`),ae=m(n,ie),oe=i===0||(re.query?re.query.length>=i:!1),se=(S===`started`||S===`updated`)&&oe;if(g={editor:e,range:re.range,query:re.query||``,text:re.text||``,items:o??[],command:t=>p({editor:e,range:re.range,props:t}),decorationNode:ie,clientRect:ae,loading:se,placement:s,offset:{mainAxis:c.mainAxis??4,crossAxis:c.crossAxis??0},container:l,flip:u,floatingUi:v,mount:TH({getReferenceRect:ae,contextElement:n.dom,config:v,container:l,dismissOnOutsideClick:f,dismiss:()=>h(e.view)})},S===`started`){var ce;r==null||(ce=r.onBeforeStart)==null||ce.call(r,g)}if(S===`updated`){var le;r==null||(le=r.onBeforeUpdate)==null||le.call(r,g)}if(S===`started`&&y(S,g),S===`started`||S===`updated`){if(!se)_.abort(),g={...g,items:o??[],loading:!1};else{g={...g,items:o??[],loading:!0},S=`updated`,y(S,g);let e=await _.fetch(re.query||``,a);if(e.status===`aborted`)return;if(!t.getState(n.state)?.active){_.abort();return}g=e.status===`resolved`?{...g,items:e.items,loading:!1}:{...g,loading:!1}}}S===`stopped`?(_.abort(),y(S,g),g=void 0):S===`updated`&&y(S,g)},destroy:()=>{var e;_.abort(),g&&(r==null||(e=r.onExit)==null||e.call(r,g))}}}var DH=new O(`suggestion`);function OH({pluginKey:e=DH,editor:t,char:n=`@`,allowSpaces:r=!1,allowToIncludeChar:i=!1,allowedPrefixes:a=[` `],startOfLine:o=!1,decorationTag:s=`span`,decorationClass:c=`suggestion`,decorationContent:l=``,decorationEmptyClass:u=`is-empty`,command:d=()=>null,items:f=()=>[],minQueryLength:p=0,debounce:m=0,initialItems:h,placement:g=`bottom-start`,offset:_={},container:v,flip:y=!0,floatingUi:b,dismissOnOutsideClick:x=!0,render:S=()=>({}),allow:C=()=>!0,findSuggestionMatch:ee=mH,shouldShow:te,shouldResetDismissed:ne}){let re=S?.(),ie=r&&!i,ae=(n,r)=>_H(t,n,r,e);function oe(e){return vH({...e,editor:t,shouldResetDismissed:ne,effectiveAllowSpaces:ie})}let se=t=>yH({view:t,pluginKeyRef:e});return new D({key:e,view:()=>EH({editor:t,pluginKey:e,items:f,renderer:re,minQueryLength:p,debounce:m,initialItems:h,placement:g,offset:_,container:v,flip:y,floatingUi:b,dismissOnOutsideClick:x,command:d,clientRectFor:ae,dispatchExit:se}),state:xH({editor:t,char:n,effectiveAllowSpaces:ie,allowToIncludeChar:i,allowedPrefixes:a,startOfLine:o,findSuggestionMatch:ee,allow:C,shouldShow:te,shouldKeepDismissed:oe,pluginKey:e}),props:bH({pluginKey:e,decorationTag:s,decorationClass:c,decorationContent:l,decorationEmptyClass:u,renderer:re,dispatchExit:se})})}var kH=OH,AH=e=>`/p/${encodeURIComponent(e)}`,jH=/^\/p\/([A-Za-z0-9_-]+)\/?(?:[?#].*)?$/;function MH(e){return jH.exec(e)?.[1]??``}function NH(e,t,n,r=`Untitled`){let i=`${n.icon?`${n.icon} `:``}${n.title||r}`;e.chain().focus().deleteRange(t).insertContent([{type:`text`,text:i,marks:[{type:`link`,attrs:{href:AH(n.id)}}]},{type:`text`,text:` `}]).run()}async function PH(e,t,n){if(!t.create)return;let{from:r,to:i,empty:a}=e.state.selection,o=a?``:e.state.doc.textBetween(r,i,` `).trim().slice(0,200),s=await t.create(o);a||!o?NH(e,{from:r,to:r},s,n):e.chain().focus().setTextSelection({from:r,to:i}).setLink({href:AH(s.id)}).run()}var FH=wp.create({name:`pageLinks`,addOptions(){return{host:void 0,labels:null,onNavigate:void 0}},addProseMirrorPlugins(){let{host:e,onNavigate:t}=this.options,n=this.options.labels,r=[];return e&&r.push(kH({editor:this.editor,pluginKey:new O(`pageLinks`),char:`[[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Hj({label:n.pageLinks,empty:n.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>NH(e.editor,e.range,t)})})),t&&r.push(new D({key:new O(`pageLinkClicks`),props:{handleClick:(e,n,r)=>{let i=(r.target?.closest?.(`a[href]`))?.getAttribute(`href`)??``;return!MH(i)||e.editable&&!(r.ctrlKey||r.metaKey)?!1:(r.preventDefault(),t(i),!0)}}})),r}}),IH=/^[a-z0-9]{6,16}$/,LH=(e,t)=>t?`${AH(e)}#b-${t}`:AH(e);function RH(e,t){let n=!1;return e.descendants(e=>(e.attrs.blockId===t&&(n=!0),!n)),n}function zH(e){let t=/\/p\/([A-Za-z0-9_-]+)\/?(?:\?[^#\s]*)?#b-([a-z0-9]{6,16})$/.exec(e.trim());return t?{page:t[1],block:t[2]}:null}var BH=wp.create({name:`syncedBlockFilter`,addOptions(){return{block:``}},addProseMirrorPlugins(){let e=this.options.block;return[new D({key:new O(`syncedBlockFilter`),props:{decorations:t=>{let n=-1;t.doc.descendants((t,r)=>(t.attrs.blockId===e&&(n=r),n<0));let r=[],i={class:`dw-synced-hidden`};if(n<0)return t.doc.forEach((e,t)=>r.push(_s.node(t,t+e.nodeSize,i))),bs.create(t.doc,r);let a=t.doc.resolve(n);for(let e=0;e<=a.depth;e++){let t=a.index(e),n=e===0?0:a.start(e);a.node(e).forEach((e,a,o)=>{o!==t&&r.push(_s.node(n,n+e.nodeSize,i)),n+=e.nodeSize})}return bs.create(t.doc,r)}}})]}});function VH(e,t,n){e.chain().focus().deleteRange(t).insertSyncedPage(n).run()}var HH=qp.create({name:`syncedPage`,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,pages:void 0,labels:null,onNavigate:void 0,nested:void 0}},addAttributes(){return{page:{default:``,parseHTML:e=>e.getAttribute(`data-page`)??``,renderHTML:e=>({"data-page":e.page})},title:{default:``,parseHTML:e=>e.getAttribute(`data-title`)??``,renderHTML:e=>e.title?{"data-title":e.title}:{}},icon:{default:``,parseHTML:e=>e.getAttribute(`data-icon`)??``,renderHTML:e=>e.icon?{"data-icon":e.icon}:{}},block:{default:``,parseHTML:e=>{let t=e.getAttribute(`data-block`)??``;return IH.test(t)?t:``},renderHTML:e=>e.block?{"data-block":e.block}:{}},folded:{default:!1,parseHTML:e=>e.hasAttribute(`data-folded`),renderHTML:e=>e.folded?{"data-folded":``}:{}}}},parseHTML(){return[{tag:`div[data-type='syncedPage']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=`${e.attrs.icon?`${e.attrs.icon} `:``}${e.attrs.title||`…`}`;return[`div`,j(t,{"data-type":`syncedPage`}),[`a`,{href:LH(String(e.attrs.page),String(e.attrs.block??``))},n]]},addCommands(){return{insertSyncedPage:e=>({commands:t})=>t.insertContent([{type:this.name,attrs:{page:e.id,title:e.title,icon:e.icon??``,block:e.block??``}},{type:`paragraph`}])}},addProseMirrorPlugins(){let{pages:e}=this.options,t=this.options.labels;return e?[kH({editor:this.editor,pluginKey:new O(`syncedPages`),char:`![[`,allowSpaces:!0,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:async({query:t})=>(await e.search(t).catch(()=>[])).slice(0,8),render:Hj({label:t.blocks.syncedPage,empty:t.noPages,toItem:e=>({label:`${e.icon?`${e.icon} `:``}${e.title||`…`}`,description:e.hint,icon:`page`}),pick:(e,t)=>VH(e.editor,e.range,t)})})]:[]},addNodeView(){let{host:e,onNavigate:t,nested:n}=this.options,r=this.options.labels.blocks;return({node:i,editor:a,getPos:o})=>{let s=i,c=String(s.attrs.page),l=IH.test(String(s.attrs.block??``))?String(s.attrs.block):``,u=LH(c,l),d=document.createElement(`div`);d.className=`dw-synced`,d.dataset.type=`syncedPage`,l&&d.classList.add(`dw-synced--block`),d.contentEditable=`false`;let f=document.createElement(`div`);f.className=`dw-synced__head`;let p=document.createElement(`a`);p.className=`dw-synced__title`,p.href=u;let m=Vj(`copy`,14);m.classList.add(`dw-synced__badge`);let h=document.createElement(`button`);h.type=`button`,h.className=`dw-synced__btn`;let g=document.createElement(`button`);g.type=`button`,g.className=`dw-synced__btn`,g.textContent=r.syncedOpen,f.append(m,p,h,g);let _=document.createElement(`div`);_.className=`dw-synced__body`,d.append(f,_);let v=e=>{e.preventDefault(),t?t(u):window.location.assign(u)};p.addEventListener(`click`,v),g.addEventListener(`click`,v);let y=e=>{let t=typeof o==`function`?o():void 0;t!==void 0&&a.view.dispatch(a.state.tr.setNodeMarkup(t,void 0,{...s.attrs,...e}))},b=null,x=()=>b??!!s.attrs.folded;h.addEventListener(`click`,()=>{a.isEditable?y({folded:!s.attrs.folded}):(b=!x(),ie())});let S=null,C=null,ee=null,te=e=>{let t=document.createElement(`p`);t.className=`dw-synced__note`,t.textContent=e,_.replaceChildren(t)},ne=()=>{ee?.(),C?.destroy(),S?.destroy(),ee=null,C=null,S=null},re=()=>{if(C||!e||!n)return;if(c===e.self)return te(r.syncedSelf);S=e.open(c),te(r.syncedLoading);let t=S,i=()=>{if(t.status===`denied`)ne(),te(r.syncedDenied);else if(t.synced&&!C){_.replaceChildren();let e=new Bp({element:_,editable:!1,extensions:n(t.doc,l||void 0),editorProps:{attributes:{class:`dw-prose`}}});if(C=e,l){let t=document.createElement(`p`);t.className=`dw-synced__note`,t.textContent=r.syncedBlockMissing;let n=()=>{let n=!RH(e.state.doc,l);n&&!t.isConnected?_.append(t):n||t.remove()};e.on(`update`,n),n()}}};ee=t.onChange(i),i()};function ie(){let t=s.attrs.title,n=l?r.syncedBlock:r.syncedPage;p.textContent=`${s.attrs.icon?`${s.attrs.icon} `:``}${t||n}`;let i=x();d.classList.toggle(`is-folded`,i),h.textContent=i?r.syncedUnfold:r.syncedFold,h.setAttribute(`aria-expanded`,String(!i)),i?(ne(),_.replaceChildren()):e?re():_.replaceChildren()}return ie(),e?.meta(c).then(e=>{if(!e)x()||te(r.syncedDenied);else if(a.isEditable&&(e.title!==s.attrs.title||e.icon!==s.attrs.icon))y({title:e.title,icon:e.icon});else{let t=l?r.syncedBlock:r.syncedPage;p.textContent=`${e.icon?`${e.icon} `:``}${e.title||t}`}}),{dom:d,update(e){return e.type!==s.type||String(e.attrs.page)!==c||String(e.attrs.block??``)!==l?!1:(s=e,ie(),!0)},ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof globalThis.Node&&(f.contains(e.target)||_.contains(e.target)),destroy:ne}}}});function UH(e){let t=document.createElement(`div`);t.className=`dw-diagram-editor`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`),t.setAttribute(`aria-label`,e);let n=document.createElement(`p`);n.className=`dw-diagram-editor__status`,t.append(n),document.body.append(t);let r=document.body.style.overflow;return document.body.style.overflow=`hidden`,{root:t,status:e=>{n.textContent=e,n.hidden=!e},close:()=>{t.remove(),document.body.style.overflow=r}}}async function WH(e,t){let n=await fetch(e.resolve(t));if(!n.ok)throw Error(`loading the drawing failed (${n.status})`);return n.text()}function GH(e,t){return new File([e],t,{type:`image/svg+xml`})}function KH(e){let t=new TextEncoder().encode(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n)}function qH(e,t,n){return new Promise(r=>{let i=UH(n.slash.drawio?.label??`Draw.io`),a=document.createElement(`iframe`),o=new URL(e);for(let[e,t]of Object.entries({embed:`1`,proto:`json`,spin:`1`,saveAndExit:`1`,noExitBtn:`0`}))o.searchParams.set(e,t);a.src=o.toString(),a.className=`dw-diagram-editor__frame`,a.title=n.slash.drawio?.label??`Draw.io`;let s=document.createElement(`div`);s.className=`dw-diagram-editor__bar`;let c=document.createElement(`button`);c.type=`button`,c.className=`dw-source__btn`,c.textContent=n.blocks.cancel,c.addEventListener(`click`,()=>d(null)),s.append(c),i.root.append(s,a),i.status(``);let l=e=>a.contentWindow?.postMessage(JSON.stringify(e),o.origin),u=!1,d=e=>{window.removeEventListener(`message`,f),i.close(),r(e)},f=e=>{if(e.source!==a.contentWindow||e.origin!==o.origin||typeof e.data!=`string`)return;let n;try{n=JSON.parse(e.data)}catch{return}switch(n.event){case`init`:l({action:`load`,autosave:0,xml:t?`data:image/svg+xml;base64,${KH(t)}`:``});break;case`save`:u=!0,l({action:`export`,format:`xmlsvg`,spinKey:`saving`});break;case`export`:{let e=n.data??``,t=e.indexOf(`,`),r=e.slice(0,t),i=e.slice(t+1),a=r.includes(`;base64`)?new TextDecoder().decode(Uint8Array.from(atob(i),e=>e.charCodeAt(0))):decodeURIComponent(i);d(u?a:null);break}case`exit`:d(null)}};window.addEventListener(`message`,f)})}async function JH(e,t,n){let r=UH(n.slash.excalidraw?.label??`Excalidraw`);r.status(``);try{let{openExcalidraw:i}=await e();return await i(r.root,t,n)}finally{r.close()}}var YH=!1;function XH(e){return qp.create({name:e,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0,loadExcalidraw:void 0,labels:null,drawioUrl:void 0,onError:void 0}},addAttributes(){return{src:{default:``},alt:{default:``}}},parseHTML(){return[{tag:`figure[data-type='${e}']`,getAttrs:e=>({src:e.querySelector(`img`)?.getAttribute(`src`)??``})}]},renderHTML({node:t,HTMLAttributes:n}){return[`figure`,j(n,{"data-type":e}),[`img`,{src:String(t.attrs.src),alt:String(t.attrs.alt||e)}]]},addCommands(){return{insertDiagram:e=>({commands:t})=>(YH=!0,t.insertContent({type:e,attrs:{src:``}}))}},addNodeView(){return({node:t,editor:n,getPos:r})=>{let i=this.options,a=i.labels,o=document.createElement(`figure`);o.className=`dw-diagram dw-diagram--${e}`,o.setAttribute(`data-type`,e);let s=document.createElement(`img`);s.className=`dw-diagram__img`;let c=document.createElement(`p`);c.className=`dw-diagram__empty`,c.textContent=e===`drawio`?a.blocks.emptyDrawio:a.blocks.emptyExcalidraw;let l=document.createElement(`button`);l.type=`button`,l.className=`dw-diagram__edit`,l.textContent=a.blocks.edit,o.append(s,c,l);let u=``,d=t=>{u=String(t.attrs.src??``),s.hidden=!u,c.hidden=!!u,u&&(s.src=i.host?i.host.resolve(u):u,s.alt=String(t.attrs.alt||a.slash[e]?.label||e))};d(t);let f=!1,p=async()=>{if(!f&&m()&&i.host?.upload){f=!0;try{let t=u?await WH(i.host,u):``,o=e===`drawio`?await qH(i.drawioUrl||`https://embed.diagrams.net`,t,a):await JH(i.loadExcalidraw,t,a);if(o===null)return;let s=await i.host.upload(GH(o,`${e===`drawio`?`diagram.drawio`:`drawing.excalidraw`}.svg`)),c=typeof r==`function`?r():void 0;c!==void 0&&ZH(n,c,e,s.url)}catch(e){i.onError?.(e)}finally{f=!1}}},m=()=>n.isEditable&&!!i.host?.upload&&(e===`drawio`||!!i.loadExcalidraw),h=()=>l.hidden=!m()||!u;return h(),n.on(`update`,h),o.addEventListener(`dblclick`,()=>void p()),c.addEventListener(`click`,()=>void p()),l.addEventListener(`click`,()=>void p()),YH&&(YH=!1,queueMicrotask(()=>void p())),{dom:o,update:t=>t.type.name===e&&(d(t),h(),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target===l||e.target===c,destroy:()=>n.off(`update`,h)}}}})}function ZH(e,t,n,r){e.chain().setNodeSelection(t).updateAttributes(n,{src:r}).run()}var QH=XH(`drawio`),$H=XH(`excalidraw`),eU=null;function tU(e){eU?.();let t=document.createElement(`div`);t.className=`dw-source`,t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-label`,e.label);let n=document.createElement(e.multiline?`textarea`:`input`);n.className=`dw-source__field`+(e.monospace?` dw-source__field--mono`:``),n.value=e.value,n.setAttribute(`aria-label`,e.label),n.spellcheck=!1,n instanceof HTMLTextAreaElement&&(n.rows=Math.min(16,Math.max(4,e.value.split(` +`).length+1)));let r=document.createElement(`div`);r.className=`dw-source__actions`;let i=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`dw-source__btn ${t}`,r.textContent=e,r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`click`,n),r};e.onRemove&&r.append(i(e.labels.remove,`dw-source__btn--danger`,()=>{u(!0),e.onRemove()}));let a=document.createElement(`span`);a.style.flex=`1`,r.append(a,i(e.labels.cancel,``,()=>u()),i(e.labels.done,`dw-source__btn--primary`,()=>o())),t.append(n,r),document.body.append(t);let o=()=>{let t=n.value;u(!0),e.onSave(t)};n.addEventListener(`input`,()=>e.onInput?.(n.value)),n.addEventListener(`keydown`,t=>{let n=t;n.key===`Escape`?(n.preventDefault(),u()):n.key===`Enter`&&(n.ctrlKey||n.metaKey||!e.multiline)&&(n.preventDefault(),o()),n.stopPropagation()});let s=n=>{!t.contains(n.target)&&!e.anchor.contains(n.target)&&u()};setTimeout(()=>document.addEventListener(`mousedown`,s),0);let c=Aj(e.anchor,t,()=>{Pj(e.anchor,t,{placement:`bottom-start`,middleware:[jj(6),Nj(),Mj({padding:8})]}).then(({x:e,y:n})=>Object.assign(t.style,{left:`${e}px`,top:`${n}px`}))}),l=!1;function u(n=!1){l||(l=!0,c(),document.removeEventListener(`mousedown`,s),t.remove(),eU===d&&(eU=null),n||e.onCancel?.())}let d=()=>u();return eU=d,n.focus(),e.multiline||n.select(),d}var nU={open:`green`,started:`yellow`,draft:`gray`,merged:`purple`,done:`blue`,closed:`red`,canceled:`gray`},rU=[{pattern:/^https:\/\/(?:www\.|m\.)?youtube\.com\/(?:watch\?(?:.*&)?v=|shorts\/|embed\/|live\/)([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/youtu\.be\/([\w-]{11})/,src:e=>`https://www.youtube-nocookie.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?vimeo\.com\/(?:video\/)?(\d+)/,src:e=>`https://player.vimeo.com/video/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/([\da-f]{32})/,src:e=>`https://www.loom.com/embed/${e[1]}`},{pattern:/^https:\/\/(?:www\.)?figma\.com\/(?:file|design|proto|board|slides)\/[\w-]+/,src:(e,t)=>`https://www.figma.com/embed?embed_host=docwell&url=${encodeURIComponent(t.href)}`},{pattern:/^https:\/\/codepen\.io\/([\w-]+)\/(?:pen|embed)\/([\w-]+)/,src:e=>`https://codepen.io/${e[1]}/embed/${e[2]}?default-tab=result`},{pattern:/^https:\/\/open\.spotify\.com\/(?:embed\/)?(track|album|playlist|episode|show)\/(\w+)/,src:e=>`https://open.spotify.com/embed/${e[1]}/${e[2]}`,ratio:`audio`},{pattern:/^https:\/\/docs\.google\.com\/(document|spreadsheets|presentation)\/d\/([\w-]+)/,src:e=>`https://docs.google.com/${e[1]}/d/${e[2]}/preview`,ratio:`tall`},{pattern:/^https:\/\/(?:www\.)?google\.com\/maps\/embed\?/,src:(e,t)=>t.href}];function iU(e){let t;try{t=new URL(e.trim())}catch{return null}for(let e of rU){let n=e.pattern.exec(t.href);if(n)return{src:e.src(n,t),ratio:e.ratio??`video`}}return null}function aU(e){try{let t=new URL(e.trim());return t.protocol===`https:`||t.protocol===`http:`?t.href:``}catch{return``}}var oU=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}};function sU(e,t,n){let{node:r}=e.view.domAtPos(e.state.selection.from),i=r instanceof HTMLElement?r:r.parentElement??e.view.dom;return new Promise(e=>{let r=t.blocks;tU({anchor:i,value:`https://`,label:n,labels:{done:r.done,cancel:r.cancel,remove:r.remove},onSave:t=>e(aU(t)),onCancel:()=>e(``)})})}async function cU(e,t,n,r){let i=await sU(e,t,t.blocks.embedUrl);i&&(iU(i)?e.chain().focus().insertEmbed(i).run():await uU(e,i,n,r))}async function lU(e,t,n,r){let i=await sU(e,t,t.blocks.linkUrl);i&&await uU(e,i,n,r)}async function uU(e,t,n,r){let i={url:t};if(n)try{i={...await n.preview(t),url:t}}catch(e){r?.(e)}e.chain().focus().insertLinkCard(i).run()}var dU=qp.create({name:`embed`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){return{url:{default:``,parseHTML:e=>e.getAttribute(`data-url`)??``,renderHTML:e=>({"data-url":e.url})}}},parseHTML(){return[{tag:`div[data-type='embed']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=aU(String(e.attrs.url));return[`div`,j(t,{"data-type":`embed`}),[`a`,{href:n},n]]},addCommands(){return{insertEmbed:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e}})}},addNodeView(){return({node:e})=>{let t=this.options.labels.blocks,n=document.createElement(`figure`);n.className=`dw-embed`,n.setAttribute(`data-type`,`embed`),n.contentEditable=`false`;let r=e=>{let r=aU(e),i=iU(r);if(n.replaceChildren(),!i){let e=document.createElement(`a`);e.href=r,e.target=`_blank`,e.rel=`noopener noreferrer`,e.textContent=r||t.embedInvalid,n.append(e);return}n.dataset.ratio=i.ratio;let a=document.createElement(`iframe`);a.className=`dw-embed__frame`,a.src=i.src,a.title=`${t.embed}: ${oU(r)}`,a.loading=`lazy`,a.allow=`fullscreen; picture-in-picture; encrypted-media; clipboard-write`,a.referrerPolicy=`strict-origin-when-cross-origin`,a.setAttribute(`sandbox`,`allow-scripts allow-same-origin allow-popups allow-presentation`);let o=document.createElement(`figcaption`);o.className=`dw-embed__caption`;let s=document.createElement(`a`);s.href=r,s.target=`_blank`,s.rel=`noopener noreferrer`,s.textContent=oU(r),o.append(s),n.append(a,o)},i=String(e.attrs.url);return r(i),{dom:n,update:e=>e.type.name===`embed`&&(e.attrs.url!==i&&r(i=String(e.attrs.url)),!0),ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`)}}}}),fU=qp.create({name:`linkCard`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},addAttributes(){let e=e=>({default:``,parseHTML:t=>t.getAttribute(`data-${e}`)??``,renderHTML:t=>({[`data-${e}`]:t[e]})});return{url:e(`url`),title:e(`title`),description:e(`description`),image:e(`image`),site:e(`site`),kind:e(`kind`),status:e(`status`),state:e(`state`),meta:e(`meta`)}},parseHTML(){return[{tag:`div[data-type='link-card']`}]},renderHTML({node:e,HTMLAttributes:t}){let n=aU(String(e.attrs.url));return[`div`,j(t,{"data-type":`link-card`}),[`a`,{href:n},String(e.attrs.title||n)]]},addCommands(){return{insertLinkCard:e=>({commands:t})=>t.insertContent({type:this.name,attrs:{url:e.url,title:e.title??``,description:e.description??``,image:e.image??``,site:e.site??``,kind:e.kind??``,status:e.status??``,state:e.state??``,meta:e.meta??``}})}},addNodeView(){return({node:e})=>{let t=document.createElement(`a`);t.className=`dw-linkcard`,t.setAttribute(`data-type`,`link-card`),t.contentEditable=`false`,t.target=`_blank`,t.rel=`noopener noreferrer`;let n=e=>{let n=aU(String(e.url));t.href=n,t.replaceChildren();let r=document.createElement(`span`);r.className=`dw-linkcard__text`;let i=document.createElement(`span`);i.className=`dw-linkcard__title`,i.textContent=String(e.title||``)||oU(n);let a=String(e.kind||``);if(t.dataset.kind=a,e.status){let t=document.createElement(`span`);t.className=`dw-linkcard__head`;let n=document.createElement(`span`);n.className=`dw-linkcard__status`,n.dataset.color=nU[String(e.state)]??`gray`,n.textContent=String(e.status),t.append(n,i),r.append(t)}else r.append(i);if(e.description){let t=document.createElement(`span`);t.className=`dw-linkcard__desc`,t.textContent=String(e.description),r.append(t)}let o=document.createElement(`span`);o.className=`dw-linkcard__site`,o.textContent=[String(e.site||``)||oU(n),String(e.meta||``)].filter(Boolean).join(` · `),r.append(o),t.append(r);let s=aU(String(e.image||``));if(s.startsWith(`https:`)){let e=document.createElement(`img`);e.className=a.startsWith(`github.`)?`dw-linkcard__image dw-linkcard__image--avatar`:`dw-linkcard__image`,e.src=s,e.alt=``,e.loading=`lazy`,e.referrerPolicy=`no-referrer`,e.onerror=()=>e.remove(),t.append(e)}},r=e;return n(e.attrs),t.addEventListener(`click`,e=>{this.editor.view.editable&&!(e.ctrlKey||e.metaKey)&&e.preventDefault()}),{dom:t,update:e=>e.type.name===`linkCard`&&(e.attrs!==r.attrs&&n(e.attrs),r=e,!0),ignoreMutation:()=>!0}}}}),pU=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,mU=qp.create({name:`image`,addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?`inline`:`block`},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?`img[src]`:`img[src]:not([src^="data:"])`}]},renderHTML({HTMLAttributes:e}){return[`img`,j(this.options.HTMLAttributes,e)]},parseMarkdown:(e,t)=>t.createNode(`image`,{src:e.href,title:e.title,alt:e.text}),renderMarkdown:e=>{let t=e.attrs?.src??``,n=e.attrs?.alt??``,r=e.attrs?.title??``;return r?`![${n}](${t} "${r}")`:`![${n}](${t})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>`u`)return null;let{directions:e,minWidth:t,minHeight:n,alwaysPreserveAspectRatio:r}=this.options.resize,i=new Set([`src`,`width`,`height`]);return({node:a,getPos:o,HTMLAttributes:s,editor:c})=>{let l=document.createElement(`img`);l.draggable=!1;let u=j(this.options.HTMLAttributes,s);Object.entries(u).forEach(([e,t])=>{if(t!=null)switch(e){case`src`:case`width`:case`height`:break;default:l.setAttribute(e,t)}}),u.src!==null&&(l.src=u.src);let d={...s},f=e=>{typeof e==`string`&&e!==``?l.getAttribute(`src`)!==e&&(l.src=e):(l.hasAttribute(`src`)&&l.removeAttribute(`src`),l.src!==``&&(l.src=``))};f(s.src);let p=new Kp({element:l,editor:c,node:a,getPos:o,onResize:(e,t)=>{l.style.width=`${e}px`,l.style.height=`${t}px`},onCommit:(e,t)=>{let n=o();n!==void 0&&this.editor.chain().setNodeSelection(n).updateAttributes(this.name,{width:e,height:t}).run()},onUpdate:e=>{if(e.type!==a.type)return!1;let t=Iu(e,c.extensionManager.attributes.filter(t=>t.type===e.type.name));return Object.keys(d).forEach(e=>{!i.has(e)&&!(e in t)&&l.removeAttribute(e)}),Object.entries(t).forEach(([e,t])=>{i.has(e)||(t==null?l.removeAttribute(e):l.setAttribute(e,t))}),f(t.src),d=t,!0},options:{directions:e,min:{width:t,height:n},preserveAspectRatio:r===!0}}),m=p.dom,h=()=>{m.style.visibility=``,m.style.pointerEvents=``};return m.style.visibility=`hidden`,m.style.pointerEvents=`none`,l.complete&&l.naturalWidth>0?h():(l.onload=h,l.onerror=h),p}},addCommands(){return{setImage:e=>({commands:t})=>t.insertContent({type:this.name,attrs:e})}},addInputRules(){return[Hp({find:pU,type:this.type,getAttributes:e=>{let[,,t,n,r]=e;return{src:n,alt:t,title:r}}})]}});function hU(e,t){return/^(audio|video)\//.test(e)||/\.(mp3|mp4|mpeg|mpga|m4a|wav|webm|ogg|oga|flac|aac|opus|mov)$/i.test(t)}async function gU(e,t,n,r){if(t.upload)for(let i of n){let n=await t.upload(i),a=n.mime.startsWith(`image/`)?{type:`image`,attrs:{src:n.url,alt:n.name}}:{type:`fileAttachment`,attrs:{url:n.url,name:n.name,size:n.size,mime:n.mime,view:Lj(n.mime,n.name)?`preview`:`card`}};e.chain().focus().insertContentAt(r??e.state.selection.to,a).run(),r=void 0}}var _U=mU.extend({addOptions(){return{...this.parent(),host:void 0,inline:!1,allowBase64:!1}},addNodeView(){return({node:e})=>{let t=document.createElement(`img`),n=e=>{let n=String(e.attrs.src??``);t.src=this.options.host?this.options.host.resolve(n):n,t.alt=String(e.attrs.alt??``),e.attrs.title&&(t.title=String(e.attrs.title))};return n(e),t.draggable=!0,{dom:t,update:t=>t.type===e.type&&(n(t),!0)}}}});function vU(e){if(!e)return``;let t=[`B`,`KB`,`MB`,`GB`],n=0,r=e;for(;r>=1024&&n({editor:e,commands:t})=>{let n=e.getAttributes(this.name);return!e.isActive(this.name)||!Lj(n.mime,n.name)?!1:t.updateAttributes(this.name,{view:n.view===`preview`?`card`:`preview`})}}},parseHTML(){return[{tag:`div[data-type=file]`,getAttrs:e=>({url:e.getAttribute(`data-url`)??``,name:e.getAttribute(`data-name`)??e.textContent??`file`,size:Number(e.getAttribute(`data-size`)??0),mime:e.getAttribute(`data-mime`)??``,view:e.getAttribute(`data-view`)===`preview`?`preview`:`card`})}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,j(t,{"data-type":`file`,"data-url":e.attrs.url,"data-name":e.attrs.name,"data-size":e.attrs.size,"data-mime":e.attrs.mime,"data-view":e.attrs.view}),[`a`,{href:e.attrs.url,download:e.attrs.name},e.attrs.name]]},addNodeView(){return({node:e,editor:t,getPos:n})=>{let{host:r,loadPdf:i,labels:a}=this.options,o=document.createElement(`div`);o.className=`dw-file-block`,o.setAttribute(`data-type`,`file`);let s=document.createElement(`div`);s.className=`dw-file`;let c=document.createElement(`a`);c.className=`dw-file__name`,c.target=`_blank`,c.rel=`noopener`;let l=document.createElement(`span`);l.className=`dw-file__size`,s.append(c,l),o.append(s);let u=null,d=null,f=e,p=async()=>{let e=r?.transcribe;if(e&&u&&a){u.disabled=!0,u.textContent=a.blocks.transcribing,d&&(d.textContent=``);try{let r=await e(String(f.attrs.url??``),String(f.attrs.name??`file`)),i=typeof n==`function`?n():void 0;i!==void 0&&r&&t.chain().insertContentAt(i+f.nodeSize,r).run()}catch(e){d&&(d.textContent=e instanceof Error&&e.message?e.message:a.blocks.transcribeFailed)}finally{u&&(u.disabled=!1,u.textContent=a.blocks.transcribe)}}},m=null,h=null,g=``,_=e=>{let n=String(e.attrs.url??``),_=r?r.resolve(n):n;c.href=_,c.textContent=String(e.attrs.name??`file`),l.textContent=vU(Number(e.attrs.size??0)),f=e;let v=!!r?.transcribe&&!!a&&t.isEditable&&hU(String(e.attrs.mime??``),String(e.attrs.name??``));v&&!u&&a?(u=document.createElement(`button`),u.type=`button`,u.className=`dw-file__action`,u.textContent=a.blocks.transcribe,u.title=a.blocks.transcribeHint,u.setAttribute(`data-testid`,`file-transcribe`),u.addEventListener(`click`,()=>void p()),d=document.createElement(`span`),d.className=`dw-file__status`,d.setAttribute(`role`,`status`),s.append(u),o.append(d)):!v&&u&&(u.remove(),d?.remove(),u=d=null),!(e.attrs.view===`preview`&&Lj(e.attrs.mime,e.attrs.name)&&n)||!i||!a?(h?.(),h=null,m?.remove(),m=null,g=``):g!==_&&(h?.(),m||(m=document.createElement(`div`),m.className=`dw-pdf`,m.tabIndex=0,m.setAttribute(`role`,`document`),o.append(m)),m.setAttribute(`aria-label`,String(e.attrs.name??`PDF`)),g=_,h=Rj(m,_,i,a))};return _(e),{dom:o,update:t=>t.type===e.type&&(_(t),!0),stopEvent:e=>!!u&&u.contains(e.target)||!!m&&m.contains(e.target)&&e.type!==`mousedown`,ignoreMutation:()=>!0,destroy:()=>h?.()}}}}),bU=wp.create({name:`fileDrop`,addOptions(){return{host:void 0,onError:void 0}},addProseMirrorPlugins(){let e=this.options.host;return e?[xU(()=>this.editor,e,this.options.onError)]:[]}});function xU(e,t,n){let r=(r,i)=>{let a=e();return!a||!r.length||!t.upload?!1:(gU(a,t,r,i).catch(n),!0)};return new D({key:new O(`docwellFileDrop`),props:{handlePaste(e,t){return r([...t.clipboardData?.files??[]])},handleDrop(e,t){let n=[...t.dataTransfer?.files??[]];if(!n.length)return!1;let i=e.posAtCoords({left:t.clientX,top:t.clientY});return t.preventDefault(),r(n,i?.pos)}}})}var SU={smileys:`😀 grinning smile happy|😃 smiley happy|😄 smile laugh|😁 grin beam|😆 laughing|😅 sweat smile|🤣 rofl rolling laugh|😂 joy tears laugh|🙂 slight smile|🙃 upside down|😉 wink|😊 blush happy|😇 innocent halo angel|🥰 love hearts|😍 heart eyes love|🤩 star struck|😘 kiss blow|😋 yum tasty|😛 tongue|😜 wink tongue|🤪 zany crazy|🤑 money|🤗 hug|🤭 oops giggle|🤫 shush quiet|🤔 thinking|🤐 zipper mouth|😐 neutral|😑 expressionless|😶 no mouth|😏 smirk|😒 unamused|🙄 eye roll|😬 grimace|😌 relieved|😔 pensive sad|😪 sleepy|😴 sleeping|😷 mask sick|🤒 thermometer ill|🤯 mind blown exploding|🥳 party celebrate|😎 cool sunglasses|🤓 nerd geek|🧐 monocle|😕 confused|😟 worried|😮 surprised open mouth|😲 astonished|😳 flushed|🥺 pleading|😢 cry tear|😭 sob crying|😱 scream fear|😤 triumph steam|😡 angry rage|🤬 cursing|😈 devil|💀 skull dead|💩 poop|🤡 clown|👻 ghost|👽 alien|🤖 robot|😺 cat smile|❤️ heart love red`,people:`👋 wave hello hi|🤚 raised back hand|✋ hand stop|👌 ok okay|✌️ victory peace|🤞 crossed fingers luck|🤟 love you|🤘 rock horns|👈 point left|👉 point right|👆 point up|👇 point down|☝️ index up|👍 thumbs up like yes|👎 thumbs down no|✊ fist|👊 punch|👏 clap applause|🙌 raised hands hooray|🤝 handshake deal|🙏 pray thanks please|✍️ writing|💪 muscle strong|🧠 brain|👀 eyes look|👁️ eye|👤 person user|👥 people users team|🧑‍💻 developer coder technologist|🧑‍🏫 teacher|🧑‍🎓 student|🧑‍🔬 scientist|🧑‍🎨 artist|🧑‍🍳 cook chef|🧑‍🔧 mechanic|🧑‍⚕️ doctor health|🧑‍💼 office worker business|🕵️ detective|👷 construction worker|🦸 superhero|🧙 wizard mage|🏃 running|🚶 walking|🧘 yoga meditation|👪 family|👶 baby`,nature:`🐶 dog puppy|🐱 cat kitten|🐭 mouse|🐰 rabbit bunny|🦊 fox|🐻 bear|🐼 panda|🐨 koala|🐯 tiger|🦁 lion|🐮 cow|🐷 pig|🐸 frog|🐵 monkey|🐔 chicken|🐧 penguin|🐦 bird|🦉 owl|🦄 unicorn|🐝 bee|🐛 bug|🦋 butterfly|🐢 turtle|🐍 snake|🐙 octopus|🐬 dolphin|🐳 whale|🐟 fish|🦈 shark|🌵 cactus|🎄 christmas tree|🌲 evergreen tree|🌳 tree|🌴 palm|🌱 seedling sprout|🌿 herb|🍀 clover luck|🍁 maple leaf|🍂 fallen leaves autumn|🌷 tulip|🌹 rose|🌻 sunflower|🌸 blossom|💐 bouquet flowers|🍄 mushroom|🌍 earth world globe|🌙 moon night|⭐ star|🌟 glowing star|✨ sparkles|⚡ lightning zap|🔥 fire hot|🌈 rainbow|☀️ sun|⛅ cloud sun|☁️ cloud|🌧️ rain|❄️ snow snowflake|💧 droplet water|🌊 wave ocean sea`,food:`🍏 green apple|🍎 apple red|🍐 pear|🍊 orange|🍋 lemon|🍌 banana|🍉 watermelon|🍇 grapes|🍓 strawberry|🫐 blueberries|🍒 cherries|🍑 peach|🥭 mango|🍍 pineapple|🥥 coconut|🥝 kiwi|🍅 tomato|🥑 avocado|🥦 broccoli|🥕 carrot|🌽 corn|🌶️ pepper hot|🥔 potato|🍞 bread|🥐 croissant|🧀 cheese|🥚 egg|🍳 cooking|🥞 pancakes|🥓 bacon|🍔 burger|🍟 fries|🍕 pizza|🌭 hot dog|🌮 taco|🌯 burrito|🥗 salad|🍝 pasta spaghetti|🍜 ramen noodles|🍣 sushi|🍱 bento|🍦 ice cream|🍩 doughnut|🍪 cookie|🎂 birthday cake|🍰 cake|🧁 cupcake|🍫 chocolate|🍬 candy|🍿 popcorn|☕ coffee|🍵 tea|🧃 juice|🥤 drink|🍺 beer|🍷 wine|🍸 cocktail|🥂 cheers champagne|🍽️ dinner plate`,activity:`⚽ soccer football|🏀 basketball|🏈 american football|⚾ baseball|🎾 tennis|🏐 volleyball|🏉 rugby|🎱 billiards|🏓 ping pong|🏸 badminton|🥅 goal|⛳ golf|🏹 archery|🎣 fishing|🥊 boxing|🎽 running shirt|⛸️ ice skate|🎿 ski|🏂 snowboard|🏋️ weights gym|🚴 cycling bike|🏆 trophy win|🥇 gold medal first|🥈 silver medal|🥉 bronze medal|🏅 medal|🎖️ military medal|🎫 ticket|🎪 circus|🎭 theatre drama|🎨 art palette paint|🎬 movie clapper film|🎤 microphone sing|🎧 headphones music|🎼 score|🎹 piano|🥁 drum|🎷 saxophone|🎺 trumpet|🎸 guitar|🎻 violin|🎲 dice game|♟️ chess|🎯 target goal dart|🎳 bowling|🎮 video game|🧩 puzzle|🎉 party popper tada|🎊 confetti|🎈 balloon|🎁 gift present`,travel:`🚗 car|🚕 taxi|🚌 bus|🚎 trolleybus|🏎️ race car|🚓 police car|🚑 ambulance|🚒 fire engine|🚚 truck delivery|🚜 tractor|🛵 scooter|🚲 bicycle|🛴 kick scooter|🚂 train locomotive|🚆 train|🚇 metro subway|✈️ airplane flight|🛫 departure|🛬 arrival|🚀 rocket launch|🛸 ufo|🚁 helicopter|⛵ sailboat|🚤 speedboat|🚢 ship|⚓ anchor|🗺️ map|🧭 compass|🏔️ mountain snow|⛰️ mountain|🌋 volcano|🏕️ camping|🏖️ beach|🏝️ island|🏠 house home|🏡 garden home|🏢 office building|🏬 department store|🏭 factory|🏥 hospital|🏦 bank|🏨 hotel|🏪 shop store|🏫 school|🏛️ classical building|⛪ church|🏰 castle|🗼 tower|🗽 statue liberty|⛲ fountain|🌆 city|🌃 night city|🌉 bridge|🎡 ferris wheel|🎢 roller coaster|🚦 traffic light|🚧 construction|⛽ fuel`,objects:`📄 page document|📃 curl page|📑 bookmark tabs|📝 memo note write|📋 clipboard|📌 pushpin pin|📍 location pin|📎 paperclip|🖇️ paperclips|📏 ruler|📐 triangle ruler|✂️ scissors|🗂️ dividers index|📁 folder|📂 open folder|🗃️ card box|🗄️ cabinet|🗑️ trash wastebasket|📅 calendar date|📆 tear off calendar|🗓️ spiral calendar|📇 card index|📈 chart up growth|📉 chart down|📊 bar chart stats|📒 ledger|📓 notebook|📔 notebook decorative|📕 book closed|📗 green book|📘 blue book|📙 orange book|📚 books library|📖 open book read|🔖 bookmark|🏷️ label tag|💼 briefcase work|💻 laptop computer|🖥️ desktop computer|⌨️ keyboard|🖱️ mouse computer|📱 phone mobile|☎️ telephone|📞 receiver call|📠 fax|🔋 battery|🔌 plug|💡 bulb idea|🔦 flashlight|🕯️ candle|💰 money bag|💳 card credit|🧾 receipt|✉️ envelope mail|📧 email|📨 incoming mail|📦 package box|📮 postbox|🔒 lock locked|🔓 unlocked|🔑 key|🗝️ old key|🔨 hammer|🛠️ tools|🔧 wrench|🔩 nut bolt|⚙️ gear settings|🧰 toolbox|🧲 magnet|🧪 test tube|🔬 microscope|🔭 telescope|📡 satellite|💊 pill|🩺 stethoscope|🛒 cart shopping|🎓 graduation cap|👑 crown|💎 gem diamond|⏰ alarm clock|⏳ hourglass|⌛ hourglass done|🕐 clock time|📷 camera photo|🎥 video camera|📺 television tv|📻 radio|🔔 bell notification|📣 megaphone announce|📢 loudspeaker|🔍 search magnifier|🧭 compass direction`,symbols:`✅ check done yes|☑️ ballot check|✔️ check mark|❌ cross no|❎ cross button|➕ plus add|➖ minus|➗ divide|✖️ multiply|❓ question|❔ white question|❗ exclamation important|‼️ double exclamation|⚠️ warning|🚫 prohibited|⛔ no entry|🛑 stop|💯 hundred|🔴 red circle|🟠 orange circle|🟡 yellow circle|🟢 green circle|🔵 blue circle|🟣 purple circle|⚫ black circle|⚪ white circle|🟥 red square|🟧 orange square|🟨 yellow square|🟩 green square|🟦 blue square|🟪 purple square|⬛ black square|⬜ white square|🔶 orange diamond|🔷 blue diamond|♻️ recycle|⚛️ atom|☮️ peace|☯️ yin yang|♾️ infinity|💲 dollar|💱 exchange|©️ copyright|®️ registered|™️ trademark|🔝 top|🔜 soon|🆕 new|🆓 free|🆗 ok|🆙 up|🆒 cool|ℹ️ info information|🔤 abc letters|🔢 numbers|#️⃣ hash|➡️ right arrow|⬅️ left arrow|⬆️ up arrow|⬇️ down arrow|🔄 refresh sync|🔁 repeat|▶️ play|⏸️ pause|⏹️ stop|⏩ fast forward|💬 speech chat comment|💭 thought|🗯️ anger bubble|💤 sleep zzz|💥 boom collision|💫 dizzy|🎵 music note|🔗 link|🏁 finish flag|🚩 red flag|🏳️ white flag|🏴 black flag|💜 purple heart|💙 blue heart|💚 green heart|💛 yellow heart|🧡 orange heart|🖤 black heart|💔 broken heart`},CU=Object.keys(SU),wU=Object.fromEntries(CU.map(e=>[e,SU[e].split(`|`).map(e=>{let[t=``,...n]=e.trim().split(` `);return{char:t,words:n.join(` `)}})]));function TU(e){let t=e.toLowerCase().split(/\s+/).filter(Boolean);if(!t.length)return[];let n=new Set,r=[];for(let e of CU)for(let i of wU[e]){if(n.has(i.char))continue;let e=i.words.split(` `);t.every(t=>e.some(e=>e.startsWith(t)))&&(n.add(i.char),r.push(i))}return r}var EU=`docwell.recentEmoji`;function DU(){try{let e=JSON.parse(localStorage.getItem(EU)??`[]`);return Array.isArray(e)?e.filter(e=>typeof e==`string`).slice(0,16):[]}catch{return[]}}function OU(e){try{localStorage.setItem(EU,JSON.stringify([e,...DU().filter(t=>t!==e)].slice(0,16)))}catch{}}function kU(){let e=DU().map(e=>({char:e,words:``})),t=new Set(e.map(e=>e.char)),n=[...wU.smileys.slice(0,8),...wU.people.slice(12,16)].filter(e=>!t.has(e.char));return[...e,...n].slice(0,10)}function AU(e){return e.trim()?TU(e).slice(0,10):kU()}var jU=wp.create({name:`emojiPicker`,addOptions(){return{labels:null}},addProseMirrorPlugins(){let e=this.options.labels;return[kH({editor:this.editor,pluginKey:new O(`emojiPicker`),char:`:`,allowSpaces:!1,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:({query:e})=>AU(e),render:Hj({label:e?.blocks.emoji??`Emoji`,empty:e?.blocks.noEmoji??`No emoji found`,toItem:e=>({label:e.words||e.char,glyph:e.char}),pick:(e,t)=>{OU(t.char),e.editor.chain().focus().insertContentAt(e.range,t.char).run()}})})]}}),MU=2e3;function NU(e){return typeof e==`string`?e.trim().slice(0,MU):``}var PU=new Set([`bold`,`italic`,`strike`,`code`,`underline`,`link`]),FU=/^(https?:\/\/|mailto:|\/(?!\/)|#)/i;function IU(e){if(!Array.isArray(e))return null;let t=[],n=MU;for(let r of e){if(n<=0||!r||typeof r!=`object`)continue;let e=r;if(e.type===`hardBreak`){t.push({type:`hardBreak`});continue}if(e.type!==`text`||typeof e.text!=`string`||!e.text)continue;let i=e.text.slice(0,n);n-=i.length;let a=(e.marks??[]).flatMap(e=>{if(!e||!PU.has(e.type))return[];if(e.type!==`link`)return[{type:e.type}];let t=typeof e.attrs?.href==`string`?e.attrs.href.trim():``;return FU.test(t)?[{type:`link`,attrs:{href:t}}]:[]});t.push(a.length?{type:`text`,text:i,marks:a}:{type:`text`,text:i})}for(;t.at(-1)?.type===`hardBreak`;)t.pop();return t.length?t:null}function LU(e){return NU((e??[]).map(e=>e.type===`hardBreak`?` +`:e.text??``).join(``))}var RU={bold:`strong`,italic:`em`,strike:`s`,code:`code`,underline:`u`};function zU(e,t){let n=document.createDocumentFragment();if(!e)return n.append(t),n;for(let t of e){if(t.type===`hardBreak`){n.append(document.createElement(`br`));continue}let e=document.createTextNode(t.text??``);for(let n of t.marks??[]){let t;if(n.type===`link`){let e=document.createElement(`a`);e.href=String(n.attrs?.href??``),e.rel=`noopener noreferrer`,e.target=`_blank`,t=e}else{let e=RU[n.type];if(!e)continue;t=document.createElement(e)}t.append(e),e=t}n.append(e)}return n}function BU(e){return IU(e.attrs.content)}function VU(e){let t=[];return e.descendants((e,n)=>(e.type.name===`footnote`&&t.push({pos:n,text:NU(e.attrs.text),content:BU(e)}),!0)),t}var HU=new O(`footnotes`),UU=qp.create({name:`doc`,topNode:!0,content:`paragraph`});function WU(e,t,n,r){let i=e.state.doc.nodeAt(t);if(!i||i.type.name!==`footnote`)return;let a=r?.blocks.footnoteText??`Footnote text`,o=null;pB(n,(n,s)=>{let c=BU(i)??(i.attrs.text?[{type:`text`,text:NU(i.attrs.text)}]:[]);if(!e.editable){n.append(L(`div`,{class:`dw-footnote-pop__read`},zU(BU(i),NU(i.attrs.text))));return}let l=n=>{let r=e.state.doc.nodeAt(t);if(!r||r.type.name!==`footnote`)return;let i=IU(n.getJSON().content?.[0]?.content??[]),a=LU(i);(a!==r.attrs.text||JSON.stringify(i)!==JSON.stringify(r.attrs.content??null))&&e.dispatch(e.state.tr.setNodeMarkup(t,void 0,{...r.attrs,text:a,content:i}))},u=()=>{s(),e.focus()},d=L(`div`,{class:`dw-footnote-pop__text`}),f=e=>{let t=String(e.getAttributes(`link`).href??``),n=window.prompt(r?.format.linkPrompt??`Link address`,t);n!==null&&(n.trim()?FU.test(n.trim())&&e.chain().focus().extendMarkRange(`link`).setLink({href:n.trim()}).run():e.chain().focus().extendMarkRange(`link`).unsetLink().run())};o=new Bp({element:d,extensions:[UU,Jk.configure({document:!1,heading:!1,blockquote:!1,bulletList:!1,orderedList:!1,listItem:!1,listKeymap:!1,codeBlock:!1,horizontalRule:!1,dropcursor:!1,gapcursor:!1,trailingNode:!1,link:{openOnClick:!1,autolink:!0}}),wp.create({name:`footnoteKeys`,addKeyboardShortcuts:()=>({Enter:()=>(u(),!0),"Mod-k":({editor:e})=>(f(e),!0)})})],content:{type:`doc`,content:[{type:`paragraph`,content:c}]},editorProps:{attributes:{class:`dw-footnote-pop__field`,"aria-label":a,role:`textbox`}},onUpdate:({editor:e})=>l(e)});let p=(e,t,n)=>{let r=L(`button`,{type:`button`,class:`dw-footnote-pop__tool`,title:t,"aria-label":t});return r.append(Vj(e,15)),r.addEventListener(`mousedown`,e=>e.preventDefault()),r.addEventListener(`click`,()=>o&&n(o)),r},m=r?.format,h=L(`div`,{class:`dw-footnote-pop__tools`,role:`toolbar`},p(`bold`,m?.bold??`Bold`,e=>e.chain().focus().toggleBold().run()),p(`italic`,m?.italic??`Italic`,e=>e.chain().focus().toggleItalic().run()),p(`code`,m?.code??`Inline code`,e=>e.chain().focus().toggleCode().run()),p(`link`,m?.link??`Link`,f));n.append(h,d),o.commands.focus(`end`)},{class:`dw-footnote-pop`,label:a,onClose:()=>{o?.destroy(),o=null}})}var GU=qp.create({name:`footnote`,group:`inline`,inline:!0,atom:!0,selectable:!0,addOptions(){return{labels:null}},addAttributes(){return{text:{default:``,parseHTML:e=>NU(e.getAttribute(`data-text`)??e.getAttribute(`title`)??``),renderHTML:e=>({"data-text":e.text,title:e.text})},content:{default:null,parseHTML:e=>{try{return IU(JSON.parse(e.getAttribute(`data-content`)??`null`))}catch{return null}},renderHTML:e=>{let t=IU(e.content);return t?{"data-content":JSON.stringify(t)}:{}}}}},parseHTML(){return[{tag:`sup[data-type=footnote]`}]},renderHTML({HTMLAttributes:e}){return[`sup`,j(e,{"data-type":`footnote`,class:`dw-footnote`})]},renderText({node:e}){return` (${NU(e.attrs.text)})`},addCommands(){return{insertFootnote:(e=``)=>({editor:t,tr:n,dispatch:r})=>{let i=t.schema.nodes.footnote;if(!r)return!0;let a=n.selection.from;n.replaceSelectionWith(i.create({text:NU(e)}),!1);let o=this.options.labels;return setTimeout(()=>{if(t.isDestroyed)return;let e=t.view.nodeDOM(a);e instanceof Element&&WU(t.view,a,e,o)}),!0}}},addProseMirrorPlugins(){let e=this.options.labels,t=t=>{let n=VU(t);if(!n.length)return bs.empty;let r=n.map((t,n)=>_s.node(t.pos,t.pos+1,{"data-n":String(n+1),id:`fnref-${n+1}`,"aria-label":(e?.blocks.footnote??`Footnote {n}`).replace(`{n}`,String(n+1))})),i=JSON.stringify(n.map(e=>e.content??e.text)),a=_s.widget(t.content.size,t=>{let r=L(`ol`,{});return n.forEach((n,i)=>{let a=L(`a`,{href:`#fnref-${i+1}`,class:`dw-footnotes__back`,title:e?.blocks.footnoteBack??`Back to the text`,"aria-label":e?.blocks.footnoteBack??`Back to the text`},`↩`);a.addEventListener(`click`,e=>{e.preventDefault(),t.dom.querySelector(`[id="fnref-${i+1}"]`)?.scrollIntoView({block:`center`})});let o=L(`span`,{class:`dw-footnotes__text`});o.append(n.text||n.content?zU(n.content,n.text):`…`),t.editable&&o.addEventListener(`click`,n=>{if(n.target?.closest?.(`a`))return;let r=VU(t.state.doc)[i],a=t.dom.querySelector(`[id="fnref-${i+1}"]`);r&&a&&WU(t,r.pos,a,e)}),r.append(L(`li`,{id:`fn-${i+1}`},o,` `,a))}),L(`section`,{class:`dw-footnotes`,contenteditable:`false`,"aria-label":e?.blocks.footnotes??`Footnotes`},r)},{side:1,key:`footnotes:${i}`,ignoreSelection:!0,stopEvent:()=>!0});return bs.create(t,[...r,a])};return[new D({key:HU,state:{init:(e,n)=>t(n.doc),apply:(e,n)=>e.docChanged?t(e.doc):n},props:{decorations:e=>HU.getState(e),handleClickOn:(t,n,r,i,a)=>{if(r.type.name!==`footnote`)return!1;let o=t.nodeDOM(i);return o instanceof Element&&(a.preventDefault(),t.dispatch(t.state.tr.setSelection(E.create(t.state.doc,i))),WU(t,i,o,e),!0)}}})]}});function KU(e,t){return e.startsWith(`video/`)||/\.(mp4|webm|mov|m4v|ogv)$/i.test(t)?`video`:e.startsWith(`audio/`)||/\.(mp3|m4a|wav|ogg|oga|flac|aac|opus)$/i.test(t)?`audio`:null}function qU(e){return qp.create({name:e,group:`block`,atom:!0,draggable:!0,addOptions(){return{host:void 0}},addAttributes(){return{src:{default:``},name:{default:``},mime:{default:``}}},parseHTML(){return[{tag:`${e}[src]`,getAttrs:e=>({src:e.getAttribute(`src`)??``,name:e.getAttribute(`data-name`)??e.getAttribute(`title`)??``,mime:e.getAttribute(`data-mime`)??``})}]},renderHTML({node:t,HTMLAttributes:n}){return[e,j(n,{src:t.attrs.src,controls:``,preload:`metadata`,"data-name":t.attrs.name||null,"data-mime":t.attrs.mime||null,title:t.attrs.name||null})]},addNodeView(){return({node:t})=>{let n=this.options.host,r=document.createElement(`div`);r.className=`dw-media dw-media--${e}`,r.setAttribute(`data-type`,e);let i=document.createElement(e);i.controls=!0,i.preload=`metadata`,r.append(i);let a=``,o=t=>{let r=String(t.attrs.src??``),o=n?n.resolve(r):r;o!==a&&(i.src=o,a=o);let s=String(t.attrs.name??``);i.title=s,i.setAttribute(`aria-label`,s||e)};return o(t),{dom:r,update:e=>e.type===t.type&&(o(e),!0),stopEvent:e=>e.target===i&&e.type!==`dragstart`,ignoreMutation:()=>!0}}}})}var JU=qU(`video`),YU=qU(`audio`),XU=qp.create({name:`pageBreak`,group:`block`,atom:!0,selectable:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`div[data-type=pageBreak]`}]},renderHTML({HTMLAttributes:e}){return[`div`,j(e,{"data-type":`pageBreak`,class:`dw-page-break`,style:`break-after: page`,"data-label":this.options.labels?.blocks.pageBreak??`Page break`})]},addCommands(){return{setPageBreak:()=>({commands:e})=>e.insertContent([{type:this.name},{type:`paragraph`}])}}});function ZU(e){return typeof e==`string`?e.replace(/\s+/g,` `).trim().slice(0,40):``}var QU=qp.create({name:`status`,group:`inline`,inline:!0,atom:!0,selectable:!0,addOptions(){return{labels:null}},addAttributes(){return{text:{default:``,parseHTML:e=>ZU(e.textContent),renderHTML:()=>({})},color:{default:`gray`,parseHTML:e=>{let t=e.getAttribute(`data-color`);return FP(t)?t:`gray`},renderHTML:e=>({"data-color":e.color})}}},parseHTML(){return[{tag:`span[data-type=status]`,priority:100}]},renderHTML({node:e,HTMLAttributes:t}){return[`span`,j(t,{"data-type":`status`,class:`dw-status`}),ZU(e.attrs.text)||this.options.labels?.blocks.statusDefault||`Status`]},renderText({node:e}){return ZU(e.attrs.text)},addCommands(){return{insertStatus:e=>({commands:t})=>t.insertContent([{type:this.name,attrs:{text:ZU(e?.text)||this.options.labels?.blocks.statusDefault||`To do`,color:e?.color??`gray`}},{type:`text`,text:` `}])}},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=e,a=document.createElement(`span`);a.className=`dw-status`,a.setAttribute(`data-type`,`status`),a.contentEditable=`false`;let o=()=>{a.setAttribute(`data-color`,String(i.attrs.color)),a.textContent=ZU(i.attrs.text)||r?.blocks.statusDefault||`Status`};o();let s=e=>{let r=t();typeof r==`number`&&n.isEditable&&n.view.dispatch(n.state.tr.setNodeMarkup(r,void 0,{...i.attrs,...e}))},c=()=>{n.isEditable&&pB(a,(e,t)=>{let a=L(`input`,{class:`dw-db-input`,"aria-label":r?.blocks.statusText??`Status text`,maxlength:`40`});a.value=ZU(i.attrs.text),a.addEventListener(`input`,()=>s({text:ZU(a.value)})),a.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),t(),n.commands.focus())});let o=L(`div`,{class:`dw-status-pop__colors`,role:`radiogroup`,"aria-label":r?.blocks.statusColor??`Status colour`});for(let e of PP){let t=L(`button`,{type:`button`,class:`dw-status-pop__swatch`,"data-color":e,role:`radio`,"aria-checked":String(i.attrs.color===e),"aria-label":r?.colors[e]??e,title:r?.colors[e]??e});t.addEventListener(`click`,()=>{s({color:e}),o.querySelectorAll(`button`).forEach(e=>e.setAttribute(`aria-checked`,String(e===t)))}),o.append(t)}e.append(a,o),a.focus(),a.select()},{class:`dw-status-pop`,label:r?.blocks.status??`Status`})};return a.addEventListener(`mousedown`,e=>{n.isEditable&&(e.preventDefault(),c())}),{dom:a,update:t=>t.type===e.type&&(i=t,o(),!0),ignoreMutation:()=>!0}}}}),$U=qp.create({name:`subpages`,group:`block`,atom:!0,draggable:!0,addOptions(){return{children:void 0,labels:null,onNavigate:void 0}},parseHTML(){return[{tag:`div[data-type=subpages]`}]},renderHTML({HTMLAttributes:e}){return[`div`,j(e,{"data-type":`subpages`})]},addCommands(){return{insertSubpages:()=>({commands:e})=>e.insertContent([{type:this.name},{type:`paragraph`}])}},addNodeView(){let{children:e,labels:t,onNavigate:n}=this.options;return()=>{let r=document.createElement(`nav`);r.className=`dw-subpages`,r.setAttribute(`data-type`,`subpages`),r.contentEditable=`false`,r.setAttribute(`aria-label`,t?.blocks.subpages??`Subpages`);let i=e=>{let t=document.createElement(`p`);t.className=`dw-subpages__note`,t.textContent=e,r.replaceChildren(t)};return e?(i(t?.blocks.subpagesLoading??`Loading subpages…`),e().then(e=>{if(!e.length)return i(t?.blocks.subpagesEmpty??`This page has no subpages yet.`);let a=document.createElement(`ul`);for(let t of e){let e=document.createElement(`li`),r=document.createElement(`a`);if(r.className=`dw-subpages__link`,r.href=AH(t.id),t.icon){let e=document.createElement(`span`);e.className=`dw-subpages__icon`,e.textContent=t.icon,r.append(e)}else r.append(Vj(`page`,16));let i=document.createElement(`span`);i.textContent=t.title||`…`,r.append(i),r.addEventListener(`click`,e=>{!n||e.ctrlKey||e.metaKey||e.shiftKey||(e.preventDefault(),n(AH(t.id)))}),e.append(r),a.append(e)}r.replaceChildren(a)}).catch(()=>i(t?.blocks.subpagesEmpty??`This page has no subpages yet.`))):i(t?.blocks.subpages??`Subpages`),{dom:r,stopEvent:e=>e.type===`click`&&!!e.target?.closest?.(`a`),ignoreMutation:()=>!0}}}});function eW(e){return typeof e==`string`?e.replace(/\s+/g,` `).trim().slice(0,60):``}var tW=(e,t)=>(e?.blocks.tabName??`Tab {n}`).replace(`{n}`,String(t+1));function nW(e,t){let{schema:n}=e.state;return n.nodes.tab.create({title:t},n.nodes.paragraph.create())}var rW=qp.create({name:`tabs`,group:`block`,content:`tab+`,defining:!0,isolating:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`div[data-type=tabs]`}]},renderHTML({HTMLAttributes:e}){return[`div`,j(e,{"data-type":`tabs`,class:`dw-tabs`}),0]},addCommands(){return{insertTabs:()=>({editor:e,tr:t,dispatch:n})=>{let r=this.options.labels,i=e.schema.nodes.tabs.create(null,[nW(e,tW(r,0)),nW(e,tW(r,1))]);if(!n)return!0;let a=t.selection.from;t.replaceSelectionWith(i);let o=-1;return t.doc.nodesBetween(a,Math.min(a+i.nodeSize+2,t.doc.content.size),(e,t)=>(o<0&&e.type.name===`tabs`&&(o=t),o<0)),o>=0&&t.setSelection(T.create(t.doc,o+3)),t.scrollIntoView(),!0}}},addNodeView(){return({node:e,getPos:t,editor:n})=>{let r=this.options.labels,i=e,a=0,o=document.createElement(`div`);o.className=`dw-tabs`,o.setAttribute(`data-type`,`tabs`);let s=document.createElement(`div`);s.className=`dw-tabs__strip`,s.contentEditable=`false`,s.setAttribute(`role`,`tablist`);let c=document.createElement(`div`);c.className=`dw-tabs__body`,o.append(s,c);let l=()=>{let e=t();return typeof e==`number`?e:null},u=e=>{let t=l();if(t===null)return null;let n=t+1;for(let t=0;t{[...c.children].forEach((e,t)=>{let n=t!==a;e.hidden!==n&&(e.hidden=n),e.getAttribute(`role`)!==`tabpanel`&&e.setAttribute(`role`,`tabpanel`)})},f=new MutationObserver(d);f.observe(c,{childList:!0});let p=e=>{let t=u(e);if(t===null||!n.isEditable)return;let a=String(i.child(e).attrs.title??``),o=window.prompt(r?.blocks.renameTab??`Tab name`,a);if(o===null)return;let s=eW(o)||tW(r,e);n.view.dispatch(n.state.tr.setNodeAttribute(t,`title`,s))},m=()=>{let e=l();if(e===null||!n.isEditable)return;let t=e+i.nodeSize-1,o=n.state.tr.insert(t,nW(n,tW(r,i.childCount)));a=i.childCount,o.setSelection(T.create(o.doc,t+2)),n.view.dispatch(o),n.view.focus()},h=e=>{let t=u(e);if(t===null||!n.isEditable)return;let r=n.state.tr;if(i.childCount<=1){let e=l();r.delete(e,e+i.nodeSize)}else r.delete(t,t+i.child(e).nodeSize),a=Math.max(0,Math.min(a,i.childCount-2));n.view.dispatch(r)},g=(e,t=!1)=>{a=e,_(),t&&s.children[e]?.focus()};function _(){if(a=Math.min(a,i.childCount-1),s.replaceChildren(),i.forEach((e,t,n)=>{let o=document.createElement(`button`);o.type=`button`,o.className=n===a?`dw-tabs__tab is-active`:`dw-tabs__tab`,o.setAttribute(`role`,`tab`),o.setAttribute(`aria-selected`,String(n===a)),o.tabIndex=n===a?0:-1,o.textContent=eW(e.attrs.title)||tW(r,n),o.addEventListener(`mousedown`,e=>e.preventDefault()),o.addEventListener(`click`,()=>g(n)),o.addEventListener(`dblclick`,()=>p(n)),o.addEventListener(`keydown`,e=>{if(e.key===`ArrowRight`||e.key===`ArrowLeft`){e.preventDefault();let t=i.childCount;g((n+(e.key===`ArrowRight`?1:-1)+t)%t,!0)}else e.key===`F2`&&(e.preventDefault(),p(n))}),s.append(o)}),n.isEditable){let e=document.createElement(`button`);e.type=`button`,e.className=`dw-tabs__action`,e.textContent=`+`;let t=r?.blocks.addTab??`Add a tab`;e.title=t,e.setAttribute(`aria-label`,t),e.addEventListener(`mousedown`,e=>e.preventDefault()),e.addEventListener(`click`,m);let n=document.createElement(`button`);n.type=`button`,n.className=`dw-tabs__action dw-tabs__delete`,n.textContent=`×`;let i=r?.blocks.deleteTab??`Delete tab`;n.title=i,n.setAttribute(`aria-label`,i),n.addEventListener(`mousedown`,e=>e.preventDefault()),n.addEventListener(`click`,()=>h(a)),s.append(e,n)}d()}return _(),{dom:o,contentDOM:c,update:t=>{if(t.type!==e.type)return!1;i=t;let r=l(),{from:o}=n.state.selection;if(r!==null&&o>r&&o{o>e&&os.contains(e.target),destroy:()=>f.disconnect(),ignoreMutation:e=>s.contains(e.target)||e.type===`attributes`&&e.target.parentElement===c}}}}),iW=qp.create({name:`tab`,content:`block+`,isolating:!0,defining:!0,addAttributes(){return{title:{default:``,parseHTML:e=>eW(e.getAttribute(`data-title`)),renderHTML:e=>({"data-title":eW(e.title)})}}},parseHTML(){return[{tag:`div[data-type=tab]`}]},renderHTML({HTMLAttributes:e}){return[`div`,j(e,{"data-type":`tab`,class:`dw-tab`}),0]},addNodeView(){return({node:e})=>{let t=document.createElement(`div`);return t.className=`dw-tab`,t.setAttribute(`data-type`,`tab`),{dom:t,contentDOM:t,update:t=>t.type===e.type,ignoreMutation:e=>e.type===`attributes`&&e.target===t}}}}),aW=new O(`dwFind`),oW=``;function sW(e,t,n=!1){if(!t)return[];let r=n?t:t.toLowerCase(),i=[];return e.descendants((e,t)=>{if(!e.isTextblock)return!0;let a=``,o=[];e.forEach((e,n)=>{let r=t+1+n;if(e.isText){let t=e.text??``;for(let e=0;ee.from>=r);return a===-1&&(a=i.length?0:-1),{term:t,caseSensitive:n,matches:i,current:a}}function lW(e,t){return t&&e.setSelection(T.create(e.doc,t.from,t.to)).scrollIntoView(),e}var uW=wp.create({name:`findReplace`,addCommands(){return{setFind:(e,t=!1)=>({state:n,tr:r,dispatch:i})=>{let a=cW(n.doc,e,t,n.selection.from);return r.setMeta(aW,{term:e,caseSensitive:t,near:n.selection.from}),i&&i(lW(r,a.matches[a.current])),!0},findStep:e=>({state:t,tr:n,dispatch:r})=>{let i=aW.getState(t);if(!i?.matches.length)return!1;let a=(i.current+e+i.matches.length)%i.matches.length;return n.setMeta(aW,{current:a}),r&&r(lW(n,i.matches[a])),!0},replaceCurrent:e=>({state:t,tr:n,dispatch:r})=>{let i=aW.getState(t),a=i?.matches[i.current];if(!i||!a)return!1;if(r){n.insertText(e,a.from,a.to),n.setMeta(aW,{term:i.term,caseSensitive:i.caseSensitive,near:a.from+e.length});let t=cW(n.doc,i.term,i.caseSensitive,a.from+e.length);r(lW(n,t.matches[t.current]))}return!0},replaceAll:e=>({state:t,tr:n,dispatch:r})=>{let i=aW.getState(t);if(!i?.matches.length)return!1;if(r){for(let t of[...i.matches].reverse())n.insertText(e,t.from,t.to);n.setMeta(aW,{term:i.term,caseSensitive:i.caseSensitive,near:0}),r(n)}return!0},clearFind:()=>({tr:e,dispatch:t})=>(t&&t(e.setMeta(aW,{clear:!0})),!0)}},addProseMirrorPlugins(){let e={term:``,caseSensitive:!1,matches:[],current:-1};return[new D({key:aW,state:{init:()=>e,apply(t,n,r,i){let a=t.getMeta(aW);if(a&&`clear`in a)return e;if(a&&`term`in a)return cW(i.doc,a.term,a.caseSensitive,a.near);if(a&&`current`in a)return{...n,current:a.current};if(!n.term||!t.docChanged)return n;let o=n.matches[n.current]?.from??0;return cW(i.doc,n.term,n.caseSensitive,t.mapping.map(o))}},props:{decorations(e){let t=aW.getState(e);return t?.matches.length?bs.create(e.doc,t.matches.map((e,n)=>_s.inline(e.from,e.to,{class:n===t.current?`dw-find dw-find-current`:`dw-find`}))):null}}})]}}),R=class e extends Error{constructor(t,n){var r=`KaTeX parse error: `+t,i,a,o=n&&n.loc;if(o&&o.start<=o.end){var s=o.lexer.input;i=o.start,a=o.end,i===s.length?r+=` at end of input: `:r+=` at position `+(i+1)+`: `;var c=s.slice(i,a).replace(/[^]/g,`$&̲`),l=i>15?`…`+s.slice(i-15,i):s.slice(0,i),u=a+15e.replace(dW,`-$1`).toLowerCase(),pW={"&":`&`,">":`>`,"<":`<`,'"':`"`,"'":`'`},mW=/[&><"']/g,hW=e=>String(e).replace(mW,e=>pW[e]),gW=e=>e.type===`ordgroup`||e.type===`color`?e.body.length===1?gW(e.body[0]):e:e.type===`font`?gW(e.body):e,_W=new Set([`mathord`,`textord`,`atom`]),vW=e=>_W.has(gW(e).type),yW=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(e);return t?t[2]!==`:`||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():`_relative`},bW={displayMode:{type:`boolean`,description:`Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.`,cli:`-d, --display-mode`},output:{type:{enum:[`htmlAndMathml`,`html`,`mathml`]},description:`Determines the markup language of the output.`,cli:`-F, --format `},leqno:{type:`boolean`,description:`Render display math in leqno style (left-justified tags).`},fleqn:{type:`boolean`,description:`Render display math flush left.`},throwOnError:{type:`boolean`,default:!0,cli:`-t, --no-throw-on-error`,cliDescription:`Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error.`},errorColor:{type:`string`,default:`#cc0000`,cli:`-c, --error-color `,cliDescription:`A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.`,cliProcessor:e=>`#`+e},macros:{type:`object`,cli:`-m, --macro `,cliDescription:`Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).`,cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:`number`,description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:`--min-rule-thickness `,cliProcessor:parseFloat},colorIsTextColor:{type:`boolean`,description:`Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.`,cli:`-b, --color-is-text-color`},strict:{type:[{enum:[`warn`,`ignore`,`error`]},`boolean`,`function`],description:`Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.`,cli:`-S, --strict`,cliDefault:!1},trust:{type:[`boolean`,`function`],description:`Trust the input, enabling all HTML features such as \\url.`,cli:`-T, --trust`},maxSize:{type:`number`,default:1/0,description:`If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large`,processor:e=>Math.max(0,e),cli:`-s, --max-size `,cliProcessor:parseInt},maxExpand:{type:`number`,default:1e3,description:`Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.`,processor:e=>Math.max(0,e),cli:`-e, --max-expand `,cliProcessor:e=>e===`Infinity`?1/0:parseInt(e)},globalGroup:{type:`boolean`,cli:!1}};function xW(e){if(typeof e!=`string`)return e.enum[0];switch(e){case`boolean`:return!1;case`string`:return``;case`number`:return 0;case`object`:return{};default:throw Error(`Unexpected schema type; settings must declare an explicit default.`)}}function SW(e){return Object.prototype.hasOwnProperty.call(e,`default`)&&e.default!==void 0?e.default:xW(Array.isArray(e.type)?e.type[0]:e.type)}function CW(e,t,n,r){var i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0,a=Object.prototype.hasOwnProperty.call(r,`processor`)?r.processor:void 0;e[t]=i===void 0?SW(r):a?a(i):i}var wW=class{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e||={};for(var t of Object.keys(bW)){var n=bW[t];n&&CW(this,t,e,n)}}reportNonstrict(e,t,n){var r=this.strict;if(typeof r==`function`&&(r=r(e,t,n)),r&&r!==`ignore`){if(r===!0||r===`error`)throw new R(`LaTeX-incompatible input and strict mode is set to 'error': `+(t+` [`+e+`]`),n);r===`warn`?typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)):typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`))}}useStrictBehavior(e,t,n){var r=this.strict;if(typeof r==`function`)try{r=r(e,t,n)}catch{r=`error`}return!r||r===`ignore`?!1:r===!0||r===`error`?!0:r===`warn`?(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)),!1):(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`)),!1)}isTrusted(e){if(`url`in e&&e.url&&!e.protocol){var t=yW(e.url);if(t==null)return!1;e.protocol=t}return!!(typeof this.trust==`function`?this.trust(e):this.trust)}},TW=class{constructor(e,t,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=t,this.cramped=n}sup(){return PW[FW[this.id]]}sub(){return PW[IW[this.id]]}fracNum(){return PW[LW[this.id]]}fracDen(){return PW[RW[this.id]]}cramp(){return PW[zW[this.id]]}text(){return PW[BW[this.id]]}isTight(){return this.size>=2}},EW=0,DW=1,OW=2,kW=3,AW=4,jW=5,MW=6,NW=7,PW=[new TW(EW,0,!1),new TW(DW,0,!0),new TW(OW,1,!1),new TW(kW,1,!0),new TW(AW,2,!1),new TW(jW,2,!0),new TW(MW,3,!1),new TW(NW,3,!0)],FW=[AW,jW,AW,jW,MW,NW,MW,NW],IW=[jW,jW,jW,jW,NW,NW,NW,NW],LW=[OW,kW,AW,jW,MW,NW,MW,NW],RW=[kW,kW,jW,jW,NW,NW,NW,NW],zW=[DW,DW,kW,kW,jW,jW,NW,NW],BW=[EW,DW,OW,kW,OW,kW,OW,kW],VW={DISPLAY:PW[EW],TEXT:PW[OW],SCRIPT:PW[AW],SCRIPTSCRIPT:PW[MW]},HW=[{name:`latin`,blocks:[[256,591],[768,879]]},{name:`cyrillic`,blocks:[[1024,1279]]},{name:`armenian`,blocks:[[1328,1423]]},{name:`brahmic`,blocks:[[2304,4255]]},{name:`georgian`,blocks:[[4256,4351]]},{name:`cjk`,blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:`hangul`,blocks:[[44032,55215]]}];function UW(e){for(var t=0;t=i[0]&&e<=i[1])return n.name}return null}var WW=[];HW.forEach(e=>e.blocks.forEach(e=>WW.push(...e)));function GW(e){for(var t=0;t=WW[t]&&e<=WW[t+1])return!0;return!1}var KW=e=>e+` `+e,qW=80,JW=function(e,t){return`M95,`+(622+e+t)+` c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14 c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54 c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10 @@ -178,7 +180,7 @@ c5.3,-9.3,12,-14,20,-14 H400000v`+(40+e)+`H845.2724 s-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7 c-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z -M`+(834+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},vU=function(e,t){return`M263,`+(601+e+t)+`c0.7,0,18,39.7,52,119 +M`+(834+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},YW=function(e,t){return`M263,`+(601+e+t)+`c0.7,0,18,39.7,52,119 c34,79.3,68.167,158.7,102.5,238c34.3,79.3,51.8,119.3,52.5,120 c340,-704.7,510.7,-1060.3,512,-1067 l`+e/2.084+` -`+e+` @@ -188,7 +190,7 @@ s-271.3,567,-271.3,567c-38.7,80.7,-84,175,-136,283c-52,108,-89.167,185.3,-111.5, c-22.3,46.7,-33.8,70.3,-34.5,71c-4.7,4.7,-12.3,7,-23,7s-12,-1,-12,-1 s-109,-253,-109,-253c-72.7,-168,-109.3,-252,-110,-252c-10.7,8,-22,16.7,-34,26 c-22,17.3,-33.3,26,-34,26s-26,-26,-26,-26s76,-59,76,-59s76,-60,76,-60z -M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},yU=function(e,t){return`M983 `+(10+e+t)+` +M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},XW=function(e,t){return`M983 `+(10+e+t)+` l`+e/3.13+` -`+e+` c4,-6.7,10,-10,18,-10 H400000v`+(40+e)+` H1013.1s-83.4,268,-264.1,840c-180.7,572,-277,876.3,-289,913c-4.7,4.7,-12.7,7,-24,7 @@ -197,7 +199,7 @@ c-10,12,-21,25,-33,39s-32,39,-32,39c-6,-5.3,-15,-14,-27,-26s25,-30,25,-30 c26.7,-32.7,52,-63,76,-91s52,-60,52,-60s208,722,208,722 c56,-175.3,126.3,-397.3,211,-666c84.7,-268.7,153.8,-488.2,207.5,-658.5 c53.7,-170.3,84.5,-266.8,92.5,-289.5z -M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},bU=function(e,t){return`M424,`+(2398+e+t)+` +M`+(1001+e)+` `+t+`h400000v`+(40+e)+`h-400000z`},ZW=function(e,t){return`M424,`+(2398+e+t)+` c-1.3,-0.7,-38.5,-172,-111.5,-514c-73,-342,-109.8,-513.3,-110.5,-514 c0,-2,-10.7,14.3,-32,49c-4.7,7.3,-9.8,15.7,-15.5,25c-5.7,9.3,-9.8,16,-12.5,20 s-5,7,-5,7c-4,-3.3,-8.3,-7.7,-13,-13s-13,-13,-13,-13s76,-122,76,-122s77,-121,77,-121 @@ -207,18 +209,18 @@ v`+(40+e)+`H1014.6 s-87.3,378.7,-272.6,1166c-185.3,787.3,-279.3,1182.3,-282,1185 c-2,6,-10,9,-24,9 c-8,0,-12,-0.7,-12,-2z M`+(1001+e)+` `+t+` -h400000v`+(40+e)+`h-400000z`},xU=function(e,t){return`M473,`+(2713+e+t)+` +h400000v`+(40+e)+`h-400000z`},QW=function(e,t){return`M473,`+(2713+e+t)+` c339.3,-1799.3,509.3,-2700,510,-2702 l`+e/5.298+` -`+e+` c3.3,-7.3,9.3,-11,18,-11 H400000v`+(40+e)+`H1017.7 s-90.5,478,-276.2,1466c-185.7,988,-279.5,1483,-281.5,1485c-2,6,-10,9,-24,9 c-8,0,-12,-0.7,-12,-2c0,-1.3,-5.3,-32,-16,-92c-50.7,-293.3,-119.7,-693.3,-207,-1200 c0,-1.3,-5.3,8.7,-16,30c-10.7,21.3,-21.3,42.7,-32,64s-16,33,-16,33s-26,-26,-26,-26 s76,-153,76,-153s77,-151,77,-151c0.7,0.7,35.7,202,105,604c67.3,400.7,102,602.7,104, -606zM`+(1001+e)+` `+t+`h400000v`+(40+e)+`H1017.7z`},SU=function(e){var t=e/2;return`M400000 `+e+` H0 L`+t+` 0 l65 45 L145 `+(e-80)+` H400000z`},CU=function(e,t,n){var r=n-54-t-e;return`M702 `+(e+t)+`H400000`+(40+e)+` +606zM`+(1001+e)+` `+t+`h400000v`+(40+e)+`H1017.7z`},$W=function(e){var t=e/2;return`M400000 `+e+` H0 L`+t+` 0 l65 45 L145 `+(e-80)+` H400000z`},eG=function(e,t,n){var r=n-54-t-e;return`M702 `+(e+t)+`H400000`+(40+e)+` H742v`+r+`l-4 4-4 4c-.667.7 -2 1.5-4 2.5s-4.167 1.833-6.5 2.5-5.5 1-9.5 1 h-12l-28-84c-16.667-52-96.667 -294.333-240-727l-212 -643 -85 170 c-4-3.333-8.333-7.667-13 -13l-13-13l77-155 77-156c66 199.333 139 419.667 -219 661 l218 661zM702 `+t+`H400000v`+(40+e)+`H742z`},wU=function(e,t,n){t=1e3*t;var r=``;switch(e){case`sqrtMain`:r=_U(t,gU);break;case`sqrtSize1`:r=vU(t,gU);break;case`sqrtSize2`:r=yU(t,gU);break;case`sqrtSize3`:r=bU(t,gU);break;case`sqrtSize4`:r=xU(t,gU);break;case`sqrtTall`:r=CU(t,gU,n)}return r},TU=function(e,t){switch(e){case`⎜`:return hU(`M291 0 H417 V`+t+` H291z`);case`∣`:return hU(`M145 0 H188 V`+t+` H145z`);case`∥`:return hU(`M145 0 H188 V`+t+` H145z`)+hU(`M367 0 H410 V`+t+` H367z`);case`⎟`:return hU(`M457 0 H583 V`+t+` H457z`);case`⎢`:return hU(`M319 0 H403 V`+t+` H319z`);case`⎥`:return hU(`M263 0 H347 V`+t+` H263z`);case`⎪`:return hU(`M384 0 H504 V`+t+` H384z`);case`⏐`:return hU(`M312 0 H355 V`+t+` H312z`);case`‖`:return hU(`M257 0 H300 V`+t+` H257z`)+hU(`M478 0 H521 V`+t+` H478z`);default:return``}},EU={doubleleftarrow:`M262 157 +219 661 l218 661zM702 `+t+`H400000v`+(40+e)+`H742z`},tG=function(e,t,n){t=1e3*t;var r=``;switch(e){case`sqrtMain`:r=JW(t,qW);break;case`sqrtSize1`:r=YW(t,qW);break;case`sqrtSize2`:r=XW(t,qW);break;case`sqrtSize3`:r=ZW(t,qW);break;case`sqrtSize4`:r=QW(t,qW);break;case`sqrtTall`:r=eG(t,qW,n)}return r},nG=function(e,t){switch(e){case`⎜`:return KW(`M291 0 H417 V`+t+` H291z`);case`∣`:return KW(`M145 0 H188 V`+t+` H145z`);case`∥`:return KW(`M145 0 H188 V`+t+` H145z`)+KW(`M367 0 H410 V`+t+` H367z`);case`⎟`:return KW(`M457 0 H583 V`+t+` H457z`);case`⎢`:return KW(`M319 0 H403 V`+t+` H319z`);case`⎥`:return KW(`M263 0 H347 V`+t+` H263z`);case`⎪`:return KW(`M384 0 H504 V`+t+` H384z`);case`⏐`:return KW(`M312 0 H355 V`+t+` H312z`);case`‖`:return KW(`M257 0 H300 V`+t+` H257z`)+KW(`M478 0 H521 V`+t+` H478z`);default:return``}},rG={doubleleftarrow:`M262 157 l10-10c34-36 62.7-77 86-123 3.3-8 5-13.3 5-16 0-5.3-6.7-8-20-8-7.3 0-12.2.5-14.5 1.5-2.3 1-4.8 4.5-7.5 10.5-49.3 97.3-121.7 169.3-217 216-28 14-57.3 25-88 33-6.7 2-11 3.8-13 5.5-2 1.7-3 4.2-3 7.5s1 5.8 3 7.5 @@ -264,10 +266,10 @@ m0 0v40h400000v-40z`,leftharpoondown:`M7 241c-4 4-6.333 8.667-7 14 0 5.333.667 9 v40h399900v-40zM0 241v40h399900v-40zm0 0v40h399900v-40z`,lefthook:`M400000 281 H103s-33-11.2-61-33.5S0 197.3 0 164s14.2-61.2 42.5 -83.5C70.8 58.2 104 47 142 47 c16.7 0 25 6.7 25 20 0 12-8.7 18.7-26 20-40 3.3 -68.7 15.7-86 37-10 12-15 25.3-15 40 0 22.7 9.8 40.7 29.5 54 19.7 13.3 43.5 21 - 71.5 23h399859zM103 281v-40h399897v40z`,leftlinesegment:hU(`M40 281 V428 H0 V94 H40 V241 H400000 v40z`),leftbracketunder:hU(`M0 0 h120 V290 H399995 v120 H0z`),leftbracketover:hU(`M0 440 h120 V150 H399995 v-120 H0z`),leftmapsto:hU(`M40 281 V448H0V74H40V241H400000v40z`),leftToFrom:`M0 147h400000v40H0zm0 214c68 40 115.7 95.7 143 167h22c15.3 0 23 + 71.5 23h399859zM103 281v-40h399897v40z`,leftlinesegment:KW(`M40 281 V428 H0 V94 H40 V241 H400000 v40z`),leftbracketunder:KW(`M0 0 h120 V290 H399995 v120 H0z`),leftbracketover:KW(`M0 440 h120 V150 H399995 v-120 H0z`),leftmapsto:KW(`M40 281 V448H0V74H40V241H400000v40z`),leftToFrom:`M0 147h400000v40H0zm0 214c68 40 115.7 95.7 143 167h22c15.3 0 23 -.3 23-1 0-1.3-5.3-13.7-16-37-18-35.3-41.3-69-70-101l-7-8h399905v-40H95l7-8 c28.7-32 52-65.7 70-101 10.7-23.3 16-35.7 16-37 0-.7-7.7-1-23-1h-22C115.7 265.3 - 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z`,longequal:hU(`M0 50 h400000 v40H0z m0 194h40000v40H0z`),midbrace:`M200428 334 + 68 321 0 361zm0-174v-40h399900v40zm100 154v40h399900v-40z`,longequal:KW(`M0 50 h400000 v40H0z m0 194h40000v40H0z`),midbrace:`M200428 334 c-100.7-8.3-195.3-44-280-108-55.3-42-101.7-93-139-153l-9-14c-2.7 4-5.7 8.7-9 14 -53.3 86.7-123.7 153-211 199-66.7 36-137.3 56.3-212 62H0V214h199568c178.3-11.7 311.7-78.3 403-201 6-8 9.7-12 11-12 .7-.7 6.7-1 18-1s17.3.3 18 1c1.3 0 5 4 11 @@ -316,7 +318,7 @@ m0 0v40h399900v-40z m100 194v40h399900v-40zm0 0v40h399900v-40z`,rightharpoondown m0-194v40h400000v-40zm0 0v40h400000v-40z`,righthook:`M399859 241c-764 0 0 0 0 0 40-3.3 68.7-15.7 86-37 10-12 15-25.3 15-40 0-22.7-9.8-40.7-29.5-54-19.7-13.3-43.5-21-71.5-23-17.3-1.3-26-8-26-20 0 -13.3 8.7-20 26-20 38 0 71 11.2 99 33.5 0 0 7 5.6 21 16.7 14 11.2 21 33.5 21 - 66.8s-14 61.2-42 83.5c-28 22.3-61 33.5-99 33.5L0 241z M0 281v-40h399859v40z`,rightlinesegment:hU(`M399960 241 V94 h40 V428 h-40 V281 H0 v-40z`),rightbracketunder:hU(`M399995 0 h-120 V290 H0 v120 H400000z`),rightbracketover:hU(`M399995 440 h-120 V150 H0 v-120 H399995z`),rightToFrom:`M400000 167c-70.7-42-118-97.7-142-167h-23c-15.3 0-23 .3-23 + 66.8s-14 61.2-42 83.5c-28 22.3-61 33.5-99 33.5L0 241z M0 281v-40h399859v40z`,rightlinesegment:KW(`M399960 241 V94 h40 V428 h-40 V281 H0 v-40z`),rightbracketunder:KW(`M399995 0 h-120 V290 H0 v120 H400000z`),rightbracketover:KW(`M399995 440 h-120 V150 H0 v-120 H399995z`),rightToFrom:`M400000 167c-70.7-42-118-97.7-142-167h-23c-15.3 0-23 .3-23 1 0 1.3 5.3 13.7 16 37 18 35.3 41.3 69 70 101l7 8H0v40h399905l-7 8c-28.7 32 -52 65.7-70 101-10.7 23.3-16 35.7-16 37 0 .7 7.7 1 23 1h23c24-69.3 71.3-125 142 -167z M100 147v40h399900v-40zM0 341v40h399900v-40z`,twoheadleftarrow:`M0 167c68 40 @@ -389,7 +391,7 @@ M93 435 v40 H400000 v-40z M500 241 v40 H400000 v-40z M500 241 v40 H400000 v-40z` c4.7,-4.7,7,-9.3,7,-14c0,-9.3,-3.7,-15.3,-11,-18c-92.7,-56.7,-159,-133.7,-199, -231c-3.3,-9.3,-6,-14.7,-8,-16c-2,-1.3,-7,-2,-15,-2c-10.7,0,-16.7,2,-18,6 c-2,2.7,-1,9.7,3,21c15.3,42,36.7,81.8,64,119.5c27.3,37.7,58,69.2,92,94.5z -M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`},DU=function(e,t){switch(e){case`lbrack`:return`M403 1759 V84 H666 V0 H319 V1759 v`+t+` v1759 v84 h347 v-84 +M500 241 v40 H399408 v-40z M500 435 v40 H400000 v-40z`},iG=function(e,t){switch(e){case`lbrack`:return`M403 1759 V84 H666 V0 H319 V1759 v`+t+` v1759 v84 h347 v-84 H403z M403 1759 V0 H319 V1759 v`+t+` v1759 v84 h84z`;case`rbrack`:return`M347 1759 V0 H0 V84 H263 V1759 v`+t+` v1759 H0 v84 H347z M347 1759 V0 H263 V1759 v`+t+` v1759 h84z`;case`vert`:return`M145 15 v585 v`+t+` v585 c2.667,10,9.667,15,21,15 c10,0,16.667,-5,20,-15 v-585 v`+-t+` v-585 c-2.667,-10,-9.667,-15,-21,-15 @@ -417,20 +419,20 @@ c-55.7,194.7,-131.8,370.3,-228.5,527c-20.7,34.7,-41.7,66.3,-63,95c-2,3.3,-4,7,-6 c0,7.3,5.7,11,17,11c0,0,11,0,11,0c9.3,0,14.3,-0.3,15,-1c5.3,-5.3,10.3,-11,15,-17 c242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558 l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7, --470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z`;default:throw Error(`Unknown stretchy delimiter.`)}};function OU(e){return`toText`in e}var kU=class{constructor(e){this.children=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.children=e,this.classes=[],this.height=0,this.depth=0,this.maxFontSize=0,this.style={}}hasClass(e){return this.classes.includes(e)}toNode(){for(var e=document.createDocumentFragment(),t=0;t{if(OU(e))return e.toText();throw Error(`Expected MathDomNode with toText, got `+e.constructor.name)}).join(``)}},AU={pt:1,mm:7227/2540,cm:7227/254,in:72.27,bp:803/800,pc:12,dd:1238/1157,cc:14856/1157,nd:685/642,nc:1370/107,sp:1/65536,px:803/800},jU={ex:!0,em:!0,mu:!0},MU=function(e){return typeof e!=`string`&&(e=e.unit),e in AU||e in jU||e===`ex`},NU=function(e,t){var n;if(e.unit in AU)n=AU[e.unit]/t.fontMetrics().ptPerEm/t.sizeMultiplier;else if(e.unit===`mu`)n=t.fontMetrics().cssEmPerMu;else{var r=t.style.isTight()?t.havingStyle(t.style.text()):t;if(e.unit===`ex`)n=r.fontMetrics().xHeight;else if(e.unit===`em`)n=r.fontMetrics().quad;else throw new L(`Invalid unit: '`+e.unit+`'`);r!==t&&(n*=r.sizeMultiplier/t.sizeMultiplier)}return Math.min(e.number*n,t.maxSize)},z=function(e){return+e.toFixed(4)+`em`},PU=function(e){return e.filter(e=>e).join(` `)},FU=function(e){var t=``;for(var n of Object.keys(e)){var r=e[n];r!==void 0&&(t+=IH(n)+`:`+r+`;`)}return t},IU=function(e,t,n){if(this.classes=e||[],this.attributes={},this.height=0,this.depth=0,this.maxFontSize=0,this.style=n||{},t){t.style.isTight()&&this.classes.push(`mtight`);var r=t.getColor();r&&(this.style.color=r)}},LU=function(e){var t=document.createElement(e);t.className=PU(this.classes),Object.assign(t.style,this.style);for(var n of Object.keys(this.attributes))t.setAttribute(n,this.attributes[n]);for(var r=0;r/=\x00-\x1f]/,zU=function(e){var t=`<`+e;this.classes.length&&(t+=` class="`+zH(PU(this.classes))+`"`);var n=FU(this.style);n&&(t+=` style="`+zH(n)+`"`);for(var r of Object.keys(this.attributes)){if(RU.test(r))throw new L(`Invalid attribute name '`+r+`'`);t+=` `+r+`="`+zH(this.attributes[r])+`"`}t+=`>`;for(var i=0;i`,t},BU=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.width=void 0,this.maxFontSize=void 0,this.style=void 0,this.italic=void 0,IU.call(this,e,n,r),this.children=t||[]}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return LU.call(this,`span`)}toMarkup(){return zU.call(this,`span`)}},VU=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,IU.call(this,t,r),this.children=n||[],this.setAttribute(`href`,e)}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return LU.call(this,`a`)}toMarkup(){return zU.call(this,`a`)}},HU=class{constructor(e,t,n){this.src=void 0,this.alt=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.alt=t,this.src=e,this.classes=[`mord`],this.height=0,this.depth=0,this.maxFontSize=0,this.style=n}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createElement(`img`);return e.src=this.src,e.alt=this.alt,e.className=`mord`,Object.assign(e.style,this.style),e}toMarkup(){var e=``+zH(this.alt)+``,e}},UU={î:`ı̂`,ï:`ı̈`,í:`ı́`,ì:`ı̀`},WU=class{constructor(e,t,n,r,i,a,o,s){this.text=void 0,this.height=void 0,this.depth=void 0,this.italic=void 0,this.skew=void 0,this.width=void 0,this.maxFontSize=void 0,this.classes=void 0,this.style=void 0,this.text=e,this.height=t||0,this.depth=n||0,this.italic=r||0,this.skew=i||0,this.width=a||0,this.classes=o||[],this.style=s||{},this.maxFontSize=0;var c=fU(this.text.charCodeAt(0));c&&this.classes.push(c+`_fallback`),/[îïíì]/.test(this.text)&&(this.text=UU[this.text])}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createTextNode(this.text),t=null;return this.italic>0&&(t=document.createElement(`span`),t.style.marginRight=z(this.italic)),this.classes.length>0&&(t||=document.createElement(`span`),t.className=PU(this.classes)),Object.keys(this.style).length>0&&(t||=document.createElement(`span`),Object.assign(t.style,this.style)),t?(t.appendChild(e),t):e}toMarkup(){var e=!1,t=`0&&(n+=`margin-right:`+z(this.italic)+`;`),n+=FU(this.style),n&&(e=!0,t+=` style="`+zH(n)+`"`);var r=zH(this.text);return e?(t+=`>`,t+=r,t+=``,t):r}},GU=class{constructor(e,t){this.children=void 0,this.attributes=void 0,this.children=e||[],this.attributes=t||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);for(var n=0;n`;for(var n=0;n`,e}},KU=class{constructor(e,t){this.pathName=void 0,this.alternate=void 0,this.pathName=e,this.alternate=t}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return this.alternate?e.setAttribute(`d`,this.alternate):e.setAttribute(`d`,EU[this.pathName]),e}toMarkup(){return this.alternate?``:``}},qU=class{constructor(e){this.attributes=void 0,this.attributes=e||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);return e}toMarkup(){var e=``,e}};function JU(e){if(e instanceof WU)return e;throw Error(`Expected symbolNode but got `+String(e)+`.`)}function YU(e){if(e instanceof BU)return e;throw Error(`Expected span but got `+String(e)+`.`)}var XU=e=>e instanceof BU||e instanceof VU||e instanceof kU,ZU={"AMS-Regular":{32:[0,0,0,0,.25],65:[0,.68889,0,0,.72222],66:[0,.68889,0,0,.66667],67:[0,.68889,0,0,.72222],68:[0,.68889,0,0,.72222],69:[0,.68889,0,0,.66667],70:[0,.68889,0,0,.61111],71:[0,.68889,0,0,.77778],72:[0,.68889,0,0,.77778],73:[0,.68889,0,0,.38889],74:[.16667,.68889,0,0,.5],75:[0,.68889,0,0,.77778],76:[0,.68889,0,0,.66667],77:[0,.68889,0,0,.94445],78:[0,.68889,0,0,.72222],79:[.16667,.68889,0,0,.77778],80:[0,.68889,0,0,.61111],81:[.16667,.68889,0,0,.77778],82:[0,.68889,0,0,.72222],83:[0,.68889,0,0,.55556],84:[0,.68889,0,0,.66667],85:[0,.68889,0,0,.72222],86:[0,.68889,0,0,.72222],87:[0,.68889,0,0,1],88:[0,.68889,0,0,.72222],89:[0,.68889,0,0,.72222],90:[0,.68889,0,0,.66667],107:[0,.68889,0,0,.55556],160:[0,0,0,0,.25],165:[0,.675,.025,0,.75],174:[.15559,.69224,0,0,.94666],240:[0,.68889,0,0,.55556],295:[0,.68889,0,0,.54028],710:[0,.825,0,0,2.33334],732:[0,.9,0,0,2.33334],770:[0,.825,0,0,2.33334],771:[0,.9,0,0,2.33334],989:[.08167,.58167,0,0,.77778],1008:[0,.43056,.04028,0,.66667],8245:[0,.54986,0,0,.275],8463:[0,.68889,0,0,.54028],8487:[0,.68889,0,0,.72222],8498:[0,.68889,0,0,.55556],8502:[0,.68889,0,0,.66667],8503:[0,.68889,0,0,.44445],8504:[0,.68889,0,0,.66667],8513:[0,.68889,0,0,.63889],8592:[-.03598,.46402,0,0,.5],8594:[-.03598,.46402,0,0,.5],8602:[-.13313,.36687,0,0,1],8603:[-.13313,.36687,0,0,1],8606:[.01354,.52239,0,0,1],8608:[.01354,.52239,0,0,1],8610:[.01354,.52239,0,0,1.11111],8611:[.01354,.52239,0,0,1.11111],8619:[0,.54986,0,0,1],8620:[0,.54986,0,0,1],8621:[-.13313,.37788,0,0,1.38889],8622:[-.13313,.36687,0,0,1],8624:[0,.69224,0,0,.5],8625:[0,.69224,0,0,.5],8630:[0,.43056,0,0,1],8631:[0,.43056,0,0,1],8634:[.08198,.58198,0,0,.77778],8635:[.08198,.58198,0,0,.77778],8638:[.19444,.69224,0,0,.41667],8639:[.19444,.69224,0,0,.41667],8642:[.19444,.69224,0,0,.41667],8643:[.19444,.69224,0,0,.41667],8644:[.1808,.675,0,0,1],8646:[.1808,.675,0,0,1],8647:[.1808,.675,0,0,1],8648:[.19444,.69224,0,0,.83334],8649:[.1808,.675,0,0,1],8650:[.19444,.69224,0,0,.83334],8651:[.01354,.52239,0,0,1],8652:[.01354,.52239,0,0,1],8653:[-.13313,.36687,0,0,1],8654:[-.13313,.36687,0,0,1],8655:[-.13313,.36687,0,0,1],8666:[.13667,.63667,0,0,1],8667:[.13667,.63667,0,0,1],8669:[-.13313,.37788,0,0,1],8672:[-.064,.437,0,0,1.334],8674:[-.064,.437,0,0,1.334],8705:[0,.825,0,0,.5],8708:[0,.68889,0,0,.55556],8709:[.08167,.58167,0,0,.77778],8717:[0,.43056,0,0,.42917],8722:[-.03598,.46402,0,0,.5],8724:[.08198,.69224,0,0,.77778],8726:[.08167,.58167,0,0,.77778],8733:[0,.69224,0,0,.77778],8736:[0,.69224,0,0,.72222],8737:[0,.69224,0,0,.72222],8738:[.03517,.52239,0,0,.72222],8739:[.08167,.58167,0,0,.22222],8740:[.25142,.74111,0,0,.27778],8741:[.08167,.58167,0,0,.38889],8742:[.25142,.74111,0,0,.5],8756:[0,.69224,0,0,.66667],8757:[0,.69224,0,0,.66667],8764:[-.13313,.36687,0,0,.77778],8765:[-.13313,.37788,0,0,.77778],8769:[-.13313,.36687,0,0,.77778],8770:[-.03625,.46375,0,0,.77778],8774:[.30274,.79383,0,0,.77778],8776:[-.01688,.48312,0,0,.77778],8778:[.08167,.58167,0,0,.77778],8782:[.06062,.54986,0,0,.77778],8783:[.06062,.54986,0,0,.77778],8785:[.08198,.58198,0,0,.77778],8786:[.08198,.58198,0,0,.77778],8787:[.08198,.58198,0,0,.77778],8790:[0,.69224,0,0,.77778],8791:[.22958,.72958,0,0,.77778],8796:[.08198,.91667,0,0,.77778],8806:[.25583,.75583,0,0,.77778],8807:[.25583,.75583,0,0,.77778],8808:[.25142,.75726,0,0,.77778],8809:[.25142,.75726,0,0,.77778],8812:[.25583,.75583,0,0,.5],8814:[.20576,.70576,0,0,.77778],8815:[.20576,.70576,0,0,.77778],8816:[.30274,.79383,0,0,.77778],8817:[.30274,.79383,0,0,.77778],8818:[.22958,.72958,0,0,.77778],8819:[.22958,.72958,0,0,.77778],8822:[.1808,.675,0,0,.77778],8823:[.1808,.675,0,0,.77778],8828:[.13667,.63667,0,0,.77778],8829:[.13667,.63667,0,0,.77778],8830:[.22958,.72958,0,0,.77778],8831:[.22958,.72958,0,0,.77778],8832:[.20576,.70576,0,0,.77778],8833:[.20576,.70576,0,0,.77778],8840:[.30274,.79383,0,0,.77778],8841:[.30274,.79383,0,0,.77778],8842:[.13597,.63597,0,0,.77778],8843:[.13597,.63597,0,0,.77778],8847:[.03517,.54986,0,0,.77778],8848:[.03517,.54986,0,0,.77778],8858:[.08198,.58198,0,0,.77778],8859:[.08198,.58198,0,0,.77778],8861:[.08198,.58198,0,0,.77778],8862:[0,.675,0,0,.77778],8863:[0,.675,0,0,.77778],8864:[0,.675,0,0,.77778],8865:[0,.675,0,0,.77778],8872:[0,.69224,0,0,.61111],8873:[0,.69224,0,0,.72222],8874:[0,.69224,0,0,.88889],8876:[0,.68889,0,0,.61111],8877:[0,.68889,0,0,.61111],8878:[0,.68889,0,0,.72222],8879:[0,.68889,0,0,.72222],8882:[.03517,.54986,0,0,.77778],8883:[.03517,.54986,0,0,.77778],8884:[.13667,.63667,0,0,.77778],8885:[.13667,.63667,0,0,.77778],8888:[0,.54986,0,0,1.11111],8890:[.19444,.43056,0,0,.55556],8891:[.19444,.69224,0,0,.61111],8892:[.19444,.69224,0,0,.61111],8901:[0,.54986,0,0,.27778],8903:[.08167,.58167,0,0,.77778],8905:[.08167,.58167,0,0,.77778],8906:[.08167,.58167,0,0,.77778],8907:[0,.69224,0,0,.77778],8908:[0,.69224,0,0,.77778],8909:[-.03598,.46402,0,0,.77778],8910:[0,.54986,0,0,.76042],8911:[0,.54986,0,0,.76042],8912:[.03517,.54986,0,0,.77778],8913:[.03517,.54986,0,0,.77778],8914:[0,.54986,0,0,.66667],8915:[0,.54986,0,0,.66667],8916:[0,.69224,0,0,.66667],8918:[.0391,.5391,0,0,.77778],8919:[.0391,.5391,0,0,.77778],8920:[.03517,.54986,0,0,1.33334],8921:[.03517,.54986,0,0,1.33334],8922:[.38569,.88569,0,0,.77778],8923:[.38569,.88569,0,0,.77778],8926:[.13667,.63667,0,0,.77778],8927:[.13667,.63667,0,0,.77778],8928:[.30274,.79383,0,0,.77778],8929:[.30274,.79383,0,0,.77778],8934:[.23222,.74111,0,0,.77778],8935:[.23222,.74111,0,0,.77778],8936:[.23222,.74111,0,0,.77778],8937:[.23222,.74111,0,0,.77778],8938:[.20576,.70576,0,0,.77778],8939:[.20576,.70576,0,0,.77778],8940:[.30274,.79383,0,0,.77778],8941:[.30274,.79383,0,0,.77778],8994:[.19444,.69224,0,0,.77778],8995:[.19444,.69224,0,0,.77778],9416:[.15559,.69224,0,0,.90222],9484:[0,.69224,0,0,.5],9488:[0,.69224,0,0,.5],9492:[0,.37788,0,0,.5],9496:[0,.37788,0,0,.5],9585:[.19444,.68889,0,0,.88889],9586:[.19444,.74111,0,0,.88889],9632:[0,.675,0,0,.77778],9633:[0,.675,0,0,.77778],9650:[0,.54986,0,0,.72222],9651:[0,.54986,0,0,.72222],9654:[.03517,.54986,0,0,.77778],9660:[0,.54986,0,0,.72222],9661:[0,.54986,0,0,.72222],9664:[.03517,.54986,0,0,.77778],9674:[.11111,.69224,0,0,.66667],9733:[.19444,.69224,0,0,.94445],10003:[0,.69224,0,0,.83334],10016:[0,.69224,0,0,.83334],10731:[.11111,.69224,0,0,.66667],10846:[.19444,.75583,0,0,.61111],10877:[.13667,.63667,0,0,.77778],10878:[.13667,.63667,0,0,.77778],10885:[.25583,.75583,0,0,.77778],10886:[.25583,.75583,0,0,.77778],10887:[.13597,.63597,0,0,.77778],10888:[.13597,.63597,0,0,.77778],10889:[.26167,.75726,0,0,.77778],10890:[.26167,.75726,0,0,.77778],10891:[.48256,.98256,0,0,.77778],10892:[.48256,.98256,0,0,.77778],10901:[.13667,.63667,0,0,.77778],10902:[.13667,.63667,0,0,.77778],10933:[.25142,.75726,0,0,.77778],10934:[.25142,.75726,0,0,.77778],10935:[.26167,.75726,0,0,.77778],10936:[.26167,.75726,0,0,.77778],10937:[.26167,.75726,0,0,.77778],10938:[.26167,.75726,0,0,.77778],10949:[.25583,.75583,0,0,.77778],10950:[.25583,.75583,0,0,.77778],10955:[.28481,.79383,0,0,.77778],10956:[.28481,.79383,0,0,.77778],57350:[.08167,.58167,0,0,.22222],57351:[.08167,.58167,0,0,.38889],57352:[.08167,.58167,0,0,.77778],57353:[0,.43056,.04028,0,.66667],57356:[.25142,.75726,0,0,.77778],57357:[.25142,.75726,0,0,.77778],57358:[.41951,.91951,0,0,.77778],57359:[.30274,.79383,0,0,.77778],57360:[.30274,.79383,0,0,.77778],57361:[.41951,.91951,0,0,.77778],57366:[.25142,.75726,0,0,.77778],57367:[.25142,.75726,0,0,.77778],57368:[.25142,.75726,0,0,.77778],57369:[.25142,.75726,0,0,.77778],57370:[.13597,.63597,0,0,.77778],57371:[.13597,.63597,0,0,.77778]},"Caligraphic-Regular":{32:[0,0,0,0,.25],65:[0,.68333,0,.19445,.79847],66:[0,.68333,.03041,.13889,.65681],67:[0,.68333,.05834,.13889,.52653],68:[0,.68333,.02778,.08334,.77139],69:[0,.68333,.08944,.11111,.52778],70:[0,.68333,.09931,.11111,.71875],71:[.09722,.68333,.0593,.11111,.59487],72:[0,.68333,.00965,.11111,.84452],73:[0,.68333,.07382,0,.54452],74:[.09722,.68333,.18472,.16667,.67778],75:[0,.68333,.01445,.05556,.76195],76:[0,.68333,0,.13889,.68972],77:[0,.68333,0,.13889,1.2009],78:[0,.68333,.14736,.08334,.82049],79:[0,.68333,.02778,.11111,.79611],80:[0,.68333,.08222,.08334,.69556],81:[.09722,.68333,0,.11111,.81667],82:[0,.68333,0,.08334,.8475],83:[0,.68333,.075,.13889,.60556],84:[0,.68333,.25417,0,.54464],85:[0,.68333,.09931,.08334,.62583],86:[0,.68333,.08222,0,.61278],87:[0,.68333,.08222,.08334,.98778],88:[0,.68333,.14643,.13889,.7133],89:[.09722,.68333,.08222,.08334,.66834],90:[0,.68333,.07944,.13889,.72473],160:[0,0,0,0,.25]},"Fraktur-Regular":{32:[0,0,0,0,.25],33:[0,.69141,0,0,.29574],34:[0,.69141,0,0,.21471],38:[0,.69141,0,0,.73786],39:[0,.69141,0,0,.21201],40:[.24982,.74947,0,0,.38865],41:[.24982,.74947,0,0,.38865],42:[0,.62119,0,0,.27764],43:[.08319,.58283,0,0,.75623],44:[0,.10803,0,0,.27764],45:[.08319,.58283,0,0,.75623],46:[0,.10803,0,0,.27764],47:[.24982,.74947,0,0,.50181],48:[0,.47534,0,0,.50181],49:[0,.47534,0,0,.50181],50:[0,.47534,0,0,.50181],51:[.18906,.47534,0,0,.50181],52:[.18906,.47534,0,0,.50181],53:[.18906,.47534,0,0,.50181],54:[0,.69141,0,0,.50181],55:[.18906,.47534,0,0,.50181],56:[0,.69141,0,0,.50181],57:[.18906,.47534,0,0,.50181],58:[0,.47534,0,0,.21606],59:[.12604,.47534,0,0,.21606],61:[-.13099,.36866,0,0,.75623],63:[0,.69141,0,0,.36245],65:[0,.69141,0,0,.7176],66:[0,.69141,0,0,.88397],67:[0,.69141,0,0,.61254],68:[0,.69141,0,0,.83158],69:[0,.69141,0,0,.66278],70:[.12604,.69141,0,0,.61119],71:[0,.69141,0,0,.78539],72:[.06302,.69141,0,0,.7203],73:[0,.69141,0,0,.55448],74:[.12604,.69141,0,0,.55231],75:[0,.69141,0,0,.66845],76:[0,.69141,0,0,.66602],77:[0,.69141,0,0,1.04953],78:[0,.69141,0,0,.83212],79:[0,.69141,0,0,.82699],80:[.18906,.69141,0,0,.82753],81:[.03781,.69141,0,0,.82699],82:[0,.69141,0,0,.82807],83:[0,.69141,0,0,.82861],84:[0,.69141,0,0,.66899],85:[0,.69141,0,0,.64576],86:[0,.69141,0,0,.83131],87:[0,.69141,0,0,1.04602],88:[0,.69141,0,0,.71922],89:[.18906,.69141,0,0,.83293],90:[.12604,.69141,0,0,.60201],91:[.24982,.74947,0,0,.27764],93:[.24982,.74947,0,0,.27764],94:[0,.69141,0,0,.49965],97:[0,.47534,0,0,.50046],98:[0,.69141,0,0,.51315],99:[0,.47534,0,0,.38946],100:[0,.62119,0,0,.49857],101:[0,.47534,0,0,.40053],102:[.18906,.69141,0,0,.32626],103:[.18906,.47534,0,0,.5037],104:[.18906,.69141,0,0,.52126],105:[0,.69141,0,0,.27899],106:[0,.69141,0,0,.28088],107:[0,.69141,0,0,.38946],108:[0,.69141,0,0,.27953],109:[0,.47534,0,0,.76676],110:[0,.47534,0,0,.52666],111:[0,.47534,0,0,.48885],112:[.18906,.52396,0,0,.50046],113:[.18906,.47534,0,0,.48912],114:[0,.47534,0,0,.38919],115:[0,.47534,0,0,.44266],116:[0,.62119,0,0,.33301],117:[0,.47534,0,0,.5172],118:[0,.52396,0,0,.5118],119:[0,.52396,0,0,.77351],120:[.18906,.47534,0,0,.38865],121:[.18906,.47534,0,0,.49884],122:[.18906,.47534,0,0,.39054],160:[0,0,0,0,.25],8216:[0,.69141,0,0,.21471],8217:[0,.69141,0,0,.21471],58112:[0,.62119,0,0,.49749],58113:[0,.62119,0,0,.4983],58114:[.18906,.69141,0,0,.33328],58115:[.18906,.69141,0,0,.32923],58116:[.18906,.47534,0,0,.50343],58117:[0,.69141,0,0,.33301],58118:[0,.62119,0,0,.33409],58119:[0,.47534,0,0,.50073]},"Main-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.35],34:[0,.69444,0,0,.60278],35:[.19444,.69444,0,0,.95833],36:[.05556,.75,0,0,.575],37:[.05556,.75,0,0,.95833],38:[0,.69444,0,0,.89444],39:[0,.69444,0,0,.31944],40:[.25,.75,0,0,.44722],41:[.25,.75,0,0,.44722],42:[0,.75,0,0,.575],43:[.13333,.63333,0,0,.89444],44:[.19444,.15556,0,0,.31944],45:[0,.44444,0,0,.38333],46:[0,.15556,0,0,.31944],47:[.25,.75,0,0,.575],48:[0,.64444,0,0,.575],49:[0,.64444,0,0,.575],50:[0,.64444,0,0,.575],51:[0,.64444,0,0,.575],52:[0,.64444,0,0,.575],53:[0,.64444,0,0,.575],54:[0,.64444,0,0,.575],55:[0,.64444,0,0,.575],56:[0,.64444,0,0,.575],57:[0,.64444,0,0,.575],58:[0,.44444,0,0,.31944],59:[.19444,.44444,0,0,.31944],60:[.08556,.58556,0,0,.89444],61:[-.10889,.39111,0,0,.89444],62:[.08556,.58556,0,0,.89444],63:[0,.69444,0,0,.54305],64:[0,.69444,0,0,.89444],65:[0,.68611,0,0,.86944],66:[0,.68611,0,0,.81805],67:[0,.68611,0,0,.83055],68:[0,.68611,0,0,.88194],69:[0,.68611,0,0,.75555],70:[0,.68611,0,0,.72361],71:[0,.68611,0,0,.90416],72:[0,.68611,0,0,.9],73:[0,.68611,0,0,.43611],74:[0,.68611,0,0,.59444],75:[0,.68611,0,0,.90138],76:[0,.68611,0,0,.69166],77:[0,.68611,0,0,1.09166],78:[0,.68611,0,0,.9],79:[0,.68611,0,0,.86388],80:[0,.68611,0,0,.78611],81:[.19444,.68611,0,0,.86388],82:[0,.68611,0,0,.8625],83:[0,.68611,0,0,.63889],84:[0,.68611,0,0,.8],85:[0,.68611,0,0,.88472],86:[0,.68611,.01597,0,.86944],87:[0,.68611,.01597,0,1.18888],88:[0,.68611,0,0,.86944],89:[0,.68611,.02875,0,.86944],90:[0,.68611,0,0,.70277],91:[.25,.75,0,0,.31944],92:[.25,.75,0,0,.575],93:[.25,.75,0,0,.31944],94:[0,.69444,0,0,.575],95:[.31,.13444,.03194,0,.575],97:[0,.44444,0,0,.55902],98:[0,.69444,0,0,.63889],99:[0,.44444,0,0,.51111],100:[0,.69444,0,0,.63889],101:[0,.44444,0,0,.52708],102:[0,.69444,.10903,0,.35139],103:[.19444,.44444,.01597,0,.575],104:[0,.69444,0,0,.63889],105:[0,.69444,0,0,.31944],106:[.19444,.69444,0,0,.35139],107:[0,.69444,0,0,.60694],108:[0,.69444,0,0,.31944],109:[0,.44444,0,0,.95833],110:[0,.44444,0,0,.63889],111:[0,.44444,0,0,.575],112:[.19444,.44444,0,0,.63889],113:[.19444,.44444,0,0,.60694],114:[0,.44444,0,0,.47361],115:[0,.44444,0,0,.45361],116:[0,.63492,0,0,.44722],117:[0,.44444,0,0,.63889],118:[0,.44444,.01597,0,.60694],119:[0,.44444,.01597,0,.83055],120:[0,.44444,0,0,.60694],121:[.19444,.44444,.01597,0,.60694],122:[0,.44444,0,0,.51111],123:[.25,.75,0,0,.575],124:[.25,.75,0,0,.31944],125:[.25,.75,0,0,.575],126:[.35,.34444,0,0,.575],160:[0,0,0,0,.25],163:[0,.69444,0,0,.86853],168:[0,.69444,0,0,.575],172:[0,.44444,0,0,.76666],176:[0,.69444,0,0,.86944],177:[.13333,.63333,0,0,.89444],184:[.17014,0,0,0,.51111],198:[0,.68611,0,0,1.04166],215:[.13333,.63333,0,0,.89444],216:[.04861,.73472,0,0,.89444],223:[0,.69444,0,0,.59722],230:[0,.44444,0,0,.83055],247:[.13333,.63333,0,0,.89444],248:[.09722,.54167,0,0,.575],305:[0,.44444,0,0,.31944],338:[0,.68611,0,0,1.16944],339:[0,.44444,0,0,.89444],567:[.19444,.44444,0,0,.35139],710:[0,.69444,0,0,.575],711:[0,.63194,0,0,.575],713:[0,.59611,0,0,.575],714:[0,.69444,0,0,.575],715:[0,.69444,0,0,.575],728:[0,.69444,0,0,.575],729:[0,.69444,0,0,.31944],730:[0,.69444,0,0,.86944],732:[0,.69444,0,0,.575],733:[0,.69444,0,0,.575],915:[0,.68611,0,0,.69166],916:[0,.68611,0,0,.95833],920:[0,.68611,0,0,.89444],923:[0,.68611,0,0,.80555],926:[0,.68611,0,0,.76666],928:[0,.68611,0,0,.9],931:[0,.68611,0,0,.83055],933:[0,.68611,0,0,.89444],934:[0,.68611,0,0,.83055],936:[0,.68611,0,0,.89444],937:[0,.68611,0,0,.83055],8211:[0,.44444,.03194,0,.575],8212:[0,.44444,.03194,0,1.14999],8216:[0,.69444,0,0,.31944],8217:[0,.69444,0,0,.31944],8220:[0,.69444,0,0,.60278],8221:[0,.69444,0,0,.60278],8224:[.19444,.69444,0,0,.51111],8225:[.19444,.69444,0,0,.51111],8242:[0,.55556,0,0,.34444],8407:[0,.72444,.15486,0,.575],8463:[0,.69444,0,0,.66759],8465:[0,.69444,0,0,.83055],8467:[0,.69444,0,0,.47361],8472:[.19444,.44444,0,0,.74027],8476:[0,.69444,0,0,.83055],8501:[0,.69444,0,0,.70277],8592:[-.10889,.39111,0,0,1.14999],8593:[.19444,.69444,0,0,.575],8594:[-.10889,.39111,0,0,1.14999],8595:[.19444,.69444,0,0,.575],8596:[-.10889,.39111,0,0,1.14999],8597:[.25,.75,0,0,.575],8598:[.19444,.69444,0,0,1.14999],8599:[.19444,.69444,0,0,1.14999],8600:[.19444,.69444,0,0,1.14999],8601:[.19444,.69444,0,0,1.14999],8636:[-.10889,.39111,0,0,1.14999],8637:[-.10889,.39111,0,0,1.14999],8640:[-.10889,.39111,0,0,1.14999],8641:[-.10889,.39111,0,0,1.14999],8656:[-.10889,.39111,0,0,1.14999],8657:[.19444,.69444,0,0,.70277],8658:[-.10889,.39111,0,0,1.14999],8659:[.19444,.69444,0,0,.70277],8660:[-.10889,.39111,0,0,1.14999],8661:[.25,.75,0,0,.70277],8704:[0,.69444,0,0,.63889],8706:[0,.69444,.06389,0,.62847],8707:[0,.69444,0,0,.63889],8709:[.05556,.75,0,0,.575],8711:[0,.68611,0,0,.95833],8712:[.08556,.58556,0,0,.76666],8715:[.08556,.58556,0,0,.76666],8722:[.13333,.63333,0,0,.89444],8723:[.13333,.63333,0,0,.89444],8725:[.25,.75,0,0,.575],8726:[.25,.75,0,0,.575],8727:[-.02778,.47222,0,0,.575],8728:[-.02639,.47361,0,0,.575],8729:[-.02639,.47361,0,0,.575],8730:[.18,.82,0,0,.95833],8733:[0,.44444,0,0,.89444],8734:[0,.44444,0,0,1.14999],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.31944],8741:[.25,.75,0,0,.575],8743:[0,.55556,0,0,.76666],8744:[0,.55556,0,0,.76666],8745:[0,.55556,0,0,.76666],8746:[0,.55556,0,0,.76666],8747:[.19444,.69444,.12778,0,.56875],8764:[-.10889,.39111,0,0,.89444],8768:[.19444,.69444,0,0,.31944],8771:[.00222,.50222,0,0,.89444],8773:[.027,.638,0,0,.894],8776:[.02444,.52444,0,0,.89444],8781:[.00222,.50222,0,0,.89444],8801:[.00222,.50222,0,0,.89444],8804:[.19667,.69667,0,0,.89444],8805:[.19667,.69667,0,0,.89444],8810:[.08556,.58556,0,0,1.14999],8811:[.08556,.58556,0,0,1.14999],8826:[.08556,.58556,0,0,.89444],8827:[.08556,.58556,0,0,.89444],8834:[.08556,.58556,0,0,.89444],8835:[.08556,.58556,0,0,.89444],8838:[.19667,.69667,0,0,.89444],8839:[.19667,.69667,0,0,.89444],8846:[0,.55556,0,0,.76666],8849:[.19667,.69667,0,0,.89444],8850:[.19667,.69667,0,0,.89444],8851:[0,.55556,0,0,.76666],8852:[0,.55556,0,0,.76666],8853:[.13333,.63333,0,0,.89444],8854:[.13333,.63333,0,0,.89444],8855:[.13333,.63333,0,0,.89444],8856:[.13333,.63333,0,0,.89444],8857:[.13333,.63333,0,0,.89444],8866:[0,.69444,0,0,.70277],8867:[0,.69444,0,0,.70277],8868:[0,.69444,0,0,.89444],8869:[0,.69444,0,0,.89444],8900:[-.02639,.47361,0,0,.575],8901:[-.02639,.47361,0,0,.31944],8902:[-.02778,.47222,0,0,.575],8968:[.25,.75,0,0,.51111],8969:[.25,.75,0,0,.51111],8970:[.25,.75,0,0,.51111],8971:[.25,.75,0,0,.51111],8994:[-.13889,.36111,0,0,1.14999],8995:[-.13889,.36111,0,0,1.14999],9651:[.19444,.69444,0,0,1.02222],9657:[-.02778,.47222,0,0,.575],9661:[.19444,.69444,0,0,1.02222],9667:[-.02778,.47222,0,0,.575],9711:[.19444,.69444,0,0,1.14999],9824:[.12963,.69444,0,0,.89444],9825:[.12963,.69444,0,0,.89444],9826:[.12963,.69444,0,0,.89444],9827:[.12963,.69444,0,0,.89444],9837:[0,.75,0,0,.44722],9838:[.19444,.69444,0,0,.44722],9839:[.19444,.69444,0,0,.44722],10216:[.25,.75,0,0,.44722],10217:[.25,.75,0,0,.44722],10815:[0,.68611,0,0,.9],10927:[.19667,.69667,0,0,.89444],10928:[.19667,.69667,0,0,.89444],57376:[.19444,.69444,0,0,0]},"Main-BoldItalic":{32:[0,0,0,0,.25],33:[0,.69444,.11417,0,.38611],34:[0,.69444,.07939,0,.62055],35:[.19444,.69444,.06833,0,.94444],37:[.05556,.75,.12861,0,.94444],38:[0,.69444,.08528,0,.88555],39:[0,.69444,.12945,0,.35555],40:[.25,.75,.15806,0,.47333],41:[.25,.75,.03306,0,.47333],42:[0,.75,.14333,0,.59111],43:[.10333,.60333,.03306,0,.88555],44:[.19444,.14722,0,0,.35555],45:[0,.44444,.02611,0,.41444],46:[0,.14722,0,0,.35555],47:[.25,.75,.15806,0,.59111],48:[0,.64444,.13167,0,.59111],49:[0,.64444,.13167,0,.59111],50:[0,.64444,.13167,0,.59111],51:[0,.64444,.13167,0,.59111],52:[.19444,.64444,.13167,0,.59111],53:[0,.64444,.13167,0,.59111],54:[0,.64444,.13167,0,.59111],55:[.19444,.64444,.13167,0,.59111],56:[0,.64444,.13167,0,.59111],57:[0,.64444,.13167,0,.59111],58:[0,.44444,.06695,0,.35555],59:[.19444,.44444,.06695,0,.35555],61:[-.10889,.39111,.06833,0,.88555],63:[0,.69444,.11472,0,.59111],64:[0,.69444,.09208,0,.88555],65:[0,.68611,0,0,.86555],66:[0,.68611,.0992,0,.81666],67:[0,.68611,.14208,0,.82666],68:[0,.68611,.09062,0,.87555],69:[0,.68611,.11431,0,.75666],70:[0,.68611,.12903,0,.72722],71:[0,.68611,.07347,0,.89527],72:[0,.68611,.17208,0,.8961],73:[0,.68611,.15681,0,.47166],74:[0,.68611,.145,0,.61055],75:[0,.68611,.14208,0,.89499],76:[0,.68611,0,0,.69777],77:[0,.68611,.17208,0,1.07277],78:[0,.68611,.17208,0,.8961],79:[0,.68611,.09062,0,.85499],80:[0,.68611,.0992,0,.78721],81:[.19444,.68611,.09062,0,.85499],82:[0,.68611,.02559,0,.85944],83:[0,.68611,.11264,0,.64999],84:[0,.68611,.12903,0,.7961],85:[0,.68611,.17208,0,.88083],86:[0,.68611,.18625,0,.86555],87:[0,.68611,.18625,0,1.15999],88:[0,.68611,.15681,0,.86555],89:[0,.68611,.19803,0,.86555],90:[0,.68611,.14208,0,.70888],91:[.25,.75,.1875,0,.35611],93:[.25,.75,.09972,0,.35611],94:[0,.69444,.06709,0,.59111],95:[.31,.13444,.09811,0,.59111],97:[0,.44444,.09426,0,.59111],98:[0,.69444,.07861,0,.53222],99:[0,.44444,.05222,0,.53222],100:[0,.69444,.10861,0,.59111],101:[0,.44444,.085,0,.53222],102:[.19444,.69444,.21778,0,.4],103:[.19444,.44444,.105,0,.53222],104:[0,.69444,.09426,0,.59111],105:[0,.69326,.11387,0,.35555],106:[.19444,.69326,.1672,0,.35555],107:[0,.69444,.11111,0,.53222],108:[0,.69444,.10861,0,.29666],109:[0,.44444,.09426,0,.94444],110:[0,.44444,.09426,0,.64999],111:[0,.44444,.07861,0,.59111],112:[.19444,.44444,.07861,0,.59111],113:[.19444,.44444,.105,0,.53222],114:[0,.44444,.11111,0,.50167],115:[0,.44444,.08167,0,.48694],116:[0,.63492,.09639,0,.385],117:[0,.44444,.09426,0,.62055],118:[0,.44444,.11111,0,.53222],119:[0,.44444,.11111,0,.76777],120:[0,.44444,.12583,0,.56055],121:[.19444,.44444,.105,0,.56166],122:[0,.44444,.13889,0,.49055],126:[.35,.34444,.11472,0,.59111],160:[0,0,0,0,.25],168:[0,.69444,.11473,0,.59111],176:[0,.69444,0,0,.94888],184:[.17014,0,0,0,.53222],198:[0,.68611,.11431,0,1.02277],216:[.04861,.73472,.09062,0,.88555],223:[.19444,.69444,.09736,0,.665],230:[0,.44444,.085,0,.82666],248:[.09722,.54167,.09458,0,.59111],305:[0,.44444,.09426,0,.35555],338:[0,.68611,.11431,0,1.14054],339:[0,.44444,.085,0,.82666],567:[.19444,.44444,.04611,0,.385],710:[0,.69444,.06709,0,.59111],711:[0,.63194,.08271,0,.59111],713:[0,.59444,.10444,0,.59111],714:[0,.69444,.08528,0,.59111],715:[0,.69444,0,0,.59111],728:[0,.69444,.10333,0,.59111],729:[0,.69444,.12945,0,.35555],730:[0,.69444,0,0,.94888],732:[0,.69444,.11472,0,.59111],733:[0,.69444,.11472,0,.59111],915:[0,.68611,.12903,0,.69777],916:[0,.68611,0,0,.94444],920:[0,.68611,.09062,0,.88555],923:[0,.68611,0,0,.80666],926:[0,.68611,.15092,0,.76777],928:[0,.68611,.17208,0,.8961],931:[0,.68611,.11431,0,.82666],933:[0,.68611,.10778,0,.88555],934:[0,.68611,.05632,0,.82666],936:[0,.68611,.10778,0,.88555],937:[0,.68611,.0992,0,.82666],8211:[0,.44444,.09811,0,.59111],8212:[0,.44444,.09811,0,1.18221],8216:[0,.69444,.12945,0,.35555],8217:[0,.69444,.12945,0,.35555],8220:[0,.69444,.16772,0,.62055],8221:[0,.69444,.07939,0,.62055]},"Main-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.12417,0,.30667],34:[0,.69444,.06961,0,.51444],35:[.19444,.69444,.06616,0,.81777],37:[.05556,.75,.13639,0,.81777],38:[0,.69444,.09694,0,.76666],39:[0,.69444,.12417,0,.30667],40:[.25,.75,.16194,0,.40889],41:[.25,.75,.03694,0,.40889],42:[0,.75,.14917,0,.51111],43:[.05667,.56167,.03694,0,.76666],44:[.19444,.10556,0,0,.30667],45:[0,.43056,.02826,0,.35778],46:[0,.10556,0,0,.30667],47:[.25,.75,.16194,0,.51111],48:[0,.64444,.13556,0,.51111],49:[0,.64444,.13556,0,.51111],50:[0,.64444,.13556,0,.51111],51:[0,.64444,.13556,0,.51111],52:[.19444,.64444,.13556,0,.51111],53:[0,.64444,.13556,0,.51111],54:[0,.64444,.13556,0,.51111],55:[.19444,.64444,.13556,0,.51111],56:[0,.64444,.13556,0,.51111],57:[0,.64444,.13556,0,.51111],58:[0,.43056,.0582,0,.30667],59:[.19444,.43056,.0582,0,.30667],61:[-.13313,.36687,.06616,0,.76666],63:[0,.69444,.1225,0,.51111],64:[0,.69444,.09597,0,.76666],65:[0,.68333,0,0,.74333],66:[0,.68333,.10257,0,.70389],67:[0,.68333,.14528,0,.71555],68:[0,.68333,.09403,0,.755],69:[0,.68333,.12028,0,.67833],70:[0,.68333,.13305,0,.65277],71:[0,.68333,.08722,0,.77361],72:[0,.68333,.16389,0,.74333],73:[0,.68333,.15806,0,.38555],74:[0,.68333,.14028,0,.525],75:[0,.68333,.14528,0,.76888],76:[0,.68333,0,0,.62722],77:[0,.68333,.16389,0,.89666],78:[0,.68333,.16389,0,.74333],79:[0,.68333,.09403,0,.76666],80:[0,.68333,.10257,0,.67833],81:[.19444,.68333,.09403,0,.76666],82:[0,.68333,.03868,0,.72944],83:[0,.68333,.11972,0,.56222],84:[0,.68333,.13305,0,.71555],85:[0,.68333,.16389,0,.74333],86:[0,.68333,.18361,0,.74333],87:[0,.68333,.18361,0,.99888],88:[0,.68333,.15806,0,.74333],89:[0,.68333,.19383,0,.74333],90:[0,.68333,.14528,0,.61333],91:[.25,.75,.1875,0,.30667],93:[.25,.75,.10528,0,.30667],94:[0,.69444,.06646,0,.51111],95:[.31,.12056,.09208,0,.51111],97:[0,.43056,.07671,0,.51111],98:[0,.69444,.06312,0,.46],99:[0,.43056,.05653,0,.46],100:[0,.69444,.10333,0,.51111],101:[0,.43056,.07514,0,.46],102:[.19444,.69444,.21194,0,.30667],103:[.19444,.43056,.08847,0,.46],104:[0,.69444,.07671,0,.51111],105:[0,.65536,.1019,0,.30667],106:[.19444,.65536,.14467,0,.30667],107:[0,.69444,.10764,0,.46],108:[0,.69444,.10333,0,.25555],109:[0,.43056,.07671,0,.81777],110:[0,.43056,.07671,0,.56222],111:[0,.43056,.06312,0,.51111],112:[.19444,.43056,.06312,0,.51111],113:[.19444,.43056,.08847,0,.46],114:[0,.43056,.10764,0,.42166],115:[0,.43056,.08208,0,.40889],116:[0,.61508,.09486,0,.33222],117:[0,.43056,.07671,0,.53666],118:[0,.43056,.10764,0,.46],119:[0,.43056,.10764,0,.66444],120:[0,.43056,.12042,0,.46389],121:[.19444,.43056,.08847,0,.48555],122:[0,.43056,.12292,0,.40889],126:[.35,.31786,.11585,0,.51111],160:[0,0,0,0,.25],168:[0,.66786,.10474,0,.51111],176:[0,.69444,0,0,.83129],184:[.17014,0,0,0,.46],198:[0,.68333,.12028,0,.88277],216:[.04861,.73194,.09403,0,.76666],223:[.19444,.69444,.10514,0,.53666],230:[0,.43056,.07514,0,.71555],248:[.09722,.52778,.09194,0,.51111],338:[0,.68333,.12028,0,.98499],339:[0,.43056,.07514,0,.71555],710:[0,.69444,.06646,0,.51111],711:[0,.62847,.08295,0,.51111],713:[0,.56167,.10333,0,.51111],714:[0,.69444,.09694,0,.51111],715:[0,.69444,0,0,.51111],728:[0,.69444,.10806,0,.51111],729:[0,.66786,.11752,0,.30667],730:[0,.69444,0,0,.83129],732:[0,.66786,.11585,0,.51111],733:[0,.69444,.1225,0,.51111],915:[0,.68333,.13305,0,.62722],916:[0,.68333,0,0,.81777],920:[0,.68333,.09403,0,.76666],923:[0,.68333,0,0,.69222],926:[0,.68333,.15294,0,.66444],928:[0,.68333,.16389,0,.74333],931:[0,.68333,.12028,0,.71555],933:[0,.68333,.11111,0,.76666],934:[0,.68333,.05986,0,.71555],936:[0,.68333,.11111,0,.76666],937:[0,.68333,.10257,0,.71555],8211:[0,.43056,.09208,0,.51111],8212:[0,.43056,.09208,0,1.02222],8216:[0,.69444,.12417,0,.30667],8217:[0,.69444,.12417,0,.30667],8220:[0,.69444,.1685,0,.51444],8221:[0,.69444,.06961,0,.51444],8463:[0,.68889,0,0,.54028]},"Main-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.27778],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.77778],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.19444,.10556,0,0,.27778],45:[0,.43056,0,0,.33333],46:[0,.10556,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.64444,0,0,.5],49:[0,.64444,0,0,.5],50:[0,.64444,0,0,.5],51:[0,.64444,0,0,.5],52:[0,.64444,0,0,.5],53:[0,.64444,0,0,.5],54:[0,.64444,0,0,.5],55:[0,.64444,0,0,.5],56:[0,.64444,0,0,.5],57:[0,.64444,0,0,.5],58:[0,.43056,0,0,.27778],59:[.19444,.43056,0,0,.27778],60:[.0391,.5391,0,0,.77778],61:[-.13313,.36687,0,0,.77778],62:[.0391,.5391,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.77778],65:[0,.68333,0,0,.75],66:[0,.68333,0,0,.70834],67:[0,.68333,0,0,.72222],68:[0,.68333,0,0,.76389],69:[0,.68333,0,0,.68056],70:[0,.68333,0,0,.65278],71:[0,.68333,0,0,.78472],72:[0,.68333,0,0,.75],73:[0,.68333,0,0,.36111],74:[0,.68333,0,0,.51389],75:[0,.68333,0,0,.77778],76:[0,.68333,0,0,.625],77:[0,.68333,0,0,.91667],78:[0,.68333,0,0,.75],79:[0,.68333,0,0,.77778],80:[0,.68333,0,0,.68056],81:[.19444,.68333,0,0,.77778],82:[0,.68333,0,0,.73611],83:[0,.68333,0,0,.55556],84:[0,.68333,0,0,.72222],85:[0,.68333,0,0,.75],86:[0,.68333,.01389,0,.75],87:[0,.68333,.01389,0,1.02778],88:[0,.68333,0,0,.75],89:[0,.68333,.025,0,.75],90:[0,.68333,0,0,.61111],91:[.25,.75,0,0,.27778],92:[.25,.75,0,0,.5],93:[.25,.75,0,0,.27778],94:[0,.69444,0,0,.5],95:[.31,.12056,.02778,0,.5],97:[0,.43056,0,0,.5],98:[0,.69444,0,0,.55556],99:[0,.43056,0,0,.44445],100:[0,.69444,0,0,.55556],101:[0,.43056,0,0,.44445],102:[0,.69444,.07778,0,.30556],103:[.19444,.43056,.01389,0,.5],104:[0,.69444,0,0,.55556],105:[0,.66786,0,0,.27778],106:[.19444,.66786,0,0,.30556],107:[0,.69444,0,0,.52778],108:[0,.69444,0,0,.27778],109:[0,.43056,0,0,.83334],110:[0,.43056,0,0,.55556],111:[0,.43056,0,0,.5],112:[.19444,.43056,0,0,.55556],113:[.19444,.43056,0,0,.52778],114:[0,.43056,0,0,.39167],115:[0,.43056,0,0,.39445],116:[0,.61508,0,0,.38889],117:[0,.43056,0,0,.55556],118:[0,.43056,.01389,0,.52778],119:[0,.43056,.01389,0,.72222],120:[0,.43056,0,0,.52778],121:[.19444,.43056,.01389,0,.52778],122:[0,.43056,0,0,.44445],123:[.25,.75,0,0,.5],124:[.25,.75,0,0,.27778],125:[.25,.75,0,0,.5],126:[.35,.31786,0,0,.5],160:[0,0,0,0,.25],163:[0,.69444,0,0,.76909],167:[.19444,.69444,0,0,.44445],168:[0,.66786,0,0,.5],172:[0,.43056,0,0,.66667],176:[0,.69444,0,0,.75],177:[.08333,.58333,0,0,.77778],182:[.19444,.69444,0,0,.61111],184:[.17014,0,0,0,.44445],198:[0,.68333,0,0,.90278],215:[.08333,.58333,0,0,.77778],216:[.04861,.73194,0,0,.77778],223:[0,.69444,0,0,.5],230:[0,.43056,0,0,.72222],247:[.08333,.58333,0,0,.77778],248:[.09722,.52778,0,0,.5],305:[0,.43056,0,0,.27778],338:[0,.68333,0,0,1.01389],339:[0,.43056,0,0,.77778],567:[.19444,.43056,0,0,.30556],710:[0,.69444,0,0,.5],711:[0,.62847,0,0,.5],713:[0,.56778,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.66786,0,0,.27778],730:[0,.69444,0,0,.75],732:[0,.66786,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.68333,0,0,.625],916:[0,.68333,0,0,.83334],920:[0,.68333,0,0,.77778],923:[0,.68333,0,0,.69445],926:[0,.68333,0,0,.66667],928:[0,.68333,0,0,.75],931:[0,.68333,0,0,.72222],933:[0,.68333,0,0,.77778],934:[0,.68333,0,0,.72222],936:[0,.68333,0,0,.77778],937:[0,.68333,0,0,.72222],8211:[0,.43056,.02778,0,.5],8212:[0,.43056,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5],8224:[.19444,.69444,0,0,.44445],8225:[.19444,.69444,0,0,.44445],8230:[0,.123,0,0,1.172],8242:[0,.55556,0,0,.275],8407:[0,.71444,.15382,0,.5],8463:[0,.68889,0,0,.54028],8465:[0,.69444,0,0,.72222],8467:[0,.69444,0,.11111,.41667],8472:[.19444,.43056,0,.11111,.63646],8476:[0,.69444,0,0,.72222],8501:[0,.69444,0,0,.61111],8592:[-.13313,.36687,0,0,1],8593:[.19444,.69444,0,0,.5],8594:[-.13313,.36687,0,0,1],8595:[.19444,.69444,0,0,.5],8596:[-.13313,.36687,0,0,1],8597:[.25,.75,0,0,.5],8598:[.19444,.69444,0,0,1],8599:[.19444,.69444,0,0,1],8600:[.19444,.69444,0,0,1],8601:[.19444,.69444,0,0,1],8614:[.011,.511,0,0,1],8617:[.011,.511,0,0,1.126],8618:[.011,.511,0,0,1.126],8636:[-.13313,.36687,0,0,1],8637:[-.13313,.36687,0,0,1],8640:[-.13313,.36687,0,0,1],8641:[-.13313,.36687,0,0,1],8652:[.011,.671,0,0,1],8656:[-.13313,.36687,0,0,1],8657:[.19444,.69444,0,0,.61111],8658:[-.13313,.36687,0,0,1],8659:[.19444,.69444,0,0,.61111],8660:[-.13313,.36687,0,0,1],8661:[.25,.75,0,0,.61111],8704:[0,.69444,0,0,.55556],8706:[0,.69444,.05556,.08334,.5309],8707:[0,.69444,0,0,.55556],8709:[.05556,.75,0,0,.5],8711:[0,.68333,0,0,.83334],8712:[.0391,.5391,0,0,.66667],8715:[.0391,.5391,0,0,.66667],8722:[.08333,.58333,0,0,.77778],8723:[.08333,.58333,0,0,.77778],8725:[.25,.75,0,0,.5],8726:[.25,.75,0,0,.5],8727:[-.03472,.46528,0,0,.5],8728:[-.05555,.44445,0,0,.5],8729:[-.05555,.44445,0,0,.5],8730:[.2,.8,0,0,.83334],8733:[0,.43056,0,0,.77778],8734:[0,.43056,0,0,1],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.27778],8741:[.25,.75,0,0,.5],8743:[0,.55556,0,0,.66667],8744:[0,.55556,0,0,.66667],8745:[0,.55556,0,0,.66667],8746:[0,.55556,0,0,.66667],8747:[.19444,.69444,.11111,0,.41667],8764:[-.13313,.36687,0,0,.77778],8768:[.19444,.69444,0,0,.27778],8771:[-.03625,.46375,0,0,.77778],8773:[-.022,.589,0,0,.778],8776:[-.01688,.48312,0,0,.77778],8781:[-.03625,.46375,0,0,.77778],8784:[-.133,.673,0,0,.778],8801:[-.03625,.46375,0,0,.77778],8804:[.13597,.63597,0,0,.77778],8805:[.13597,.63597,0,0,.77778],8810:[.0391,.5391,0,0,1],8811:[.0391,.5391,0,0,1],8826:[.0391,.5391,0,0,.77778],8827:[.0391,.5391,0,0,.77778],8834:[.0391,.5391,0,0,.77778],8835:[.0391,.5391,0,0,.77778],8838:[.13597,.63597,0,0,.77778],8839:[.13597,.63597,0,0,.77778],8846:[0,.55556,0,0,.66667],8849:[.13597,.63597,0,0,.77778],8850:[.13597,.63597,0,0,.77778],8851:[0,.55556,0,0,.66667],8852:[0,.55556,0,0,.66667],8853:[.08333,.58333,0,0,.77778],8854:[.08333,.58333,0,0,.77778],8855:[.08333,.58333,0,0,.77778],8856:[.08333,.58333,0,0,.77778],8857:[.08333,.58333,0,0,.77778],8866:[0,.69444,0,0,.61111],8867:[0,.69444,0,0,.61111],8868:[0,.69444,0,0,.77778],8869:[0,.69444,0,0,.77778],8872:[.249,.75,0,0,.867],8900:[-.05555,.44445,0,0,.5],8901:[-.05555,.44445,0,0,.27778],8902:[-.03472,.46528,0,0,.5],8904:[.005,.505,0,0,.9],8942:[.03,.903,0,0,.278],8943:[-.19,.313,0,0,1.172],8945:[-.1,.823,0,0,1.282],8968:[.25,.75,0,0,.44445],8969:[.25,.75,0,0,.44445],8970:[.25,.75,0,0,.44445],8971:[.25,.75,0,0,.44445],8994:[-.14236,.35764,0,0,1],8995:[-.14236,.35764,0,0,1],9136:[.244,.744,0,0,.412],9137:[.244,.745,0,0,.412],9651:[.19444,.69444,0,0,.88889],9657:[-.03472,.46528,0,0,.5],9661:[.19444,.69444,0,0,.88889],9667:[-.03472,.46528,0,0,.5],9711:[.19444,.69444,0,0,1],9824:[.12963,.69444,0,0,.77778],9825:[.12963,.69444,0,0,.77778],9826:[.12963,.69444,0,0,.77778],9827:[.12963,.69444,0,0,.77778],9837:[0,.75,0,0,.38889],9838:[.19444,.69444,0,0,.38889],9839:[.19444,.69444,0,0,.38889],10216:[.25,.75,0,0,.38889],10217:[.25,.75,0,0,.38889],10222:[.244,.744,0,0,.412],10223:[.244,.745,0,0,.412],10229:[.011,.511,0,0,1.609],10230:[.011,.511,0,0,1.638],10231:[.011,.511,0,0,1.859],10232:[.024,.525,0,0,1.609],10233:[.024,.525,0,0,1.638],10234:[.024,.525,0,0,1.858],10236:[.011,.511,0,0,1.638],10815:[0,.68333,0,0,.75],10927:[.13597,.63597,0,0,.77778],10928:[.13597,.63597,0,0,.77778],57376:[.19444,.69444,0,0,0]},"Math-BoldItalic":{32:[0,0,0,0,.25],48:[0,.44444,0,0,.575],49:[0,.44444,0,0,.575],50:[0,.44444,0,0,.575],51:[.19444,.44444,0,0,.575],52:[.19444,.44444,0,0,.575],53:[.19444,.44444,0,0,.575],54:[0,.64444,0,0,.575],55:[.19444,.44444,0,0,.575],56:[0,.64444,0,0,.575],57:[.19444,.44444,0,0,.575],65:[0,.68611,0,0,.86944],66:[0,.68611,.04835,0,.8664],67:[0,.68611,.06979,0,.81694],68:[0,.68611,.03194,0,.93812],69:[0,.68611,.05451,0,.81007],70:[0,.68611,.15972,0,.68889],71:[0,.68611,0,0,.88673],72:[0,.68611,.08229,0,.98229],73:[0,.68611,.07778,0,.51111],74:[0,.68611,.10069,0,.63125],75:[0,.68611,.06979,0,.97118],76:[0,.68611,0,0,.75555],77:[0,.68611,.11424,0,1.14201],78:[0,.68611,.11424,0,.95034],79:[0,.68611,.03194,0,.83666],80:[0,.68611,.15972,0,.72309],81:[.19444,.68611,0,0,.86861],82:[0,.68611,.00421,0,.87235],83:[0,.68611,.05382,0,.69271],84:[0,.68611,.15972,0,.63663],85:[0,.68611,.11424,0,.80027],86:[0,.68611,.25555,0,.67778],87:[0,.68611,.15972,0,1.09305],88:[0,.68611,.07778,0,.94722],89:[0,.68611,.25555,0,.67458],90:[0,.68611,.06979,0,.77257],97:[0,.44444,0,0,.63287],98:[0,.69444,0,0,.52083],99:[0,.44444,0,0,.51342],100:[0,.69444,0,0,.60972],101:[0,.44444,0,0,.55361],102:[.19444,.69444,.11042,0,.56806],103:[.19444,.44444,.03704,0,.5449],104:[0,.69444,0,0,.66759],105:[0,.69326,0,0,.4048],106:[.19444,.69326,.0622,0,.47083],107:[0,.69444,.01852,0,.6037],108:[0,.69444,.0088,0,.34815],109:[0,.44444,0,0,1.0324],110:[0,.44444,0,0,.71296],111:[0,.44444,0,0,.58472],112:[.19444,.44444,0,0,.60092],113:[.19444,.44444,.03704,0,.54213],114:[0,.44444,.03194,0,.5287],115:[0,.44444,0,0,.53125],116:[0,.63492,0,0,.41528],117:[0,.44444,0,0,.68102],118:[0,.44444,.03704,0,.56666],119:[0,.44444,.02778,0,.83148],120:[0,.44444,0,0,.65903],121:[.19444,.44444,.03704,0,.59028],122:[0,.44444,.04213,0,.55509],160:[0,0,0,0,.25],915:[0,.68611,.15972,0,.65694],916:[0,.68611,0,0,.95833],920:[0,.68611,.03194,0,.86722],923:[0,.68611,0,0,.80555],926:[0,.68611,.07458,0,.84125],928:[0,.68611,.08229,0,.98229],931:[0,.68611,.05451,0,.88507],933:[0,.68611,.15972,0,.67083],934:[0,.68611,0,0,.76666],936:[0,.68611,.11653,0,.71402],937:[0,.68611,.04835,0,.8789],945:[0,.44444,0,0,.76064],946:[.19444,.69444,.03403,0,.65972],947:[.19444,.44444,.06389,0,.59003],948:[0,.69444,.03819,0,.52222],949:[0,.44444,0,0,.52882],950:[.19444,.69444,.06215,0,.50833],951:[.19444,.44444,.03704,0,.6],952:[0,.69444,.03194,0,.5618],953:[0,.44444,0,0,.41204],954:[0,.44444,0,0,.66759],955:[0,.69444,0,0,.67083],956:[.19444,.44444,0,0,.70787],957:[0,.44444,.06898,0,.57685],958:[.19444,.69444,.03021,0,.50833],959:[0,.44444,0,0,.58472],960:[0,.44444,.03704,0,.68241],961:[.19444,.44444,0,0,.6118],962:[.09722,.44444,.07917,0,.42361],963:[0,.44444,.03704,0,.68588],964:[0,.44444,.13472,0,.52083],965:[0,.44444,.03704,0,.63055],966:[.19444,.44444,0,0,.74722],967:[.19444,.44444,0,0,.71805],968:[.19444,.69444,.03704,0,.75833],969:[0,.44444,.03704,0,.71782],977:[0,.69444,0,0,.69155],981:[.19444,.69444,0,0,.7125],982:[0,.44444,.03194,0,.975],1009:[.19444,.44444,0,0,.6118],1013:[0,.44444,0,0,.48333],57649:[0,.44444,0,0,.39352],57911:[.19444,.44444,0,0,.43889]},"Math-Italic":{32:[0,0,0,0,.25],48:[0,.43056,0,0,.5],49:[0,.43056,0,0,.5],50:[0,.43056,0,0,.5],51:[.19444,.43056,0,0,.5],52:[.19444,.43056,0,0,.5],53:[.19444,.43056,0,0,.5],54:[0,.64444,0,0,.5],55:[.19444,.43056,0,0,.5],56:[0,.64444,0,0,.5],57:[.19444,.43056,0,0,.5],65:[0,.68333,0,.13889,.75],66:[0,.68333,.05017,.08334,.75851],67:[0,.68333,.07153,.08334,.71472],68:[0,.68333,.02778,.05556,.82792],69:[0,.68333,.05764,.08334,.7382],70:[0,.68333,.13889,.08334,.64306],71:[0,.68333,0,.08334,.78625],72:[0,.68333,.08125,.05556,.83125],73:[0,.68333,.07847,.11111,.43958],74:[0,.68333,.09618,.16667,.55451],75:[0,.68333,.07153,.05556,.84931],76:[0,.68333,0,.02778,.68056],77:[0,.68333,.10903,.08334,.97014],78:[0,.68333,.10903,.08334,.80347],79:[0,.68333,.02778,.08334,.76278],80:[0,.68333,.13889,.08334,.64201],81:[.19444,.68333,0,.08334,.79056],82:[0,.68333,.00773,.08334,.75929],83:[0,.68333,.05764,.08334,.6132],84:[0,.68333,.13889,.08334,.58438],85:[0,.68333,.10903,.02778,.68278],86:[0,.68333,.22222,0,.58333],87:[0,.68333,.13889,0,.94445],88:[0,.68333,.07847,.08334,.82847],89:[0,.68333,.22222,0,.58056],90:[0,.68333,.07153,.08334,.68264],97:[0,.43056,0,0,.52859],98:[0,.69444,0,0,.42917],99:[0,.43056,0,.05556,.43276],100:[0,.69444,0,.16667,.52049],101:[0,.43056,0,.05556,.46563],102:[.19444,.69444,.10764,.16667,.48959],103:[.19444,.43056,.03588,.02778,.47697],104:[0,.69444,0,0,.57616],105:[0,.65952,0,0,.34451],106:[.19444,.65952,.05724,0,.41181],107:[0,.69444,.03148,0,.5206],108:[0,.69444,.01968,.08334,.29838],109:[0,.43056,0,0,.87801],110:[0,.43056,0,0,.60023],111:[0,.43056,0,.05556,.48472],112:[.19444,.43056,0,.08334,.50313],113:[.19444,.43056,.03588,.08334,.44641],114:[0,.43056,.02778,.05556,.45116],115:[0,.43056,0,.05556,.46875],116:[0,.61508,0,.08334,.36111],117:[0,.43056,0,.02778,.57246],118:[0,.43056,.03588,.02778,.48472],119:[0,.43056,.02691,.08334,.71592],120:[0,.43056,0,.02778,.57153],121:[.19444,.43056,.03588,.05556,.49028],122:[0,.43056,.04398,.05556,.46505],160:[0,0,0,0,.25],915:[0,.68333,.13889,.08334,.61528],916:[0,.68333,0,.16667,.83334],920:[0,.68333,.02778,.08334,.76278],923:[0,.68333,0,.16667,.69445],926:[0,.68333,.07569,.08334,.74236],928:[0,.68333,.08125,.05556,.83125],931:[0,.68333,.05764,.08334,.77986],933:[0,.68333,.13889,.05556,.58333],934:[0,.68333,0,.08334,.66667],936:[0,.68333,.11,.05556,.61222],937:[0,.68333,.05017,.08334,.7724],945:[0,.43056,.0037,.02778,.6397],946:[.19444,.69444,.05278,.08334,.56563],947:[.19444,.43056,.05556,0,.51773],948:[0,.69444,.03785,.05556,.44444],949:[0,.43056,0,.08334,.46632],950:[.19444,.69444,.07378,.08334,.4375],951:[.19444,.43056,.03588,.05556,.49653],952:[0,.69444,.02778,.08334,.46944],953:[0,.43056,0,.05556,.35394],954:[0,.43056,0,0,.57616],955:[0,.69444,0,0,.58334],956:[.19444,.43056,0,.02778,.60255],957:[0,.43056,.06366,.02778,.49398],958:[.19444,.69444,.04601,.11111,.4375],959:[0,.43056,0,.05556,.48472],960:[0,.43056,.03588,0,.57003],961:[.19444,.43056,0,.08334,.51702],962:[.09722,.43056,.07986,.08334,.36285],963:[0,.43056,.03588,0,.57141],964:[0,.43056,.1132,.02778,.43715],965:[0,.43056,.03588,.02778,.54028],966:[.19444,.43056,0,.08334,.65417],967:[.19444,.43056,0,.05556,.62569],968:[.19444,.69444,.03588,.11111,.65139],969:[0,.43056,.03588,0,.62245],977:[0,.69444,0,.08334,.59144],981:[.19444,.69444,0,.08334,.59583],982:[0,.43056,.02778,0,.82813],1009:[.19444,.43056,0,.08334,.51702],1013:[0,.43056,0,.05556,.4059],57649:[0,.43056,0,.02778,.32246],57911:[.19444,.43056,0,.08334,.38403]},"SansSerif-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.36667],34:[0,.69444,0,0,.55834],35:[.19444,.69444,0,0,.91667],36:[.05556,.75,0,0,.55],37:[.05556,.75,0,0,1.02912],38:[0,.69444,0,0,.83056],39:[0,.69444,0,0,.30556],40:[.25,.75,0,0,.42778],41:[.25,.75,0,0,.42778],42:[0,.75,0,0,.55],43:[.11667,.61667,0,0,.85556],44:[.10556,.13056,0,0,.30556],45:[0,.45833,0,0,.36667],46:[0,.13056,0,0,.30556],47:[.25,.75,0,0,.55],48:[0,.69444,0,0,.55],49:[0,.69444,0,0,.55],50:[0,.69444,0,0,.55],51:[0,.69444,0,0,.55],52:[0,.69444,0,0,.55],53:[0,.69444,0,0,.55],54:[0,.69444,0,0,.55],55:[0,.69444,0,0,.55],56:[0,.69444,0,0,.55],57:[0,.69444,0,0,.55],58:[0,.45833,0,0,.30556],59:[.10556,.45833,0,0,.30556],61:[-.09375,.40625,0,0,.85556],63:[0,.69444,0,0,.51945],64:[0,.69444,0,0,.73334],65:[0,.69444,0,0,.73334],66:[0,.69444,0,0,.73334],67:[0,.69444,0,0,.70278],68:[0,.69444,0,0,.79445],69:[0,.69444,0,0,.64167],70:[0,.69444,0,0,.61111],71:[0,.69444,0,0,.73334],72:[0,.69444,0,0,.79445],73:[0,.69444,0,0,.33056],74:[0,.69444,0,0,.51945],75:[0,.69444,0,0,.76389],76:[0,.69444,0,0,.58056],77:[0,.69444,0,0,.97778],78:[0,.69444,0,0,.79445],79:[0,.69444,0,0,.79445],80:[0,.69444,0,0,.70278],81:[.10556,.69444,0,0,.79445],82:[0,.69444,0,0,.70278],83:[0,.69444,0,0,.61111],84:[0,.69444,0,0,.73334],85:[0,.69444,0,0,.76389],86:[0,.69444,.01528,0,.73334],87:[0,.69444,.01528,0,1.03889],88:[0,.69444,0,0,.73334],89:[0,.69444,.0275,0,.73334],90:[0,.69444,0,0,.67223],91:[.25,.75,0,0,.34306],93:[.25,.75,0,0,.34306],94:[0,.69444,0,0,.55],95:[.35,.10833,.03056,0,.55],97:[0,.45833,0,0,.525],98:[0,.69444,0,0,.56111],99:[0,.45833,0,0,.48889],100:[0,.69444,0,0,.56111],101:[0,.45833,0,0,.51111],102:[0,.69444,.07639,0,.33611],103:[.19444,.45833,.01528,0,.55],104:[0,.69444,0,0,.56111],105:[0,.69444,0,0,.25556],106:[.19444,.69444,0,0,.28611],107:[0,.69444,0,0,.53056],108:[0,.69444,0,0,.25556],109:[0,.45833,0,0,.86667],110:[0,.45833,0,0,.56111],111:[0,.45833,0,0,.55],112:[.19444,.45833,0,0,.56111],113:[.19444,.45833,0,0,.56111],114:[0,.45833,.01528,0,.37222],115:[0,.45833,0,0,.42167],116:[0,.58929,0,0,.40417],117:[0,.45833,0,0,.56111],118:[0,.45833,.01528,0,.5],119:[0,.45833,.01528,0,.74445],120:[0,.45833,0,0,.5],121:[.19444,.45833,.01528,0,.5],122:[0,.45833,0,0,.47639],126:[.35,.34444,0,0,.55],160:[0,0,0,0,.25],168:[0,.69444,0,0,.55],176:[0,.69444,0,0,.73334],180:[0,.69444,0,0,.55],184:[.17014,0,0,0,.48889],305:[0,.45833,0,0,.25556],567:[.19444,.45833,0,0,.28611],710:[0,.69444,0,0,.55],711:[0,.63542,0,0,.55],713:[0,.63778,0,0,.55],728:[0,.69444,0,0,.55],729:[0,.69444,0,0,.30556],730:[0,.69444,0,0,.73334],732:[0,.69444,0,0,.55],733:[0,.69444,0,0,.55],915:[0,.69444,0,0,.58056],916:[0,.69444,0,0,.91667],920:[0,.69444,0,0,.85556],923:[0,.69444,0,0,.67223],926:[0,.69444,0,0,.73334],928:[0,.69444,0,0,.79445],931:[0,.69444,0,0,.79445],933:[0,.69444,0,0,.85556],934:[0,.69444,0,0,.79445],936:[0,.69444,0,0,.85556],937:[0,.69444,0,0,.79445],8211:[0,.45833,.03056,0,.55],8212:[0,.45833,.03056,0,1.10001],8216:[0,.69444,0,0,.30556],8217:[0,.69444,0,0,.30556],8220:[0,.69444,0,0,.55834],8221:[0,.69444,0,0,.55834]},"SansSerif-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.05733,0,.31945],34:[0,.69444,.00316,0,.5],35:[.19444,.69444,.05087,0,.83334],36:[.05556,.75,.11156,0,.5],37:[.05556,.75,.03126,0,.83334],38:[0,.69444,.03058,0,.75834],39:[0,.69444,.07816,0,.27778],40:[.25,.75,.13164,0,.38889],41:[.25,.75,.02536,0,.38889],42:[0,.75,.11775,0,.5],43:[.08333,.58333,.02536,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,.01946,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,.13164,0,.5],48:[0,.65556,.11156,0,.5],49:[0,.65556,.11156,0,.5],50:[0,.65556,.11156,0,.5],51:[0,.65556,.11156,0,.5],52:[0,.65556,.11156,0,.5],53:[0,.65556,.11156,0,.5],54:[0,.65556,.11156,0,.5],55:[0,.65556,.11156,0,.5],56:[0,.65556,.11156,0,.5],57:[0,.65556,.11156,0,.5],58:[0,.44444,.02502,0,.27778],59:[.125,.44444,.02502,0,.27778],61:[-.13,.37,.05087,0,.77778],63:[0,.69444,.11809,0,.47222],64:[0,.69444,.07555,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,.08293,0,.66667],67:[0,.69444,.11983,0,.63889],68:[0,.69444,.07555,0,.72223],69:[0,.69444,.11983,0,.59722],70:[0,.69444,.13372,0,.56945],71:[0,.69444,.11983,0,.66667],72:[0,.69444,.08094,0,.70834],73:[0,.69444,.13372,0,.27778],74:[0,.69444,.08094,0,.47222],75:[0,.69444,.11983,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,.08094,0,.875],78:[0,.69444,.08094,0,.70834],79:[0,.69444,.07555,0,.73611],80:[0,.69444,.08293,0,.63889],81:[.125,.69444,.07555,0,.73611],82:[0,.69444,.08293,0,.64584],83:[0,.69444,.09205,0,.55556],84:[0,.69444,.13372,0,.68056],85:[0,.69444,.08094,0,.6875],86:[0,.69444,.1615,0,.66667],87:[0,.69444,.1615,0,.94445],88:[0,.69444,.13372,0,.66667],89:[0,.69444,.17261,0,.66667],90:[0,.69444,.11983,0,.61111],91:[.25,.75,.15942,0,.28889],93:[.25,.75,.08719,0,.28889],94:[0,.69444,.0799,0,.5],95:[.35,.09444,.08616,0,.5],97:[0,.44444,.00981,0,.48056],98:[0,.69444,.03057,0,.51667],99:[0,.44444,.08336,0,.44445],100:[0,.69444,.09483,0,.51667],101:[0,.44444,.06778,0,.44445],102:[0,.69444,.21705,0,.30556],103:[.19444,.44444,.10836,0,.5],104:[0,.69444,.01778,0,.51667],105:[0,.67937,.09718,0,.23889],106:[.19444,.67937,.09162,0,.26667],107:[0,.69444,.08336,0,.48889],108:[0,.69444,.09483,0,.23889],109:[0,.44444,.01778,0,.79445],110:[0,.44444,.01778,0,.51667],111:[0,.44444,.06613,0,.5],112:[.19444,.44444,.0389,0,.51667],113:[.19444,.44444,.04169,0,.51667],114:[0,.44444,.10836,0,.34167],115:[0,.44444,.0778,0,.38333],116:[0,.57143,.07225,0,.36111],117:[0,.44444,.04169,0,.51667],118:[0,.44444,.10836,0,.46111],119:[0,.44444,.10836,0,.68334],120:[0,.44444,.09169,0,.46111],121:[.19444,.44444,.10836,0,.46111],122:[0,.44444,.08752,0,.43472],126:[.35,.32659,.08826,0,.5],160:[0,0,0,0,.25],168:[0,.67937,.06385,0,.5],176:[0,.69444,0,0,.73752],184:[.17014,0,0,0,.44445],305:[0,.44444,.04169,0,.23889],567:[.19444,.44444,.04169,0,.26667],710:[0,.69444,.0799,0,.5],711:[0,.63194,.08432,0,.5],713:[0,.60889,.08776,0,.5],714:[0,.69444,.09205,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,.09483,0,.5],729:[0,.67937,.07774,0,.27778],730:[0,.69444,0,0,.73752],732:[0,.67659,.08826,0,.5],733:[0,.69444,.09205,0,.5],915:[0,.69444,.13372,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,.07555,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,.12816,0,.66667],928:[0,.69444,.08094,0,.70834],931:[0,.69444,.11983,0,.72222],933:[0,.69444,.09031,0,.77778],934:[0,.69444,.04603,0,.72222],936:[0,.69444,.09031,0,.77778],937:[0,.69444,.08293,0,.72222],8211:[0,.44444,.08616,0,.5],8212:[0,.44444,.08616,0,1],8216:[0,.69444,.07816,0,.27778],8217:[0,.69444,.07816,0,.27778],8220:[0,.69444,.14205,0,.5],8221:[0,.69444,.00316,0,.5]},"SansSerif-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.31945],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.75834],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,0,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.65556,0,0,.5],49:[0,.65556,0,0,.5],50:[0,.65556,0,0,.5],51:[0,.65556,0,0,.5],52:[0,.65556,0,0,.5],53:[0,.65556,0,0,.5],54:[0,.65556,0,0,.5],55:[0,.65556,0,0,.5],56:[0,.65556,0,0,.5],57:[0,.65556,0,0,.5],58:[0,.44444,0,0,.27778],59:[.125,.44444,0,0,.27778],61:[-.13,.37,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,0,0,.66667],67:[0,.69444,0,0,.63889],68:[0,.69444,0,0,.72223],69:[0,.69444,0,0,.59722],70:[0,.69444,0,0,.56945],71:[0,.69444,0,0,.66667],72:[0,.69444,0,0,.70834],73:[0,.69444,0,0,.27778],74:[0,.69444,0,0,.47222],75:[0,.69444,0,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,0,0,.875],78:[0,.69444,0,0,.70834],79:[0,.69444,0,0,.73611],80:[0,.69444,0,0,.63889],81:[.125,.69444,0,0,.73611],82:[0,.69444,0,0,.64584],83:[0,.69444,0,0,.55556],84:[0,.69444,0,0,.68056],85:[0,.69444,0,0,.6875],86:[0,.69444,.01389,0,.66667],87:[0,.69444,.01389,0,.94445],88:[0,.69444,0,0,.66667],89:[0,.69444,.025,0,.66667],90:[0,.69444,0,0,.61111],91:[.25,.75,0,0,.28889],93:[.25,.75,0,0,.28889],94:[0,.69444,0,0,.5],95:[.35,.09444,.02778,0,.5],97:[0,.44444,0,0,.48056],98:[0,.69444,0,0,.51667],99:[0,.44444,0,0,.44445],100:[0,.69444,0,0,.51667],101:[0,.44444,0,0,.44445],102:[0,.69444,.06944,0,.30556],103:[.19444,.44444,.01389,0,.5],104:[0,.69444,0,0,.51667],105:[0,.67937,0,0,.23889],106:[.19444,.67937,0,0,.26667],107:[0,.69444,0,0,.48889],108:[0,.69444,0,0,.23889],109:[0,.44444,0,0,.79445],110:[0,.44444,0,0,.51667],111:[0,.44444,0,0,.5],112:[.19444,.44444,0,0,.51667],113:[.19444,.44444,0,0,.51667],114:[0,.44444,.01389,0,.34167],115:[0,.44444,0,0,.38333],116:[0,.57143,0,0,.36111],117:[0,.44444,0,0,.51667],118:[0,.44444,.01389,0,.46111],119:[0,.44444,.01389,0,.68334],120:[0,.44444,0,0,.46111],121:[.19444,.44444,.01389,0,.46111],122:[0,.44444,0,0,.43472],126:[.35,.32659,0,0,.5],160:[0,0,0,0,.25],168:[0,.67937,0,0,.5],176:[0,.69444,0,0,.66667],184:[.17014,0,0,0,.44445],305:[0,.44444,0,0,.23889],567:[.19444,.44444,0,0,.26667],710:[0,.69444,0,0,.5],711:[0,.63194,0,0,.5],713:[0,.60889,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.67937,0,0,.27778],730:[0,.69444,0,0,.66667],732:[0,.67659,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.69444,0,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,0,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,0,0,.66667],928:[0,.69444,0,0,.70834],931:[0,.69444,0,0,.72222],933:[0,.69444,0,0,.77778],934:[0,.69444,0,0,.72222],936:[0,.69444,0,0,.77778],937:[0,.69444,0,0,.72222],8211:[0,.44444,.02778,0,.5],8212:[0,.44444,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5]},"Script-Regular":{32:[0,0,0,0,.25],65:[0,.7,.22925,0,.80253],66:[0,.7,.04087,0,.90757],67:[0,.7,.1689,0,.66619],68:[0,.7,.09371,0,.77443],69:[0,.7,.18583,0,.56162],70:[0,.7,.13634,0,.89544],71:[0,.7,.17322,0,.60961],72:[0,.7,.29694,0,.96919],73:[0,.7,.19189,0,.80907],74:[.27778,.7,.19189,0,1.05159],75:[0,.7,.31259,0,.91364],76:[0,.7,.19189,0,.87373],77:[0,.7,.15981,0,1.08031],78:[0,.7,.3525,0,.9015],79:[0,.7,.08078,0,.73787],80:[0,.7,.08078,0,1.01262],81:[0,.7,.03305,0,.88282],82:[0,.7,.06259,0,.85],83:[0,.7,.19189,0,.86767],84:[0,.7,.29087,0,.74697],85:[0,.7,.25815,0,.79996],86:[0,.7,.27523,0,.62204],87:[0,.7,.27523,0,.80532],88:[0,.7,.26006,0,.94445],89:[0,.7,.2939,0,.70961],90:[0,.7,.24037,0,.8212],160:[0,0,0,0,.25]},"Size1-Regular":{32:[0,0,0,0,.25],40:[.35001,.85,0,0,.45834],41:[.35001,.85,0,0,.45834],47:[.35001,.85,0,0,.57778],91:[.35001,.85,0,0,.41667],92:[.35001,.85,0,0,.57778],93:[.35001,.85,0,0,.41667],123:[.35001,.85,0,0,.58334],125:[.35001,.85,0,0,.58334],160:[0,0,0,0,.25],710:[0,.72222,0,0,.55556],732:[0,.72222,0,0,.55556],770:[0,.72222,0,0,.55556],771:[0,.72222,0,0,.55556],8214:[-99e-5,.601,0,0,.77778],8593:[1e-5,.6,0,0,.66667],8595:[1e-5,.6,0,0,.66667],8657:[1e-5,.6,0,0,.77778],8659:[1e-5,.6,0,0,.77778],8719:[.25001,.75,0,0,.94445],8720:[.25001,.75,0,0,.94445],8721:[.25001,.75,0,0,1.05556],8730:[.35001,.85,0,0,1],8739:[-.00599,.606,0,0,.33333],8741:[-.00599,.606,0,0,.55556],8747:[.30612,.805,.19445,0,.47222],8748:[.306,.805,.19445,0,.47222],8749:[.306,.805,.19445,0,.47222],8750:[.30612,.805,.19445,0,.47222],8896:[.25001,.75,0,0,.83334],8897:[.25001,.75,0,0,.83334],8898:[.25001,.75,0,0,.83334],8899:[.25001,.75,0,0,.83334],8968:[.35001,.85,0,0,.47222],8969:[.35001,.85,0,0,.47222],8970:[.35001,.85,0,0,.47222],8971:[.35001,.85,0,0,.47222],9168:[-99e-5,.601,0,0,.66667],10216:[.35001,.85,0,0,.47222],10217:[.35001,.85,0,0,.47222],10752:[.25001,.75,0,0,1.11111],10753:[.25001,.75,0,0,1.11111],10754:[.25001,.75,0,0,1.11111],10756:[.25001,.75,0,0,.83334],10758:[.25001,.75,0,0,.83334]},"Size2-Regular":{32:[0,0,0,0,.25],40:[.65002,1.15,0,0,.59722],41:[.65002,1.15,0,0,.59722],47:[.65002,1.15,0,0,.81111],91:[.65002,1.15,0,0,.47222],92:[.65002,1.15,0,0,.81111],93:[.65002,1.15,0,0,.47222],123:[.65002,1.15,0,0,.66667],125:[.65002,1.15,0,0,.66667],160:[0,0,0,0,.25],710:[0,.75,0,0,1],732:[0,.75,0,0,1],770:[0,.75,0,0,1],771:[0,.75,0,0,1],8719:[.55001,1.05,0,0,1.27778],8720:[.55001,1.05,0,0,1.27778],8721:[.55001,1.05,0,0,1.44445],8730:[.65002,1.15,0,0,1],8747:[.86225,1.36,.44445,0,.55556],8748:[.862,1.36,.44445,0,.55556],8749:[.862,1.36,.44445,0,.55556],8750:[.86225,1.36,.44445,0,.55556],8896:[.55001,1.05,0,0,1.11111],8897:[.55001,1.05,0,0,1.11111],8898:[.55001,1.05,0,0,1.11111],8899:[.55001,1.05,0,0,1.11111],8968:[.65002,1.15,0,0,.52778],8969:[.65002,1.15,0,0,.52778],8970:[.65002,1.15,0,0,.52778],8971:[.65002,1.15,0,0,.52778],10216:[.65002,1.15,0,0,.61111],10217:[.65002,1.15,0,0,.61111],10752:[.55001,1.05,0,0,1.51112],10753:[.55001,1.05,0,0,1.51112],10754:[.55001,1.05,0,0,1.51112],10756:[.55001,1.05,0,0,1.11111],10758:[.55001,1.05,0,0,1.11111]},"Size3-Regular":{32:[0,0,0,0,.25],40:[.95003,1.45,0,0,.73611],41:[.95003,1.45,0,0,.73611],47:[.95003,1.45,0,0,1.04445],91:[.95003,1.45,0,0,.52778],92:[.95003,1.45,0,0,1.04445],93:[.95003,1.45,0,0,.52778],123:[.95003,1.45,0,0,.75],125:[.95003,1.45,0,0,.75],160:[0,0,0,0,.25],710:[0,.75,0,0,1.44445],732:[0,.75,0,0,1.44445],770:[0,.75,0,0,1.44445],771:[0,.75,0,0,1.44445],8730:[.95003,1.45,0,0,1],8968:[.95003,1.45,0,0,.58334],8969:[.95003,1.45,0,0,.58334],8970:[.95003,1.45,0,0,.58334],8971:[.95003,1.45,0,0,.58334],10216:[.95003,1.45,0,0,.75],10217:[.95003,1.45,0,0,.75]},"Size4-Regular":{32:[0,0,0,0,.25],40:[1.25003,1.75,0,0,.79167],41:[1.25003,1.75,0,0,.79167],47:[1.25003,1.75,0,0,1.27778],91:[1.25003,1.75,0,0,.58334],92:[1.25003,1.75,0,0,1.27778],93:[1.25003,1.75,0,0,.58334],123:[1.25003,1.75,0,0,.80556],125:[1.25003,1.75,0,0,.80556],160:[0,0,0,0,.25],710:[0,.825,0,0,1.8889],732:[0,.825,0,0,1.8889],770:[0,.825,0,0,1.8889],771:[0,.825,0,0,1.8889],8730:[1.25003,1.75,0,0,1],8968:[1.25003,1.75,0,0,.63889],8969:[1.25003,1.75,0,0,.63889],8970:[1.25003,1.75,0,0,.63889],8971:[1.25003,1.75,0,0,.63889],9115:[.64502,1.155,0,0,.875],9116:[1e-5,.6,0,0,.875],9117:[.64502,1.155,0,0,.875],9118:[.64502,1.155,0,0,.875],9119:[1e-5,.6,0,0,.875],9120:[.64502,1.155,0,0,.875],9121:[.64502,1.155,0,0,.66667],9122:[-99e-5,.601,0,0,.66667],9123:[.64502,1.155,0,0,.66667],9124:[.64502,1.155,0,0,.66667],9125:[-99e-5,.601,0,0,.66667],9126:[.64502,1.155,0,0,.66667],9127:[1e-5,.9,0,0,.88889],9128:[.65002,1.15,0,0,.88889],9129:[.90001,0,0,0,.88889],9130:[0,.3,0,0,.88889],9131:[1e-5,.9,0,0,.88889],9132:[.65002,1.15,0,0,.88889],9133:[.90001,0,0,0,.88889],9143:[.88502,.915,0,0,1.05556],10216:[1.25003,1.75,0,0,.80556],10217:[1.25003,1.75,0,0,.80556],57344:[-.00499,.605,0,0,1.05556],57345:[-.00499,.605,0,0,1.05556],57680:[0,.12,0,0,.45],57681:[0,.12,0,0,.45],57682:[0,.12,0,0,.45],57683:[0,.12,0,0,.45]},"Typewriter-Regular":{32:[0,0,0,0,.525],33:[0,.61111,0,0,.525],34:[0,.61111,0,0,.525],35:[0,.61111,0,0,.525],36:[.08333,.69444,0,0,.525],37:[.08333,.69444,0,0,.525],38:[0,.61111,0,0,.525],39:[0,.61111,0,0,.525],40:[.08333,.69444,0,0,.525],41:[.08333,.69444,0,0,.525],42:[0,.52083,0,0,.525],43:[-.08056,.53055,0,0,.525],44:[.13889,.125,0,0,.525],45:[-.08056,.53055,0,0,.525],46:[0,.125,0,0,.525],47:[.08333,.69444,0,0,.525],48:[0,.61111,0,0,.525],49:[0,.61111,0,0,.525],50:[0,.61111,0,0,.525],51:[0,.61111,0,0,.525],52:[0,.61111,0,0,.525],53:[0,.61111,0,0,.525],54:[0,.61111,0,0,.525],55:[0,.61111,0,0,.525],56:[0,.61111,0,0,.525],57:[0,.61111,0,0,.525],58:[0,.43056,0,0,.525],59:[.13889,.43056,0,0,.525],60:[-.05556,.55556,0,0,.525],61:[-.19549,.41562,0,0,.525],62:[-.05556,.55556,0,0,.525],63:[0,.61111,0,0,.525],64:[0,.61111,0,0,.525],65:[0,.61111,0,0,.525],66:[0,.61111,0,0,.525],67:[0,.61111,0,0,.525],68:[0,.61111,0,0,.525],69:[0,.61111,0,0,.525],70:[0,.61111,0,0,.525],71:[0,.61111,0,0,.525],72:[0,.61111,0,0,.525],73:[0,.61111,0,0,.525],74:[0,.61111,0,0,.525],75:[0,.61111,0,0,.525],76:[0,.61111,0,0,.525],77:[0,.61111,0,0,.525],78:[0,.61111,0,0,.525],79:[0,.61111,0,0,.525],80:[0,.61111,0,0,.525],81:[.13889,.61111,0,0,.525],82:[0,.61111,0,0,.525],83:[0,.61111,0,0,.525],84:[0,.61111,0,0,.525],85:[0,.61111,0,0,.525],86:[0,.61111,0,0,.525],87:[0,.61111,0,0,.525],88:[0,.61111,0,0,.525],89:[0,.61111,0,0,.525],90:[0,.61111,0,0,.525],91:[.08333,.69444,0,0,.525],92:[.08333,.69444,0,0,.525],93:[.08333,.69444,0,0,.525],94:[0,.61111,0,0,.525],95:[.09514,0,0,0,.525],96:[0,.61111,0,0,.525],97:[0,.43056,0,0,.525],98:[0,.61111,0,0,.525],99:[0,.43056,0,0,.525],100:[0,.61111,0,0,.525],101:[0,.43056,0,0,.525],102:[0,.61111,0,0,.525],103:[.22222,.43056,0,0,.525],104:[0,.61111,0,0,.525],105:[0,.61111,0,0,.525],106:[.22222,.61111,0,0,.525],107:[0,.61111,0,0,.525],108:[0,.61111,0,0,.525],109:[0,.43056,0,0,.525],110:[0,.43056,0,0,.525],111:[0,.43056,0,0,.525],112:[.22222,.43056,0,0,.525],113:[.22222,.43056,0,0,.525],114:[0,.43056,0,0,.525],115:[0,.43056,0,0,.525],116:[0,.55358,0,0,.525],117:[0,.43056,0,0,.525],118:[0,.43056,0,0,.525],119:[0,.43056,0,0,.525],120:[0,.43056,0,0,.525],121:[.22222,.43056,0,0,.525],122:[0,.43056,0,0,.525],123:[.08333,.69444,0,0,.525],124:[.08333,.69444,0,0,.525],125:[.08333,.69444,0,0,.525],126:[0,.61111,0,0,.525],127:[0,.61111,0,0,.525],160:[0,0,0,0,.525],176:[0,.61111,0,0,.525],184:[.19445,0,0,0,.525],305:[0,.43056,0,0,.525],567:[.22222,.43056,0,0,.525],711:[0,.56597,0,0,.525],713:[0,.56555,0,0,.525],714:[0,.61111,0,0,.525],715:[0,.61111,0,0,.525],728:[0,.61111,0,0,.525],730:[0,.61111,0,0,.525],770:[0,.61111,0,0,.525],771:[0,.61111,0,0,.525],776:[0,.61111,0,0,.525],915:[0,.61111,0,0,.525],916:[0,.61111,0,0,.525],920:[0,.61111,0,0,.525],923:[0,.61111,0,0,.525],926:[0,.61111,0,0,.525],928:[0,.61111,0,0,.525],931:[0,.61111,0,0,.525],933:[0,.61111,0,0,.525],934:[0,.61111,0,0,.525],936:[0,.61111,0,0,.525],937:[0,.61111,0,0,.525],8216:[0,.61111,0,0,.525],8217:[0,.61111,0,0,.525],8242:[0,.61111,0,0,.525],9251:[.11111,.21944,0,0,.525]}},QU={slant:[.25,.25,.25],space:[0,0,0],stretch:[0,0,0],shrink:[0,0,0],xHeight:[.431,.431,.431],quad:[1,1.171,1.472],extraSpace:[0,0,0],num1:[.677,.732,.925],num2:[.394,.384,.387],num3:[.444,.471,.504],denom1:[.686,.752,1.025],denom2:[.345,.344,.532],sup1:[.413,.503,.504],sup2:[.363,.431,.404],sup3:[.289,.286,.294],sub1:[.15,.143,.2],sub2:[.247,.286,.4],supDrop:[.386,.353,.494],subDrop:[.05,.071,.1],delim1:[2.39,1.7,1.98],delim2:[1.01,1.157,1.42],axisHeight:[.25,.25,.25],defaultRuleThickness:[.04,.049,.049],bigOpSpacing1:[.111,.111,.111],bigOpSpacing2:[.166,.166,.166],bigOpSpacing3:[.2,.2,.2],bigOpSpacing4:[.6,.611,.611],bigOpSpacing5:[.1,.143,.143],sqrtRuleThickness:[.04,.04,.04],ptPerEm:[10,10,10],doubleRuleSep:[.2,.2,.2],arrayRuleWidth:[.04,.04,.04],fboxsep:[.3,.3,.3],fboxrule:[.04,.04,.04]},$U={Å:`A`,Ð:`D`,Þ:`o`,å:`a`,ð:`d`,þ:`o`,А:`A`,Б:`B`,В:`B`,Г:`F`,Д:`A`,Е:`E`,Ж:`K`,З:`3`,И:`N`,Й:`N`,К:`K`,Л:`N`,М:`M`,Н:`H`,О:`O`,П:`N`,Р:`P`,С:`C`,Т:`T`,У:`y`,Ф:`O`,Х:`X`,Ц:`U`,Ч:`h`,Ш:`W`,Щ:`W`,Ъ:`B`,Ы:`X`,Ь:`B`,Э:`3`,Ю:`X`,Я:`R`,а:`a`,б:`b`,в:`a`,г:`r`,д:`y`,е:`e`,ж:`m`,з:`e`,и:`n`,й:`n`,к:`n`,л:`n`,м:`m`,н:`n`,о:`o`,п:`n`,р:`p`,с:`c`,т:`o`,у:`y`,ф:`b`,х:`x`,ц:`n`,ч:`n`,ш:`w`,щ:`w`,ъ:`a`,ы:`m`,ь:`a`,э:`e`,ю:`m`,я:`r`};function eW(e,t){ZU[e]=t}function tW(e,t,n){if(!ZU[t])throw Error(`Font metrics not found for font: `+t+`.`);var r=e.charCodeAt(0),i=ZU[t][r];if(!i&&e[0]in $U&&(r=$U[e[0]].charCodeAt(0),i=ZU[t][r]),!i&&n===`text`&&mU(r)&&(i=ZU[t][77]),i)return{depth:i[0],height:i[1],italic:i[2],skew:i[3],width:i[4]}}var nW={};function rW(e){var t=e>=5?0:e>=3?1:2;if(!nW[t]){var n=nW[t]={cssEmPerMu:QU.quad[t]/18};for(var r of Object.keys(QU))n[r]=QU[r][t]}return nW[t]}var iW={math:{},text:{}};function B(e,t,n,r,i,a){iW[e][i]={font:t,group:n,replace:r},a&&r&&(iW[e][r]=iW[e][i])}var V=`math`,H=`text`,U=`main`,W=`ams`,aW=`accent-token`,G=`bin`,oW=`close`,sW=`inner`,K=`mathord`,cW=`op-token`,lW=`open`,uW=`punct`,q=`rel`,dW=`spacing`,J=`textord`;B(V,U,q,`≡`,`\\equiv`,!0),B(V,U,q,`≺`,`\\prec`,!0),B(V,U,q,`≻`,`\\succ`,!0),B(V,U,q,`∼`,`\\sim`,!0),B(V,U,q,`⊥`,`\\perp`),B(V,U,q,`⪯`,`\\preceq`,!0),B(V,U,q,`⪰`,`\\succeq`,!0),B(V,U,q,`≃`,`\\simeq`,!0),B(V,U,q,`∣`,`\\mid`,!0),B(V,U,q,`≪`,`\\ll`,!0),B(V,U,q,`≫`,`\\gg`,!0),B(V,U,q,`≍`,`\\asymp`,!0),B(V,U,q,`∥`,`\\parallel`),B(V,U,q,`⋈`,`\\bowtie`,!0),B(V,U,q,`⌣`,`\\smile`,!0),B(V,U,q,`⊑`,`\\sqsubseteq`,!0),B(V,U,q,`⊒`,`\\sqsupseteq`,!0),B(V,U,q,`≐`,`\\doteq`,!0),B(V,U,q,`⌢`,`\\frown`,!0),B(V,U,q,`∋`,`\\ni`,!0),B(V,U,q,`∝`,`\\propto`,!0),B(V,U,q,`⊢`,`\\vdash`,!0),B(V,U,q,`⊣`,`\\dashv`,!0),B(V,U,q,`∋`,`\\owns`),B(V,U,uW,`.`,`\\ldotp`),B(V,U,uW,`⋅`,`\\cdotp`),B(V,U,uW,`⋅`,`·`),B(H,U,J,`⋅`,`·`),B(V,U,J,`#`,`\\#`),B(H,U,J,`#`,`\\#`),B(V,U,J,`&`,`\\&`),B(H,U,J,`&`,`\\&`),B(V,U,J,`ℵ`,`\\aleph`,!0),B(V,U,J,`∀`,`\\forall`,!0),B(V,U,J,`ℏ`,`\\hbar`,!0),B(V,U,J,`∃`,`\\exists`,!0),B(V,U,J,`∇`,`\\nabla`,!0),B(V,U,J,`♭`,`\\flat`,!0),B(V,U,J,`ℓ`,`\\ell`,!0),B(V,U,J,`♮`,`\\natural`,!0),B(V,U,J,`♣`,`\\clubsuit`,!0),B(V,U,J,`℘`,`\\wp`,!0),B(V,U,J,`♯`,`\\sharp`,!0),B(V,U,J,`♢`,`\\diamondsuit`,!0),B(V,U,J,`ℜ`,`\\Re`,!0),B(V,U,J,`♡`,`\\heartsuit`,!0),B(V,U,J,`ℑ`,`\\Im`,!0),B(V,U,J,`♠`,`\\spadesuit`,!0),B(V,U,J,`§`,`\\S`,!0),B(H,U,J,`§`,`\\S`),B(V,U,J,`¶`,`\\P`,!0),B(H,U,J,`¶`,`\\P`),B(V,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\textdagger`),B(V,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\textdaggerdbl`),B(V,U,oW,`⎱`,`\\rmoustache`,!0),B(V,U,lW,`⎰`,`\\lmoustache`,!0),B(V,U,oW,`⟯`,`\\rgroup`,!0),B(V,U,lW,`⟮`,`\\lgroup`,!0),B(V,U,G,`∓`,`\\mp`,!0),B(V,U,G,`⊖`,`\\ominus`,!0),B(V,U,G,`⊎`,`\\uplus`,!0),B(V,U,G,`⊓`,`\\sqcap`,!0),B(V,U,G,`∗`,`\\ast`),B(V,U,G,`⊔`,`\\sqcup`,!0),B(V,U,G,`◯`,`\\bigcirc`,!0),B(V,U,G,`∙`,`\\bullet`,!0),B(V,U,G,`‡`,`\\ddagger`),B(V,U,G,`≀`,`\\wr`,!0),B(V,U,G,`⨿`,`\\amalg`),B(V,U,G,`&`,`\\And`),B(V,U,q,`⟵`,`\\longleftarrow`,!0),B(V,U,q,`⇐`,`\\Leftarrow`,!0),B(V,U,q,`⟸`,`\\Longleftarrow`,!0),B(V,U,q,`⟶`,`\\longrightarrow`,!0),B(V,U,q,`⇒`,`\\Rightarrow`,!0),B(V,U,q,`⟹`,`\\Longrightarrow`,!0),B(V,U,q,`↔`,`\\leftrightarrow`,!0),B(V,U,q,`⟷`,`\\longleftrightarrow`,!0),B(V,U,q,`⇔`,`\\Leftrightarrow`,!0),B(V,U,q,`⟺`,`\\Longleftrightarrow`,!0),B(V,U,q,`↦`,`\\mapsto`,!0),B(V,U,q,`⟼`,`\\longmapsto`,!0),B(V,U,q,`↗`,`\\nearrow`,!0),B(V,U,q,`↩`,`\\hookleftarrow`,!0),B(V,U,q,`↪`,`\\hookrightarrow`,!0),B(V,U,q,`↘`,`\\searrow`,!0),B(V,U,q,`↼`,`\\leftharpoonup`,!0),B(V,U,q,`⇀`,`\\rightharpoonup`,!0),B(V,U,q,`↙`,`\\swarrow`,!0),B(V,U,q,`↽`,`\\leftharpoondown`,!0),B(V,U,q,`⇁`,`\\rightharpoondown`,!0),B(V,U,q,`↖`,`\\nwarrow`,!0),B(V,U,q,`⇌`,`\\rightleftharpoons`,!0),B(V,W,q,`≮`,`\\nless`,!0),B(V,W,q,``,`\\@nleqslant`),B(V,W,q,``,`\\@nleqq`),B(V,W,q,`⪇`,`\\lneq`,!0),B(V,W,q,`≨`,`\\lneqq`,!0),B(V,W,q,``,`\\@lvertneqq`),B(V,W,q,`⋦`,`\\lnsim`,!0),B(V,W,q,`⪉`,`\\lnapprox`,!0),B(V,W,q,`⊀`,`\\nprec`,!0),B(V,W,q,`⋠`,`\\npreceq`,!0),B(V,W,q,`⋨`,`\\precnsim`,!0),B(V,W,q,`⪹`,`\\precnapprox`,!0),B(V,W,q,`≁`,`\\nsim`,!0),B(V,W,q,``,`\\@nshortmid`),B(V,W,q,`∤`,`\\nmid`,!0),B(V,W,q,`⊬`,`\\nvdash`,!0),B(V,W,q,`⊭`,`\\nvDash`,!0),B(V,W,q,`⋪`,`\\ntriangleleft`),B(V,W,q,`⋬`,`\\ntrianglelefteq`,!0),B(V,W,q,`⊊`,`\\subsetneq`,!0),B(V,W,q,``,`\\@varsubsetneq`),B(V,W,q,`⫋`,`\\subsetneqq`,!0),B(V,W,q,``,`\\@varsubsetneqq`),B(V,W,q,`≯`,`\\ngtr`,!0),B(V,W,q,``,`\\@ngeqslant`),B(V,W,q,``,`\\@ngeqq`),B(V,W,q,`⪈`,`\\gneq`,!0),B(V,W,q,`≩`,`\\gneqq`,!0),B(V,W,q,``,`\\@gvertneqq`),B(V,W,q,`⋧`,`\\gnsim`,!0),B(V,W,q,`⪊`,`\\gnapprox`,!0),B(V,W,q,`⊁`,`\\nsucc`,!0),B(V,W,q,`⋡`,`\\nsucceq`,!0),B(V,W,q,`⋩`,`\\succnsim`,!0),B(V,W,q,`⪺`,`\\succnapprox`,!0),B(V,W,q,`≆`,`\\ncong`,!0),B(V,W,q,``,`\\@nshortparallel`),B(V,W,q,`∦`,`\\nparallel`,!0),B(V,W,q,`⊯`,`\\nVDash`,!0),B(V,W,q,`⋫`,`\\ntriangleright`),B(V,W,q,`⋭`,`\\ntrianglerighteq`,!0),B(V,W,q,``,`\\@nsupseteqq`),B(V,W,q,`⊋`,`\\supsetneq`,!0),B(V,W,q,``,`\\@varsupsetneq`),B(V,W,q,`⫌`,`\\supsetneqq`,!0),B(V,W,q,``,`\\@varsupsetneqq`),B(V,W,q,`⊮`,`\\nVdash`,!0),B(V,W,q,`⪵`,`\\precneqq`,!0),B(V,W,q,`⪶`,`\\succneqq`,!0),B(V,W,q,``,`\\@nsubseteqq`),B(V,W,G,`⊴`,`\\unlhd`),B(V,W,G,`⊵`,`\\unrhd`),B(V,W,q,`↚`,`\\nleftarrow`,!0),B(V,W,q,`↛`,`\\nrightarrow`,!0),B(V,W,q,`⇍`,`\\nLeftarrow`,!0),B(V,W,q,`⇏`,`\\nRightarrow`,!0),B(V,W,q,`↮`,`\\nleftrightarrow`,!0),B(V,W,q,`⇎`,`\\nLeftrightarrow`,!0),B(V,W,q,`△`,`\\vartriangle`),B(V,W,J,`ℏ`,`\\hslash`),B(V,W,J,`▽`,`\\triangledown`),B(V,W,J,`◊`,`\\lozenge`),B(V,W,J,`Ⓢ`,`\\circledS`),B(V,W,J,`®`,`\\circledR`),B(H,W,J,`®`,`\\circledR`),B(V,W,J,`∡`,`\\measuredangle`,!0),B(V,W,J,`∄`,`\\nexists`),B(V,W,J,`℧`,`\\mho`),B(V,W,J,`Ⅎ`,`\\Finv`,!0),B(V,W,J,`⅁`,`\\Game`,!0),B(V,W,J,`‵`,`\\backprime`),B(V,W,J,`▲`,`\\blacktriangle`),B(V,W,J,`▼`,`\\blacktriangledown`),B(V,W,J,`■`,`\\blacksquare`),B(V,W,J,`⧫`,`\\blacklozenge`),B(V,W,J,`★`,`\\bigstar`),B(V,W,J,`∢`,`\\sphericalangle`,!0),B(V,W,J,`∁`,`\\complement`,!0),B(V,W,J,`ð`,`\\eth`,!0),B(H,U,J,`ð`,`ð`),B(V,W,J,`╱`,`\\diagup`),B(V,W,J,`╲`,`\\diagdown`),B(V,W,J,`□`,`\\square`),B(V,W,J,`□`,`\\Box`),B(V,W,J,`◊`,`\\Diamond`),B(V,W,J,`¥`,`\\yen`,!0),B(H,W,J,`¥`,`\\yen`,!0),B(V,W,J,`✓`,`\\checkmark`,!0),B(H,W,J,`✓`,`\\checkmark`),B(V,W,J,`ℶ`,`\\beth`,!0),B(V,W,J,`ℸ`,`\\daleth`,!0),B(V,W,J,`ℷ`,`\\gimel`,!0),B(V,W,J,`ϝ`,`\\digamma`,!0),B(V,W,J,`ϰ`,`\\varkappa`),B(V,W,lW,`┌`,`\\@ulcorner`,!0),B(V,W,oW,`┐`,`\\@urcorner`,!0),B(V,W,lW,`└`,`\\@llcorner`,!0),B(V,W,oW,`┘`,`\\@lrcorner`,!0),B(V,W,q,`≦`,`\\leqq`,!0),B(V,W,q,`⩽`,`\\leqslant`,!0),B(V,W,q,`⪕`,`\\eqslantless`,!0),B(V,W,q,`≲`,`\\lesssim`,!0),B(V,W,q,`⪅`,`\\lessapprox`,!0),B(V,W,q,`≊`,`\\approxeq`,!0),B(V,W,G,`⋖`,`\\lessdot`),B(V,W,q,`⋘`,`\\lll`,!0),B(V,W,q,`≶`,`\\lessgtr`,!0),B(V,W,q,`⋚`,`\\lesseqgtr`,!0),B(V,W,q,`⪋`,`\\lesseqqgtr`,!0),B(V,W,q,`≑`,`\\doteqdot`),B(V,W,q,`≓`,`\\risingdotseq`,!0),B(V,W,q,`≒`,`\\fallingdotseq`,!0),B(V,W,q,`∽`,`\\backsim`,!0),B(V,W,q,`⋍`,`\\backsimeq`,!0),B(V,W,q,`⫅`,`\\subseteqq`,!0),B(V,W,q,`⋐`,`\\Subset`,!0),B(V,W,q,`⊏`,`\\sqsubset`,!0),B(V,W,q,`≼`,`\\preccurlyeq`,!0),B(V,W,q,`⋞`,`\\curlyeqprec`,!0),B(V,W,q,`≾`,`\\precsim`,!0),B(V,W,q,`⪷`,`\\precapprox`,!0),B(V,W,q,`⊲`,`\\vartriangleleft`),B(V,W,q,`⊴`,`\\trianglelefteq`),B(V,W,q,`⊨`,`\\vDash`,!0),B(V,W,q,`⊪`,`\\Vvdash`,!0),B(V,W,q,`⌣`,`\\smallsmile`),B(V,W,q,`⌢`,`\\smallfrown`),B(V,W,q,`≏`,`\\bumpeq`,!0),B(V,W,q,`≎`,`\\Bumpeq`,!0),B(V,W,q,`≧`,`\\geqq`,!0),B(V,W,q,`⩾`,`\\geqslant`,!0),B(V,W,q,`⪖`,`\\eqslantgtr`,!0),B(V,W,q,`≳`,`\\gtrsim`,!0),B(V,W,q,`⪆`,`\\gtrapprox`,!0),B(V,W,G,`⋗`,`\\gtrdot`),B(V,W,q,`⋙`,`\\ggg`,!0),B(V,W,q,`≷`,`\\gtrless`,!0),B(V,W,q,`⋛`,`\\gtreqless`,!0),B(V,W,q,`⪌`,`\\gtreqqless`,!0),B(V,W,q,`≖`,`\\eqcirc`,!0),B(V,W,q,`≗`,`\\circeq`,!0),B(V,W,q,`≜`,`\\triangleq`,!0),B(V,W,q,`∼`,`\\thicksim`),B(V,W,q,`≈`,`\\thickapprox`),B(V,W,q,`⫆`,`\\supseteqq`,!0),B(V,W,q,`⋑`,`\\Supset`,!0),B(V,W,q,`⊐`,`\\sqsupset`,!0),B(V,W,q,`≽`,`\\succcurlyeq`,!0),B(V,W,q,`⋟`,`\\curlyeqsucc`,!0),B(V,W,q,`≿`,`\\succsim`,!0),B(V,W,q,`⪸`,`\\succapprox`,!0),B(V,W,q,`⊳`,`\\vartriangleright`),B(V,W,q,`⊵`,`\\trianglerighteq`),B(V,W,q,`⊩`,`\\Vdash`,!0),B(V,W,q,`∣`,`\\shortmid`),B(V,W,q,`∥`,`\\shortparallel`),B(V,W,q,`≬`,`\\between`,!0),B(V,W,q,`⋔`,`\\pitchfork`,!0),B(V,W,q,`∝`,`\\varpropto`),B(V,W,q,`◀`,`\\blacktriangleleft`),B(V,W,q,`∴`,`\\therefore`,!0),B(V,W,q,`∍`,`\\backepsilon`),B(V,W,q,`▶`,`\\blacktriangleright`),B(V,W,q,`∵`,`\\because`,!0),B(V,W,q,`⋘`,`\\llless`),B(V,W,q,`⋙`,`\\gggtr`),B(V,W,G,`⊲`,`\\lhd`),B(V,W,G,`⊳`,`\\rhd`),B(V,W,q,`≂`,`\\eqsim`,!0),B(V,U,q,`⋈`,`\\Join`),B(V,W,q,`≑`,`\\Doteq`,!0),B(V,W,G,`∔`,`\\dotplus`,!0),B(V,W,G,`∖`,`\\smallsetminus`),B(V,W,G,`⋒`,`\\Cap`,!0),B(V,W,G,`⋓`,`\\Cup`,!0),B(V,W,G,`⩞`,`\\doublebarwedge`,!0),B(V,W,G,`⊟`,`\\boxminus`,!0),B(V,W,G,`⊞`,`\\boxplus`,!0),B(V,W,G,`⋇`,`\\divideontimes`,!0),B(V,W,G,`⋉`,`\\ltimes`,!0),B(V,W,G,`⋊`,`\\rtimes`,!0),B(V,W,G,`⋋`,`\\leftthreetimes`,!0),B(V,W,G,`⋌`,`\\rightthreetimes`,!0),B(V,W,G,`⋏`,`\\curlywedge`,!0),B(V,W,G,`⋎`,`\\curlyvee`,!0),B(V,W,G,`⊝`,`\\circleddash`,!0),B(V,W,G,`⊛`,`\\circledast`,!0),B(V,W,G,`⋅`,`\\centerdot`),B(V,W,G,`⊺`,`\\intercal`,!0),B(V,W,G,`⋒`,`\\doublecap`),B(V,W,G,`⋓`,`\\doublecup`),B(V,W,G,`⊠`,`\\boxtimes`,!0),B(V,W,q,`⇢`,`\\dashrightarrow`,!0),B(V,W,q,`⇠`,`\\dashleftarrow`,!0),B(V,W,q,`⇇`,`\\leftleftarrows`,!0),B(V,W,q,`⇆`,`\\leftrightarrows`,!0),B(V,W,q,`⇚`,`\\Lleftarrow`,!0),B(V,W,q,`↞`,`\\twoheadleftarrow`,!0),B(V,W,q,`↢`,`\\leftarrowtail`,!0),B(V,W,q,`↫`,`\\looparrowleft`,!0),B(V,W,q,`⇋`,`\\leftrightharpoons`,!0),B(V,W,q,`↶`,`\\curvearrowleft`,!0),B(V,W,q,`↺`,`\\circlearrowleft`,!0),B(V,W,q,`↰`,`\\Lsh`,!0),B(V,W,q,`⇈`,`\\upuparrows`,!0),B(V,W,q,`↿`,`\\upharpoonleft`,!0),B(V,W,q,`⇃`,`\\downharpoonleft`,!0),B(V,U,q,`⊶`,`\\origof`,!0),B(V,U,q,`⊷`,`\\imageof`,!0),B(V,W,q,`⊸`,`\\multimap`,!0),B(V,W,q,`↭`,`\\leftrightsquigarrow`,!0),B(V,W,q,`⇉`,`\\rightrightarrows`,!0),B(V,W,q,`⇄`,`\\rightleftarrows`,!0),B(V,W,q,`↠`,`\\twoheadrightarrow`,!0),B(V,W,q,`↣`,`\\rightarrowtail`,!0),B(V,W,q,`↬`,`\\looparrowright`,!0),B(V,W,q,`↷`,`\\curvearrowright`,!0),B(V,W,q,`↻`,`\\circlearrowright`,!0),B(V,W,q,`↱`,`\\Rsh`,!0),B(V,W,q,`⇊`,`\\downdownarrows`,!0),B(V,W,q,`↾`,`\\upharpoonright`,!0),B(V,W,q,`⇂`,`\\downharpoonright`,!0),B(V,W,q,`⇝`,`\\rightsquigarrow`,!0),B(V,W,q,`⇝`,`\\leadsto`),B(V,W,q,`⇛`,`\\Rrightarrow`,!0),B(V,W,q,`↾`,`\\restriction`),B(V,U,J,`‘`,"`"),B(V,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\textdollar`),B(V,U,J,`%`,`\\%`),B(H,U,J,`%`,`\\%`),B(V,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\textunderscore`),B(V,U,J,`∠`,`\\angle`,!0),B(V,U,J,`∞`,`\\infty`,!0),B(V,U,J,`′`,`\\prime`),B(V,U,J,`△`,`\\triangle`),B(V,U,J,`Γ`,`\\Gamma`,!0),B(V,U,J,`Δ`,`\\Delta`,!0),B(V,U,J,`Θ`,`\\Theta`,!0),B(V,U,J,`Λ`,`\\Lambda`,!0),B(V,U,J,`Ξ`,`\\Xi`,!0),B(V,U,J,`Π`,`\\Pi`,!0),B(V,U,J,`Σ`,`\\Sigma`,!0),B(V,U,J,`Υ`,`\\Upsilon`,!0),B(V,U,J,`Φ`,`\\Phi`,!0),B(V,U,J,`Ψ`,`\\Psi`,!0),B(V,U,J,`Ω`,`\\Omega`,!0),B(V,U,J,`A`,`Α`),B(V,U,J,`B`,`Β`),B(V,U,J,`E`,`Ε`),B(V,U,J,`Z`,`Ζ`),B(V,U,J,`H`,`Η`),B(V,U,J,`I`,`Ι`),B(V,U,J,`K`,`Κ`),B(V,U,J,`M`,`Μ`),B(V,U,J,`N`,`Ν`),B(V,U,J,`O`,`Ο`),B(V,U,J,`P`,`Ρ`),B(V,U,J,`T`,`Τ`),B(V,U,J,`X`,`Χ`),B(V,U,J,`¬`,`\\neg`,!0),B(V,U,J,`¬`,`\\lnot`),B(V,U,J,`⊤`,`\\top`),B(V,U,J,`⊥`,`\\bot`),B(V,U,J,`∅`,`\\emptyset`),B(V,W,J,`∅`,`\\varnothing`),B(V,U,K,`α`,`\\alpha`,!0),B(V,U,K,`β`,`\\beta`,!0),B(V,U,K,`γ`,`\\gamma`,!0),B(V,U,K,`δ`,`\\delta`,!0),B(V,U,K,`ϵ`,`\\epsilon`,!0),B(V,U,K,`ζ`,`\\zeta`,!0),B(V,U,K,`η`,`\\eta`,!0),B(V,U,K,`θ`,`\\theta`,!0),B(V,U,K,`ι`,`\\iota`,!0),B(V,U,K,`κ`,`\\kappa`,!0),B(V,U,K,`λ`,`\\lambda`,!0),B(V,U,K,`μ`,`\\mu`,!0),B(V,U,K,`ν`,`\\nu`,!0),B(V,U,K,`ξ`,`\\xi`,!0),B(V,U,K,`ο`,`\\omicron`,!0),B(V,U,K,`π`,`\\pi`,!0),B(V,U,K,`ρ`,`\\rho`,!0),B(V,U,K,`σ`,`\\sigma`,!0),B(V,U,K,`τ`,`\\tau`,!0),B(V,U,K,`υ`,`\\upsilon`,!0),B(V,U,K,`ϕ`,`\\phi`,!0),B(V,U,K,`χ`,`\\chi`,!0),B(V,U,K,`ψ`,`\\psi`,!0),B(V,U,K,`ω`,`\\omega`,!0),B(V,U,K,`ε`,`\\varepsilon`,!0),B(V,U,K,`ϑ`,`\\vartheta`,!0),B(V,U,K,`ϖ`,`\\varpi`,!0),B(V,U,K,`ϱ`,`\\varrho`,!0),B(V,U,K,`ς`,`\\varsigma`,!0),B(V,U,K,`φ`,`\\varphi`,!0),B(V,U,G,`∗`,`*`,!0),B(V,U,G,`+`,`+`),B(V,U,G,`−`,`-`,!0),B(V,U,G,`⋅`,`\\cdot`,!0),B(V,U,G,`∘`,`\\circ`,!0),B(V,U,G,`÷`,`\\div`,!0),B(V,U,G,`±`,`\\pm`,!0),B(V,U,G,`×`,`\\times`,!0),B(V,U,G,`∩`,`\\cap`,!0),B(V,U,G,`∪`,`\\cup`,!0),B(V,U,G,`∖`,`\\setminus`,!0),B(V,U,G,`∧`,`\\land`),B(V,U,G,`∨`,`\\lor`),B(V,U,G,`∧`,`\\wedge`,!0),B(V,U,G,`∨`,`\\vee`,!0),B(V,U,J,`√`,`\\surd`),B(V,U,lW,`⟨`,`\\langle`,!0),B(V,U,lW,`∣`,`\\lvert`),B(V,U,lW,`∥`,`\\lVert`),B(V,U,oW,`?`,`?`),B(V,U,oW,`!`,`!`),B(V,U,oW,`⟩`,`\\rangle`,!0),B(V,U,oW,`∣`,`\\rvert`),B(V,U,oW,`∥`,`\\rVert`),B(V,U,q,`=`,`=`),B(V,U,q,`:`,`:`),B(V,U,q,`≈`,`\\approx`,!0),B(V,U,q,`≅`,`\\cong`,!0),B(V,U,q,`≥`,`\\ge`),B(V,U,q,`≥`,`\\geq`,!0),B(V,U,q,`←`,`\\gets`),B(V,U,q,`>`,`\\gt`,!0),B(V,U,q,`∈`,`\\in`,!0),B(V,U,q,``,`\\@not`),B(V,U,q,`⊂`,`\\subset`,!0),B(V,U,q,`⊃`,`\\supset`,!0),B(V,U,q,`⊆`,`\\subseteq`,!0),B(V,U,q,`⊇`,`\\supseteq`,!0),B(V,W,q,`⊈`,`\\nsubseteq`,!0),B(V,W,q,`⊉`,`\\nsupseteq`,!0),B(V,U,q,`⊨`,`\\models`),B(V,U,q,`←`,`\\leftarrow`,!0),B(V,U,q,`≤`,`\\le`),B(V,U,q,`≤`,`\\leq`,!0),B(V,U,q,`<`,`\\lt`,!0),B(V,U,q,`→`,`\\rightarrow`,!0),B(V,U,q,`→`,`\\to`),B(V,W,q,`≱`,`\\ngeq`,!0),B(V,W,q,`≰`,`\\nleq`,!0),B(V,U,dW,`\xA0`,`\\ `),B(V,U,dW,`\xA0`,`\\space`),B(V,U,dW,`\xA0`,`\\nobreakspace`),B(H,U,dW,`\xA0`,`\\ `),B(H,U,dW,`\xA0`,` `),B(H,U,dW,`\xA0`,`\\space`),B(H,U,dW,`\xA0`,`\\nobreakspace`),B(V,U,dW,``,`\\nobreak`),B(V,U,dW,``,`\\allowbreak`),B(V,U,uW,`,`,`,`),B(V,U,uW,`;`,`;`),B(V,W,G,`⊼`,`\\barwedge`,!0),B(V,W,G,`⊻`,`\\veebar`,!0),B(V,U,G,`⊙`,`\\odot`,!0),B(V,U,G,`⊕`,`\\oplus`,!0),B(V,U,G,`⊗`,`\\otimes`,!0),B(V,U,J,`∂`,`\\partial`,!0),B(V,U,G,`⊘`,`\\oslash`,!0),B(V,W,G,`⊚`,`\\circledcirc`,!0),B(V,W,G,`⊡`,`\\boxdot`,!0),B(V,U,G,`△`,`\\bigtriangleup`),B(V,U,G,`▽`,`\\bigtriangledown`),B(V,U,G,`†`,`\\dagger`),B(V,U,G,`⋄`,`\\diamond`),B(V,U,G,`⋆`,`\\star`),B(V,U,G,`◃`,`\\triangleleft`),B(V,U,G,`▹`,`\\triangleright`),B(V,U,lW,`{`,`\\{`),B(H,U,J,`{`,`\\{`),B(H,U,J,`{`,`\\textbraceleft`),B(V,U,oW,`}`,`\\}`),B(H,U,J,`}`,`\\}`),B(H,U,J,`}`,`\\textbraceright`),B(V,U,lW,`{`,`\\lbrace`),B(V,U,oW,`}`,`\\rbrace`),B(V,U,lW,`[`,`\\lbrack`,!0),B(H,U,J,`[`,`\\lbrack`,!0),B(V,U,oW,`]`,`\\rbrack`,!0),B(H,U,J,`]`,`\\rbrack`,!0),B(V,U,lW,`(`,`\\lparen`,!0),B(V,U,oW,`)`,`\\rparen`,!0),B(H,U,J,`<`,`\\textless`,!0),B(H,U,J,`>`,`\\textgreater`,!0),B(V,U,lW,`⌊`,`\\lfloor`,!0),B(V,U,oW,`⌋`,`\\rfloor`,!0),B(V,U,lW,`⌈`,`\\lceil`,!0),B(V,U,oW,`⌉`,`\\rceil`,!0),B(V,U,J,`\\`,`\\backslash`),B(V,U,J,`∣`,`|`),B(V,U,J,`∣`,`\\vert`),B(H,U,J,`|`,`\\textbar`,!0),B(V,U,J,`∥`,`\\|`),B(V,U,J,`∥`,`\\Vert`),B(H,U,J,`∥`,`\\textbardbl`),B(H,U,J,`~`,`\\textasciitilde`),B(H,U,J,`\\`,`\\textbackslash`),B(H,U,J,`^`,`\\textasciicircum`),B(V,U,q,`↑`,`\\uparrow`,!0),B(V,U,q,`⇑`,`\\Uparrow`,!0),B(V,U,q,`↓`,`\\downarrow`,!0),B(V,U,q,`⇓`,`\\Downarrow`,!0),B(V,U,q,`↕`,`\\updownarrow`,!0),B(V,U,q,`⇕`,`\\Updownarrow`,!0),B(V,U,cW,`∐`,`\\coprod`),B(V,U,cW,`⋁`,`\\bigvee`),B(V,U,cW,`⋀`,`\\bigwedge`),B(V,U,cW,`⨄`,`\\biguplus`),B(V,U,cW,`⋂`,`\\bigcap`),B(V,U,cW,`⋃`,`\\bigcup`),B(V,U,cW,`∫`,`\\int`),B(V,U,cW,`∫`,`\\intop`),B(V,U,cW,`∬`,`\\iint`),B(V,U,cW,`∭`,`\\iiint`),B(V,U,cW,`∏`,`\\prod`),B(V,U,cW,`∑`,`\\sum`),B(V,U,cW,`⨂`,`\\bigotimes`),B(V,U,cW,`⨁`,`\\bigoplus`),B(V,U,cW,`⨀`,`\\bigodot`),B(V,U,cW,`∮`,`\\oint`),B(V,U,cW,`∯`,`\\oiint`),B(V,U,cW,`∰`,`\\oiiint`),B(V,U,cW,`⨆`,`\\bigsqcup`),B(V,U,cW,`∫`,`\\smallint`),B(H,U,sW,`…`,`\\textellipsis`),B(V,U,sW,`…`,`\\mathellipsis`),B(H,U,sW,`…`,`\\ldots`,!0),B(V,U,sW,`…`,`\\ldots`,!0),B(V,U,sW,`⋯`,`\\@cdots`,!0),B(V,U,sW,`⋱`,`\\ddots`,!0),B(V,U,J,`⋮`,`\\varvdots`),B(H,U,J,`⋮`,`\\varvdots`),B(V,U,aW,`ˊ`,`\\acute`),B(V,U,aW,`ˋ`,`\\grave`),B(V,U,aW,`¨`,`\\ddot`),B(V,U,aW,`~`,`\\tilde`),B(V,U,aW,`ˉ`,`\\bar`),B(V,U,aW,`˘`,`\\breve`),B(V,U,aW,`ˇ`,`\\check`),B(V,U,aW,`^`,`\\hat`),B(V,U,aW,`⃗`,`\\vec`),B(V,U,aW,`˙`,`\\dot`),B(V,U,aW,`˚`,`\\mathring`),B(V,U,K,``,`\\@imath`),B(V,U,K,``,`\\@jmath`),B(V,U,J,`ı`,`ı`),B(V,U,J,`ȷ`,`ȷ`),B(H,U,J,`ı`,`\\i`,!0),B(H,U,J,`ȷ`,`\\j`,!0),B(H,U,J,`ß`,`\\ss`,!0),B(H,U,J,`æ`,`\\ae`,!0),B(H,U,J,`œ`,`\\oe`,!0),B(H,U,J,`ø`,`\\o`,!0),B(H,U,J,`Æ`,`\\AE`,!0),B(H,U,J,`Œ`,`\\OE`,!0),B(H,U,J,`Ø`,`\\O`,!0),B(H,U,aW,`ˊ`,`\\'`),B(H,U,aW,`ˋ`,"\\`"),B(H,U,aW,`ˆ`,`\\^`),B(H,U,aW,`˜`,`\\~`),B(H,U,aW,`ˉ`,`\\=`),B(H,U,aW,`˘`,`\\u`),B(H,U,aW,`˙`,`\\.`),B(H,U,aW,`¸`,`\\c`),B(H,U,aW,`˚`,`\\r`),B(H,U,aW,`ˇ`,`\\v`),B(H,U,aW,`¨`,`\\"`),B(H,U,aW,`˝`,`\\H`),B(H,U,aW,`◯`,`\\textcircled`);var fW={"--":!0,"---":!0,"``":!0,"''":!0};B(H,U,J,`–`,`--`,!0),B(H,U,J,`–`,`\\textendash`),B(H,U,J,`—`,`---`,!0),B(H,U,J,`—`,`\\textemdash`),B(H,U,J,`‘`,"`",!0),B(H,U,J,`‘`,`\\textquoteleft`),B(H,U,J,`’`,`'`,!0),B(H,U,J,`’`,`\\textquoteright`),B(H,U,J,`“`,"``",!0),B(H,U,J,`“`,`\\textquotedblleft`),B(H,U,J,`”`,`''`,!0),B(H,U,J,`”`,`\\textquotedblright`),B(V,U,J,`°`,`\\degree`,!0),B(H,U,J,`°`,`\\degree`),B(H,U,J,`°`,`\\textdegree`,!0),B(V,U,J,`£`,`\\pounds`),B(V,U,J,`£`,`\\mathsterling`,!0),B(H,U,J,`£`,`\\pounds`),B(H,U,J,`£`,`\\textsterling`,!0),B(V,W,J,`✠`,`\\maltese`),B(H,W,J,`✠`,`\\maltese`);for(var pW=`0123456789/@."`,mW=0;mW{var t=e.charCodeAt(0),n=e.charCodeAt(1),r=(t-55296)*1024+(n-56320)+65536;if(119808<=r&&r<120484)return VW[Math.floor((r-119808)/26)];if(120782<=r&&r<=120831)return HW[Math.floor((r-120782)/10)];if(r===120485||r===120486)return VW[0];if(120486{if(PU(e.classes)!==PU(t.classes)||e.skew!==t.skew||e.maxFontSize!==t.maxFontSize||e.italic!==0&&e.hasClass(`mathnormal`))return!1;if(e.classes.length===1){var n=e.classes[0];if(n===`mbin`||n===`mord`)return!1}for(var r of Object.keys(e.style))if(e.style[r]!==t.style[r])return!1;for(var i of Object.keys(t.style))if(e.style[i]!==t.style[i])return!1;return!0},XW=e=>{for(var t=0;tt&&(t=a.height),a.depth>n&&(n=a.depth),a.maxFontSize>r&&(r=a.maxFontSize)}e.height=t,e.depth=n,e.maxFontSize=r},X=function(e,t,n,r){var i=new BU(e,t,n,r);return ZW(i),i},QW=(e,t,n,r)=>new BU(e,t,n,r),$W=function(e,t,n){var r=X([e],[],t);return r.height=Math.max(n||t.fontMetrics().defaultRuleThickness,t.minRuleThickness),r.style.borderBottomWidth=z(r.height),r.maxFontSize=1,r},eG=function(e,t,n,r){var i=new VU(e,t,n,r);return ZW(i),i},tG=function(e){var t=new kU(e);return ZW(t),t},nG=function(e,t){return e instanceof kU?X([],[e],t):e},rG=function(e){if(e.positionType===`individualShift`){for(var t=e.children,n=[t[0]],r=-t[0].shift-t[0].elem.depth,i=r,a=1;a{var n=X([`mspace`],[],t),r=NU(e,t);return n.style.marginRight=z(r),n},oG=(e,t,n)=>{var r,i;switch(e){case`amsrm`:r=`AMS`;break;case`textrm`:r=`Main`;break;case`textsf`:r=`SansSerif`;break;case`texttt`:r=`Typewriter`;break;default:r=e}return i=t===`textbf`&&n===`textit`?`BoldItalic`:t===`textbf`?`Bold`:n===`textit`?`Italic`:`Regular`,r+`-`+i},sG={mathbf:{variant:`bold`,fontName:`Main-Bold`},mathrm:{variant:`normal`,fontName:`Main-Regular`},textit:{variant:`italic`,fontName:`Main-Italic`},mathit:{variant:`italic`,fontName:`Main-Italic`},mathnormal:{variant:`italic`,fontName:`Math-Italic`},mathsfit:{variant:`sans-serif-italic`,fontName:`SansSerif-Italic`},mathbb:{variant:`double-struck`,fontName:`AMS-Regular`},mathcal:{variant:`script`,fontName:`Caligraphic-Regular`},mathfrak:{variant:`fraktur`,fontName:`Fraktur-Regular`},mathscr:{variant:`script`,fontName:`Script-Regular`},mathsf:{variant:`sans-serif`,fontName:`SansSerif-Regular`},mathtt:{variant:`monospace`,fontName:`Typewriter-Regular`}},cG={vec:[`vec`,.471,.714],oiintSize1:[`oiintSize1`,.957,.499],oiintSize2:[`oiintSize2`,1.472,.659],oiiintSize1:[`oiiintSize1`,1.304,.499],oiiintSize2:[`oiiintSize2`,1.98,.659]},lG=function(e,t){var n=cG[e],r=n[0],i=n[1],a=n[2],o=QW([`katex-overlay`],[new GU([new KU(r)],{width:z(i),height:z(a),style:`width:`+z(i),viewBox:`0 0 `+1e3*i+` `+1e3*a,preserveAspectRatio:`xMinYMin`})],t);return o.height=a,o.style.height=z(a),o.style.width=z(i),o},uG={number:3,unit:`mu`},dG={number:4,unit:`mu`},fG={number:5,unit:`mu`},pG={mord:{mop:uG,mbin:dG,mrel:fG,minner:uG},mop:{mord:uG,mop:uG,mrel:fG,minner:uG},mbin:{mord:dG,mop:dG,mopen:dG,minner:dG},mrel:{mord:fG,mop:fG,mopen:fG,minner:fG},mopen:{},mclose:{mop:uG,mbin:dG,mrel:fG,minner:uG},mpunct:{mord:uG,mop:uG,mrel:fG,mopen:uG,mclose:uG,mpunct:uG,minner:uG},minner:{mord:uG,mop:uG,mbin:dG,mrel:fG,mopen:uG,mpunct:uG,minner:uG}},mG={mord:{mop:uG},mop:{mord:uG,mop:uG},mbin:{},mrel:{},mopen:{},mclose:{mop:uG},mpunct:{},minner:{mop:uG}},hG={},gG={},_G={};function Z(e){for(var t=e.type,n=e.names,r=e.htmlBuilder,i=e.mathmlBuilder,a=0;a{var n=t.classes[0],r=e.classes[0];n===`mbin`&&SG.has(r)?t.classes[0]=`mord`:r===`mbin`&&xG.has(n)&&(e.classes[0]=`mord`)},{node:u},d,f),EG(i,(e,t)=>{var n=kG(t),r=kG(e),i=n&&r?e.hasClass(`mtight`)?mG[n]?.[r]:pG[n]?.[r]:null;if(i)return aG(i,c)},{node:u},d,f),i},EG=function(e,t,n,r,i){r&&e.push(r);for(var a=0;an=>{e.splice(t+1,0,n),a++})(a)}}r&&e.pop()},DG=function(e){return e instanceof kU||e instanceof VU||e instanceof BU&&e.hasClass(`enclosing`)?e:null},OG=function(e,t){var n=DG(e);if(n){var r=n.children;if(r.length){if(t===`right`)return OG(r[r.length-1],`right`);if(t===`left`)return OG(r[0],`left`)}}return e},kG=function(e,t){return e?(t&&(e=OG(e,t)),wG[e.classes[0]]||null):null},AG=function(e,t){var n=[`nulldelimiter`].concat(e.baseSizingClasses());return X(t.concat(n))},jG=function(e,t,n){if(!e)return X();if(gG[e.type]){var r=gG[e.type](e,t);if(n&&t.size!==n.size){r=X(t.sizingClasses(n),[r],t);var i=t.sizeMultiplier/n.sizeMultiplier;r.height*=i,r.depth*=i}return r}throw new L(`Got group of unknown type: '`+e.type+`'`)};function MG(e,t){var n=X([`katex-base`],e,t),r=X([`katex-strut`]);return r.style.height=z(n.height+n.depth),n.depth&&(r.style.verticalAlign=z(-n.depth)),n.children.unshift(r),n}function NG(e,t){var n=null;e.length===1&&e[0].type===`tag`&&(n=e[0].tag,e=e[0].body);var r=TG(e,t,`root`),i;r.length===2&&r[1].hasClass(`katex-tag`)&&(i=r.pop());for(var a=[],o=[],s=0;s0&&(a.push(MG(o,t)),o=[]),a.push(r[s]));o.length>0&&a.push(MG(o,t));var l;n?(l=MG(TG(n,t,!0),t),l.classes=[`katex-tag`],a.push(l)):i&&a.push(i);var u=X([`katex-html`],a);if(u.setAttribute(`aria-hidden`,`true`),l){var d=l.children[0];d.style.height=z(u.height+u.depth),u.depth&&(d.style.verticalAlign=z(-u.depth))}return u}function PG(e){return new kU(e)}var Q=class{constructor(e,t,n){this.type=void 0,this.attributes=void 0,this.children=void 0,this.classes=void 0,this.type=e,this.attributes={},this.children=t||[],this.classes=n||[]}setAttribute(e,t){this.attributes[e]=t}getAttribute(e){return this.attributes[e]}toNode(){var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,this.type);for(var t of Object.entries(this.attributes)){var n=t[0],r=t[1];e.setAttribute(n,r)}this.classes.length>0&&(e.className=PU(this.classes));for(var i=0;i0&&(e+=` class ="`+zH(PU(this.classes))+`"`),e+=`>`;for(var i=0;i`,e}toText(){return this.children.map(e=>e.toText()).join(``)}},FG=class{constructor(e){this.text=void 0,this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return zH(this.toText())}toText(){return this.text}},IG=class{constructor(e){this.width=void 0,this.character=void 0,this.width=e,this.character=e>=.05555&&e<=.05556?` `:e>=.1666&&e<=.1667?` `:e>=.2222&&e<=.2223?` `:e>=.2777&&e<=.2778?`  `:e>=-.05556&&e<=-.05555?` ⁣`:e>=-.1667&&e<=-.1666?` ⁣`:e>=-.2223&&e<=-.2222?` ⁣`:e>=-.2778&&e<=-.2777?` ⁣`:null}toNode(){if(this.character)return document.createTextNode(this.character);var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`mspace`);return e.setAttribute(`width`,z(this.width)),e}toMarkup(){return this.character?``+this.character+``:``}toText(){return this.character?this.character:` `}},LG=new Set([`\\imath`,`\\jmath`]),RG=new Set([`mrow`,`mtable`]),zG=function(e,t,n){var r,i;return iW[t][e]&&iW[t][e].replace&&e.charCodeAt(0)!==55349&&(!Object.prototype.hasOwnProperty.call(fW,e)||(n==null||(r=n.fontFamily)==null?void 0:r.slice(4,6))!==`tt`&&(n==null||(i=n.font)==null?void 0:i.slice(4,6))!==`tt`)&&(e=iW[t][e].replace),new FG(e)},BG=function(e){return e.length===1?e[0]:new Q(`mrow`,e)},VG={mathit:`italic`,boldsymbol:e=>e.type===`textord`?`bold`:`bold-italic`,mathbf:`bold`,mathbb:`double-struck`,mathsfit:`sans-serif-italic`,mathfrak:`fraktur`,mathscr:`script`,mathcal:`script`,mathsf:`sans-serif`,mathtt:`monospace`},HG=(e,t)=>{if(e.mode===`text`){if(t.fontFamily===`texttt`)return`monospace`;if(t.fontFamily===`textsf`)return t.fontShape===`textit`&&t.fontWeight===`textbf`?`sans-serif-bold-italic`:t.fontShape===`textit`?`sans-serif-italic`:t.fontWeight===`textbf`?`bold-sans-serif`:`sans-serif`;if(t.fontShape===`textit`&&t.fontWeight===`textbf`)return`bold-italic`;if(t.fontShape===`textit`)return`italic`;if(t.fontWeight===`textbf`)return`bold`}var n=t.font;if(!n||n===`mathnormal`)return null;var r=e.mode,i=VG[n];if(i)return typeof i==`function`?i(e):i;var a=e.text;if(LG.has(a))return null;if(iW[r][a]){var o=iW[r][a].replace;o&&(a=o)}var s=sG[n].fontName;return tW(a,s,r)?sG[n].variant:null};function UG(e){if(!e)return!1;if(e.type===`mi`&&e.children.length===1){var t=e.children[0];return t instanceof FG&&t.text===`.`}if(e.type===`mo`&&e.children.length===1&&e.getAttribute(`separator`)===`true`&&e.getAttribute(`lspace`)===`0em`&&e.getAttribute(`rspace`)===`0em`){var n=e.children[0];return n instanceof FG&&n.text===`,`}return!1}var WG=function(e,t,n){if(e.length===1){var r=KG(e[0],t);return n&&r instanceof Q&&r.type===`mo`&&(r.setAttribute(`lspace`,`0em`),r.setAttribute(`rspace`,`0em`)),[r]}for(var i=[],a,o=0;o=1&&(a.type===`mn`||UG(a))){var c=s.children[0];c instanceof Q&&c.type===`mn`&&(c.children=[...a.children,...c.children],i.pop())}else if(a.type===`mi`&&a.children.length===1){var l=a.children[0];if(l instanceof FG&&l.text===`̸`&&(s.type===`mo`||s.type===`mi`||s.type===`mn`)){var u=s.children[0];u instanceof FG&&u.text.length>0&&(u.text=u.text.slice(0,1)+`̸`+u.text.slice(1),i.pop())}}}i.push(s),a=s}return i},GG=function(e,t,n){return BG(WG(e,t,n))},KG=function(e,t){if(!e)return new Q(`mrow`);if(_G[e.type])return _G[e.type](e,t);throw new L(`Got group of unknown type: '`+e.type+`'`)};function qG(e,t,n,r,i){var a=WG(e,n),o=a.length===1&&a[0]instanceof Q&&RG.has(a[0].type)?a[0]:new Q(`mrow`,a),s=new Q(`annotation`,[new FG(t)]);s.setAttribute(`encoding`,`application/x-tex`);var c=new Q(`math`,[new Q(`semantics`,[o,s])]);return c.setAttribute(`xmlns`,`http://www.w3.org/1998/Math/MathML`),r&&c.setAttribute(`display`,`block`),X([i?`katex`:`katex-mathml`],[c])}var JG=[[1,1,1],[2,1,1],[3,1,1],[4,2,1],[5,2,1],[6,3,1],[7,4,2],[8,6,3],[9,7,6],[10,8,7],[11,10,9]],YG=[.5,.6,.7,.8,.9,1,1.2,1.44,1.728,2.074,2.488],XG=function(e,t){return t.size<2?e:JG[e-1][t.size-1]},ZG=class e{constructor(t){this.style=void 0,this.color=void 0,this.size=void 0,this.textSize=void 0,this.phantom=void 0,this.font=void 0,this.fontFamily=void 0,this.fontWeight=void 0,this.fontShape=void 0,this.sizeMultiplier=void 0,this.maxSize=void 0,this.minRuleThickness=void 0,this._fontMetrics=void 0,this.style=t.style,this.color=t.color,this.size=t.size||e.BASESIZE,this.textSize=t.textSize||this.size,this.phantom=!!t.phantom,this.font=t.font||``,this.fontFamily=t.fontFamily||``,this.fontWeight=t.fontWeight||``,this.fontShape=t.fontShape||``,this.sizeMultiplier=YG[this.size-1],this.maxSize=t.maxSize,this.minRuleThickness=t.minRuleThickness,this._fontMetrics=void 0}extend(t){var n={style:this.style,size:this.size,textSize:this.textSize,color:this.color,phantom:this.phantom,font:this.font,fontFamily:this.fontFamily,fontWeight:this.fontWeight,fontShape:this.fontShape,maxSize:this.maxSize,minRuleThickness:this.minRuleThickness};return Object.assign(n,t),new e(n)}havingStyle(e){return this.style===e?this:this.extend({style:e,size:XG(this.textSize,e)})}havingCrampedStyle(){return this.havingStyle(this.style.cramp())}havingSize(e){return this.size===e&&this.textSize===e?this:this.extend({style:this.style.text(),size:e,textSize:e,sizeMultiplier:YG[e-1]})}havingBaseStyle(t){t||=this.style.text();var n=XG(e.BASESIZE,t);return this.size===n&&this.textSize===e.BASESIZE&&this.style===t?this:this.extend({style:t,size:n})}havingBaseSizing(){var e;switch(this.style.id){case 4:case 5:e=3;break;case 6:case 7:e=1;break;default:e=6}return this.extend({style:this.style.text(),size:e})}withColor(e){return this.extend({color:e})}withPhantom(){return this.extend({phantom:!0})}withFont(e){return this.extend({font:e})}withTextFontFamily(e){return this.extend({fontFamily:e,font:``})}withTextFontWeight(e){return this.extend({fontWeight:e,font:``})}withTextFontShape(e){return this.extend({fontShape:e,font:``})}sizingClasses(e){return e.size===this.size?[]:[`katex-sizing`,`reset-size`+e.size,`size`+this.size]}baseSizingClasses(){return this.size===e.BASESIZE?[]:[`katex-sizing`,`reset-size`+this.size,`size`+e.BASESIZE]}fontMetrics(){return this._fontMetrics||=rW(this.size),this._fontMetrics}getColor(){return this.phantom?`transparent`:this.color}};ZG.BASESIZE=6;var QG=function(e){return new ZG({style:e.displayMode?R.DISPLAY:R.TEXT,maxSize:e.maxSize,minRuleThickness:e.minRuleThickness})},$G=function(e,t){if(t.displayMode){var n=[`katex-display`];t.leqno&&n.push(`leqno`),t.fleqn&&n.push(`fleqn`),e=X(n,[e])}return e},eK=function(e,t,n){var r=QG(n),i;return n.output===`mathml`?qG(e,t,r,n.displayMode,!0):(i=n.output===`html`?X([`katex`],[NG(e,r)]):X([`katex`],[qG(e,t,r,n.displayMode,!1),NG(e,r)]),$G(i,n))},tK=function(e,t,n){return $G(X([`katex`],[NG(e,QG(n))]),n)},nK={widehat:`^`,widecheck:`ˇ`,widetilde:`~`,utilde:`~`,overleftarrow:`←`,underleftarrow:`←`,xleftarrow:`←`,overrightarrow:`→`,underrightarrow:`→`,xrightarrow:`→`,underbrace:`⏟`,overbrace:`⏞`,underbracket:`⎵`,overbracket:`⎴`,overgroup:`⏠`,undergroup:`⏡`,overleftrightarrow:`↔`,underleftrightarrow:`↔`,xleftrightarrow:`↔`,Overrightarrow:`⇒`,xRightarrow:`⇒`,overleftharpoon:`↼`,xleftharpoonup:`↼`,overrightharpoon:`⇀`,xrightharpoonup:`⇀`,xLeftarrow:`⇐`,xLeftrightarrow:`⇔`,xhookleftarrow:`↩`,xhookrightarrow:`↪`,xmapsto:`↦`,xrightharpoondown:`⇁`,xleftharpoondown:`↽`,xrightleftharpoons:`⇌`,xleftrightharpoons:`⇋`,xtwoheadleftarrow:`↞`,xtwoheadrightarrow:`↠`,xlongequal:`=`,xtofrom:`⇄`,xrightleftarrows:`⇄`,xrightequilibrium:`⇌`,xleftequilibrium:`⇋`,"\\cdrightarrow":`→`,"\\cdleftarrow":`←`,"\\cdlongequal":`=`},rK=function(e){var t=new Q(`mo`,[new FG(nK[e.replace(/^\\/,``)])]);return t.setAttribute(`stretchy`,`true`),t},iK={overrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],overleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],underrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],underleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],xrightarrow:[[`rightarrow`],1.469,522,`xMaxYMin`],"\\cdrightarrow":[[`rightarrow`],3,522,`xMaxYMin`],xleftarrow:[[`leftarrow`],1.469,522,`xMinYMin`],"\\cdleftarrow":[[`leftarrow`],3,522,`xMinYMin`],Overrightarrow:[[`doublerightarrow`],.888,560,`xMaxYMin`],xRightarrow:[[`doublerightarrow`],1.526,560,`xMaxYMin`],xLeftarrow:[[`doubleleftarrow`],1.526,560,`xMinYMin`],overleftharpoon:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoonup:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoondown:[[`leftharpoondown`],.888,522,`xMinYMin`],overrightharpoon:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoonup:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoondown:[[`rightharpoondown`],.888,522,`xMaxYMin`],xlongequal:[[`longequal`],.888,334,`xMinYMin`],"\\cdlongequal":[[`longequal`],3,334,`xMinYMin`],xtwoheadleftarrow:[[`twoheadleftarrow`],.888,334,`xMinYMin`],xtwoheadrightarrow:[[`twoheadrightarrow`],.888,334,`xMaxYMin`],overleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],overbrace:[[`leftbrace`,`midbrace`,`rightbrace`],1.6,548],underbrace:[[`leftbraceunder`,`midbraceunder`,`rightbraceunder`],1.6,548],underleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],xleftrightarrow:[[`leftarrow`,`rightarrow`],1.75,522],xLeftrightarrow:[[`doubleleftarrow`,`doublerightarrow`],1.75,560],xrightleftharpoons:[[`leftharpoondownplus`,`rightharpoonplus`],1.75,716],xleftrightharpoons:[[`leftharpoonplus`,`rightharpoondownplus`],1.75,716],xhookleftarrow:[[`leftarrow`,`righthook`],1.08,522],xhookrightarrow:[[`lefthook`,`rightarrow`],1.08,522],overlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],underlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],overbracket:[[`leftbracketover`,`rightbracketover`],1.6,440],underbracket:[[`leftbracketunder`,`rightbracketunder`],1.6,410],overgroup:[[`leftgroup`,`rightgroup`],.888,342],undergroup:[[`leftgroupunder`,`rightgroupunder`],.888,342],xmapsto:[[`leftmapsto`,`rightarrow`],1.5,522],xtofrom:[[`leftToFrom`,`rightToFrom`],1.75,528],xrightleftarrows:[[`baraboveleftarrow`,`rightarrowabovebar`],1.75,901],xrightequilibrium:[[`baraboveshortleftharpoon`,`rightharpoonaboveshortbar`],1.75,716],xleftequilibrium:[[`shortbaraboveleftharpoon`,`shortrightharpoonabovebar`],1.75,716]},aK=new Set([`widehat`,`widecheck`,`widetilde`,`utilde`]),oK=function(e,t){function n(){var n=4e5,r=e.label.slice(1);if(aK.has(r)&&`base`in e){var i=e.base.type===`ordgroup`?e.base.body.length:1,a,o,s;if(i>5)r===`widehat`||r===`widecheck`?(a=420,n=2364,s=.42,o=r+`4`):(a=312,n=2340,s=.34,o=`tilde4`);else{var c=[1,1,2,2,3,3][i];r===`widehat`||r===`widecheck`?(n=[0,1062,2364,2364,2364][c],a=[0,239,300,360,420][c],s=[0,.24,.3,.3,.36,.42][c],o=r+c):(n=[0,600,1033,2339,2340][c],a=[0,260,286,306,312][c],s=[0,.26,.286,.3,.306,.34][c],o=`tilde`+c)}return{span:QW([],[new GU([new KU(o)],{width:`100%`,height:z(s),viewBox:`0 0 `+n+` `+a,preserveAspectRatio:`none`})],t),minWidth:0,height:s}}var l=[],u=iK[r];if(!u)throw Error(`No SVG data for "`+r+`".`);var d=u[0],f=u[1],p=u[2],m=p/1e3,h=d.length,g,_;if(h===1){if(u.length!==4)throw Error(`Expected 4-tuple for single-path SVG data "`+r+`".`);g=[`hide-tail`],_=[u[3]]}else if(h===2)g=[`halfarrow-left`,`halfarrow-right`],_=[`xMinYMin`,`xMaxYMin`];else if(h===3)g=[`brace-left`,`brace-center`,`brace-right`],_=[`xMinYMin`,`xMidYMin`,`xMaxYMin`];else throw Error(`Correct katexImagesData or update code here to support - `+h+` children.`);for(var v=0;v0&&(i.style.minWidth=z(a)),i},sK=function(e,t,n,r,i){var a,o=e.height+e.depth+n+r;if(/fbox|color|angl/.test(t)){if(a=X([`katex-stretchy`,t],[],i),t===`fbox`){var s=i.color&&i.getColor();s&&(a.style.borderColor=s)}}else{var c=[];/^[bx]cancel$/.test(t)&&c.push(new qU({x1:`0`,y1:`0`,x2:`100%`,y2:`100%`,"stroke-width":`0.046em`})),/^x?cancel$/.test(t)&&c.push(new qU({x1:`0`,y1:`100%`,x2:`100%`,y2:`0`,"stroke-width":`0.046em`})),a=QW([],[new GU(c,{width:`100%`,height:z(o)})],i)}return a.height=o,a.style.height=z(o),a},cK=[`bin`,`close`,`inner`,`open`,`punct`,`rel`],lK=[`accent-token`,`mathord`,`op-token`,`spacing`,`textord`],uK=new Set(cK),dK=new Set(lK);function fK(e){return uK.has(e)}function pK(e,t){if(!e||e.type!==t)throw Error(`Expected node of type `+t+`, but got `+(e?`node of type `+e.type:String(e)));return e}function mK(e){var t=hK(e);if(!t)throw Error(`Expected node of symbol group type, but got `+(e?`node of type `+e.type:String(e)));return t}function hK(e){return e.type===`atom`||dK.has(e.type)?e:null}function gK(e,t,n){var r=``;for(var i of e.body)if(i.type===`textord`)r+=i.text;else if(n&&i.type===`spacing`&&i.text===` `)r+=` `;else throw new L(t,e);return r}var _K=e=>{if(e instanceof WU)return e;if(XU(e)&&e.children.length===1)return _K(e.children[0])},vK=(e,t)=>{var n,r,i;e&&e.type===`supsub`?(r=pK(e.base,`accent`),n=r.base,e.base=n,i=YU(jG(e,t)),e.base=r):(r=pK(e,`accent`),n=r.base);var a=jG(n,t.havingCrampedStyle()),o=r.isShifty&&HH(n),s=0;o&&(s=_K(a)?.skew??0);var c=r.label===`\\c`,l=c?a.height+a.depth:Math.min(a.height,t.fontMetrics().xHeight),u;if(r.isStretchy)u=oK(r,t),u=iG({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`elem`,elem:u,wrapperClasses:[`svg-align`],wrapperStyle:s>0?{width:`calc(100% - `+z(2*s)+`)`,marginLeft:z(2*s)}:void 0}]});else{var d,f;r.label===`\\vec`?(d=lG(`vec`,t),f=cG.vec[1]):(d=JW({type:`textord`,mode:r.mode,text:r.label},t),d=JU(d),d.italic=0,f=d.width,c&&(l+=d.depth)),u=X([`accent-body`],[d]);var p=r.label===`\\textcircled`;p&&(u.classes.push(`accent-full`),l=a.height);var m=s;p||(m-=f/2),u.style.left=z(m),r.label===`\\textcircled`&&(u.style.top=`.2em`),u=iG({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:-l},{type:`elem`,elem:u}]})}var h=X([`mord`,`katex-accent`],[u],t);return i?(i.children[0]=h,i.height=Math.max(h.height,i.height),i.classes[0]=`mord`,i):h},yK=(e,t)=>{var n=e.isStretchy?rK(e.label):new Q(`mo`,[zG(e.label,e.mode)]),r=new Q(`mover`,[KG(e.base,t),n]);return r.setAttribute(`accent`,`true`),r},bK=new RegExp([`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`].map(e=>`\\`+e).join(`|`));Z({type:`accent`,names:[`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`,`\\widecheck`,`\\widehat`,`\\widetilde`,`\\overrightarrow`,`\\overleftarrow`,`\\Overrightarrow`,`\\overleftrightarrow`,`\\overgroup`,`\\overlinesegment`,`\\overleftharpoon`,`\\overrightharpoon`],numArgs:1,handler:(e,t)=>{var n=yG(t[0]),r=!bK.test(e.funcName),i=!r||e.funcName===`\\widehat`||e.funcName===`\\widetilde`||e.funcName===`\\widecheck`;return{type:`accent`,mode:e.parser.mode,label:e.funcName,isStretchy:r,isShifty:i,base:n}},htmlBuilder:vK,mathmlBuilder:yK}),Z({type:`accent`,names:[`\\'`,"\\`",`\\^`,`\\~`,`\\=`,`\\u`,`\\.`,`\\"`,`\\c`,`\\r`,`\\H`,`\\v`,`\\textcircled`],numArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`primitive`],handler:(e,t)=>{var n=t[0],r=e.parser.mode;return r===`math`&&(e.parser.settings.reportNonstrict(`mathVsTextAccents`,`LaTeX's accent `+e.funcName+` works only in text mode`),r=`text`),{type:`accent`,mode:r,label:e.funcName,isStretchy:!1,isShifty:!0,base:n}}}),Z({type:`accentUnder`,names:[`\\underleftarrow`,`\\underrightarrow`,`\\underleftrightarrow`,`\\undergroup`,`\\underlinesegment`,`\\utilde`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`accentUnder`,mode:n.mode,label:r,base:i}},htmlBuilder:(e,t)=>{var n=jG(e.base,t),r=oK(e,t),i=e.label===`\\utilde`?.12:0;return X([`mord`,`accentunder`],[iG({positionType:`top`,positionData:n.height,children:[{type:`elem`,elem:r,wrapperClasses:[`svg-align`]},{type:`kern`,size:i},{type:`elem`,elem:n}]})],t)},mathmlBuilder:(e,t)=>{var n=rK(e.label),r=new Q(`munder`,[KG(e.base,t),n]);return r.setAttribute(`accentunder`,`true`),r}});var xK=e=>{var t=new Q(`mpadded`,e?[e]:[]);return t.setAttribute(`width`,`+0.6em`),t.setAttribute(`lspace`,`0.3em`),t};Z({type:`xArrow`,names:[`\\xleftarrow`,`\\xrightarrow`,`\\xLeftarrow`,`\\xRightarrow`,`\\xleftrightarrow`,`\\xLeftrightarrow`,`\\xhookleftarrow`,`\\xhookrightarrow`,`\\xmapsto`,`\\xrightharpoondown`,`\\xrightharpoonup`,`\\xleftharpoondown`,`\\xleftharpoonup`,`\\xrightleftharpoons`,`\\xleftrightharpoons`,`\\xlongequal`,`\\xtwoheadrightarrow`,`\\xtwoheadleftarrow`,`\\xtofrom`,`\\xrightleftarrows`,`\\xrightequilibrium`,`\\xleftequilibrium`,`\\\\cdrightarrow`,`\\\\cdleftarrow`,`\\\\cdlongequal`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=e.funcName;return{type:`xArrow`,mode:r.mode,label:i,body:t[0],below:n[0]}},htmlBuilder(e,t){var n=t.style,r=t.havingStyle(n.sup()),i=nG(jG(e.body,r,t),t),a=e.label.slice(0,2)===`\\x`?`x`:`cd`;i.classes.push(a+`-arrow-pad`);var o;e.below&&(r=t.havingStyle(n.sub()),o=nG(jG(e.below,r,t),t),o.classes.push(a+`-arrow-pad`));var s=oK(e,t),c=-t.fontMetrics().axisHeight+.5*s.height,l=-t.fontMetrics().axisHeight-.5*s.height-.111;(i.depth>.25||e.label===`\\xleftequilibrium`)&&(l-=i.depth);var u;if(o){var d=-t.fontMetrics().axisHeight+o.height+.5*s.height+.111;u=iG({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]},{type:`elem`,elem:o,shift:d}]})}else u=iG({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]}]});return X([`mrel`,`x-arrow`],[u],t)},mathmlBuilder(e,t){var n=rK(e.label);n.setAttribute(`minsize`,e.label.charAt(0)===`x`?`1.75em`:`3.0em`);var r;if(e.body){var i=xK(KG(e.body,t));r=e.below?new Q(`munderover`,[n,xK(KG(e.below,t)),i]):new Q(`mover`,[n,i])}else e.below?r=new Q(`munder`,[n,xK(KG(e.below,t))]):(r=xK(),r=new Q(`mover`,[n,r]));return r}});function SK(e,t){var n=TG(e.body,t,!0);return X([e.mclass],n,t)}function CK(e,t){var n,r=WG(e.body,t);return e.mclass===`minner`?n=new Q(`mpadded`,r):e.mclass===`mord`?e.isCharacterBox?(n=r[0],n.type=`mi`):n=new Q(`mi`,r):(e.isCharacterBox?(n=r[0],n.type=`mo`):n=new Q(`mo`,r),e.mclass===`mbin`?(n.attributes.lspace=`0.22em`,n.attributes.rspace=`0.22em`):e.mclass===`mpunct`?(n.attributes.lspace=`0em`,n.attributes.rspace=`0.17em`):(e.mclass===`mopen`||e.mclass===`mclose`)&&(n.attributes.lspace=`0em`,n.attributes.rspace=`0em`)),n}Z({type:`mclass`,names:[`\\mathord`,`\\mathbin`,`\\mathrel`,`\\mathopen`,`\\mathclose`,`\\mathpunct`,`\\mathinner`],numArgs:1,primitive:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`mclass`,mode:n.mode,mclass:`m`+r.slice(5),body:bG(i),isCharacterBox:HH(i)}},htmlBuilder:SK,mathmlBuilder:CK});var wK=e=>{var t=e.type===`ordgroup`&&e.body.length?e.body[0]:e;return t.type===`atom`&&(t.family===`bin`||t.family===`rel`)?`m`+t.family:`mord`};Z({type:`mclass`,names:[`\\@binrel`],numArgs:2,handler(e,t){return{type:`mclass`,mode:e.parser.mode,mclass:wK(t[0]),body:bG(t[1]),isCharacterBox:HH(t[1])}}}),Z({type:`mclass`,names:[`\\stackrel`,`\\overset`,`\\underset`],numArgs:2,handler(e,t){var n=e.parser,r=e.funcName,i=t[1],a=t[0],o=r===`\\stackrel`?`mrel`:wK(i),s={type:`op`,mode:i.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,suppressBaseShift:r!==`\\stackrel`,body:bG(i)},c=r===`\\underset`?{type:`supsub`,mode:a.mode,base:s,sub:a}:{type:`supsub`,mode:a.mode,base:s,sup:a};return{type:`mclass`,mode:n.mode,mclass:o,body:[c],isCharacterBox:HH(c)}}}),Z({type:`pmb`,names:[`\\pmb`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`pmb`,mode:e.parser.mode,mclass:wK(t[0]),body:bG(t[0])}},htmlBuilder(e,t){var n=TG(e.body,t,!0),r=X([e.mclass],n,t);return r.style.textShadow=`0.02em 0.01em 0.04px`,r},mathmlBuilder(e,t){var n=new Q(`mstyle`,WG(e.body,t));return n.setAttribute(`style`,`text-shadow: 0.02em 0.01em 0.04px`),n}});var TK={">":`\\\\cdrightarrow`,"<":`\\\\cdleftarrow`,"=":`\\\\cdlongequal`,A:`\\uparrow`,V:`\\downarrow`,"|":`\\Vert`,".":`no arrow`},EK=()=>({type:`styling`,body:[],mode:`math`,style:`display`,resetFont:!0}),DK=e=>e.type===`textord`&&e.text===`@`,OK=(e,t)=>(e.type===`mathord`||e.type===`atom`)&&e.text===t;function kK(e,t,n){var r=TK[e];switch(r){case`\\\\cdrightarrow`:case`\\\\cdleftarrow`:return n.callFunction(r,[t[0]],[t[1]]);case`\\uparrow`:case`\\downarrow`:var i=n.callFunction(`\\\\cdleft`,[t[0]],[]),a={type:`atom`,text:r,mode:`math`,family:`rel`},o={type:`ordgroup`,mode:`math`,body:[i,n.callFunction(`\\Big`,[a],[]),n.callFunction(`\\\\cdright`,[t[1]],[])]};return n.callFunction(`\\\\cdparent`,[o],[]);case`\\\\cdlongequal`:return n.callFunction(`\\\\cdlongequal`,[],[]);case`\\Vert`:return n.callFunction(`\\Big`,[{type:`textord`,text:`\\Vert`,mode:`math`}],[]);default:return{type:`textord`,text:` `,mode:`math`}}}function AK(e){var t=[];for(e.gullet.beginGroup(),e.gullet.macros.set(`\\cr`,`\\\\\\relax`),e.gullet.beginGroup();;){t.push(e.parseExpression(!1,`\\\\`)),e.gullet.endGroup(),e.gullet.beginGroup();var n=e.fetch().text;if(n===`&`||n===`\\\\`)e.consume();else if(n===`\\end`){t[t.length-1].length===0&&t.pop();break}else throw new L(`Expected \\\\ or \\cr or \\end`,e.nextToken)}for(var r=[],i=[r],a=0;aAV`.includes(l))for(var d=0;d<2;d++){for(var f=!0,p=c+1;pAV=|." after @`,o[c])}var m={type:`styling`,body:[kK(l,u,e)],mode:`math`,style:`display`,resetFont:!0};r.push(m),s=EK()}a%2==0?r.push(s):r.shift(),r=[],i.push(r)}return e.gullet.endGroup(),e.gullet.endGroup(),{type:`array`,mode:`math`,body:i,arraystretch:1,addJot:!0,rowGaps:[null],cols:Array(i[0].length).fill({type:`align`,align:`c`,pregap:.25,postgap:.25}),colSeparationType:`CD`,hLinesBeforeRow:Array(i.length+1).fill([])}}Z({type:`cdlabel`,names:[`\\\\cdleft`,`\\\\cdright`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`cdlabel`,mode:n.mode,side:r.slice(4),label:t[0]}},htmlBuilder(e,t){var n=t.havingStyle(t.style.sup()),r=nG(jG(e.label,n,t),t);return r.classes.push(`cd-label-`+e.side),r.style.bottom=z(.8-r.depth),r.height=0,r.depth=0,r},mathmlBuilder(e,t){var n=new Q(`mrow`,[KG(e.label,t)]);return n=new Q(`mpadded`,[n]),n.setAttribute(`width`,`0`),e.side===`left`&&n.setAttribute(`lspace`,`-1width`),n.setAttribute(`voffset`,`0.7em`),n=new Q(`mstyle`,[n]),n.setAttribute(`displaystyle`,`false`),n.setAttribute(`scriptlevel`,`1`),n}}),Z({type:`cdlabelparent`,names:[`\\\\cdparent`],numArgs:1,handler(e,t){return{type:`cdlabelparent`,mode:e.parser.mode,fragment:t[0]}},htmlBuilder(e,t){var n=nG(jG(e.fragment,t),t);return n.classes.push(`cd-vert-arrow`),n},mathmlBuilder(e,t){return new Q(`mrow`,[KG(e.fragment,t)])}}),Z({type:`textord`,names:[`\\@char`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=gK(pK(t[0],`ordgroup`),`\\@char has non-numeric argument`),i=parseInt(r),a;if(isNaN(i))throw new L(`\\@char has non-numeric argument `+r);if(i<0||i>1114111)throw new L(`\\@char with invalid code point `+r);return i<=65535?a=String.fromCharCode(i):(i-=65536,a=String.fromCharCode((i>>10)+55296,(i&1023)+56320)),{type:`textord`,mode:n.mode,text:a}}}),Z({type:`color`,names:[`\\textcolor`],numArgs:2,allowedInText:!0,argTypes:[`color`,`original`],handler(e,t){var n=e.parser,r=pK(t[0],`color-token`).color,i=t[1];return{type:`color`,mode:n.mode,color:r,body:bG(i)}},htmlBuilder:(e,t)=>tG(TG(e.body,t.withColor(e.color),!1)),mathmlBuilder:(e,t)=>{var n=new Q(`mstyle`,WG(e.body,t.withColor(e.color)));return n.setAttribute(`mathcolor`,e.color),n}}),Z({type:`color`,names:[`\\color`],numArgs:1,allowedInText:!0,argTypes:[`color`],handler(e,t){var n=e.parser,r=e.breakOnTokenText,i=pK(t[0],`color-token`).color;n.gullet.macros.set(`\\current@color`,i);var a=n.parseExpression(!0,r);return{type:`color`,mode:n.mode,color:i,body:a}}}),Z({type:`cr`,names:[`\\\\`],numArgs:0,numOptionalArgs:0,allowedInText:!0,handler(e,t,n){var r=e.parser,i=r.gullet.future().text===`[`?r.parseSizeGroup(!0):null,a=!r.settings.displayMode||!r.settings.useStrictBehavior(`newLineInDisplayMode`,`In LaTeX, \\\\ or \\newline does nothing in display mode`);return{type:`cr`,mode:r.mode,newLine:a,size:i&&pK(i,`size`).value}},htmlBuilder(e,t){var n=X([`mspace`],[],t);return e.newLine&&(n.classes.push(`katex-newline`),e.size&&(n.style.marginTop=z(NU(e.size,t)))),n},mathmlBuilder(e,t){var n=new Q(`mspace`);return e.newLine&&(n.setAttribute(`linebreak`,`newline`),e.size&&n.setAttribute(`height`,z(NU(e.size,t)))),n}});var jK={"\\global":`\\global`,"\\long":`\\\\globallong`,"\\\\globallong":`\\\\globallong`,"\\def":`\\gdef`,"\\gdef":`\\gdef`,"\\edef":`\\xdef`,"\\xdef":`\\xdef`,"\\let":`\\\\globallet`,"\\futurelet":`\\\\globalfuture`},MK=e=>{var t=e.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(t))throw new L(`Expected a control sequence`,e);return t},NK=e=>{var t=e.gullet.popToken();return t.text===`=`&&(t=e.gullet.popToken(),t.text===` `&&(t=e.gullet.popToken())),t},PK=(e,t,n,r)=>{var i=e.gullet.macros.get(n.text);i??=(n.noexpand=!0,{tokens:[n],numArgs:0,unexpandable:!e.gullet.isExpandable(n.text)}),e.gullet.macros.set(t,i,r)};Z({type:`internal`,names:[`\\global`,`\\long`,`\\\\globallong`],numArgs:0,allowedInText:!0,handler(e){var t=e.parser,n=e.funcName;t.consumeSpaces();var r=t.fetch();if(jK[r.text])return(n===`\\global`||n===`\\\\globallong`)&&(r.text=jK[r.text]),pK(t.parseFunction(),`internal`);throw new L(`Invalid token after macro prefix`,r)}}),Z({type:`internal`,names:[`\\def`,`\\gdef`,`\\edef`,`\\xdef`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=t.gullet.popToken(),i=r.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(i))throw new L(`Expected a control sequence`,r);for(var a=0,o,s=[[]];t.gullet.future().text!==`{`;)if(r=t.gullet.popToken(),r.text===`#`){if(t.gullet.future().text===`{`){o=t.gullet.future(),s[a].push(`{`);break}if(r=t.gullet.popToken(),!/^[1-9]$/.test(r.text))throw new L(`Invalid argument number "`+r.text+`"`);if(parseInt(r.text)!==a+1)throw new L(`Argument number "`+r.text+`" out of order`);a++,s.push([])}else if(r.text===`EOF`)throw new L(`Expected a macro definition`);else s[a].push(r.text);var c=t.gullet.consumeArg().tokens;return o&&c.unshift(o),(n===`\\edef`||n===`\\xdef`)&&(c=t.gullet.expandTokens(c),c.reverse()),t.gullet.macros.set(i,{tokens:c,numArgs:a,delimiters:s},n===jK[n]),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\let`,`\\\\globallet`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=MK(t.gullet.popToken());return t.gullet.consumeSpaces(),PK(t,r,NK(t),n===`\\\\globallet`),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\futurelet`,`\\\\globalfuture`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=MK(t.gullet.popToken()),i=t.gullet.popToken(),a=t.gullet.popToken();return PK(t,r,a,n===`\\\\globalfuture`),t.gullet.pushToken(a),t.gullet.pushToken(i),{type:`internal`,mode:t.mode}}});var FK=function(e,t,n){var r=tW(iW.math[e]&&iW.math[e].replace||e,t,n);if(!r)throw Error(`Unsupported symbol `+e+` and font size `+t+`.`);return r},IK=function(e,t,n,r){var i=n.havingBaseStyle(t),a=X(r.concat(i.sizingClasses(n)),[e],n),o=i.sizeMultiplier/n.sizeMultiplier;return a.height*=o,a.depth*=o,a.maxFontSize=i.sizeMultiplier,a},LK=function(e,t,n){var r=t.havingBaseStyle(n),i=(1-t.sizeMultiplier/r.sizeMultiplier)*t.fontMetrics().axisHeight;e.classes.push(`delimcenter`),e.style.top=z(i),e.height-=i,e.depth+=i},RK=function(e,t,n,r,i,a){var o=IK(GW(e,`Main-Regular`,i,r),t,r,a);return n&&LK(o,r,t),o},zK=function(e,t,n,r){return GW(e,`Size`+t+`-Regular`,n,r)},BK=function(e,t,n,r,i,a){var o=zK(e,t,i,r),s=IK(X([`delimsizing`,`size`+t],[o],r),R.TEXT,r,a);return n&&LK(s,r,R.TEXT),s},VK=function(e,t,n){return{type:`elem`,elem:X([`delimsizinginner`,t===`Size1-Regular`?`delim-size1`:`delim-size4`],[X([],[GW(e,t,n)])])}},HK=function(e,t,n){var r=ZU[`Size4-Regular`][e.charCodeAt(0)]?ZU[`Size4-Regular`][e.charCodeAt(0)][4]:ZU[`Size1-Regular`][e.charCodeAt(0)][4],i=QW([],[new GU([new KU(`inner`,TU(e,Math.round(1e3*t)))],{width:z(r),height:z(t),style:`width:`+z(r),viewBox:`0 0 `+1e3*r+` `+Math.round(1e3*t),preserveAspectRatio:`xMinYMin`})],n);return i.height=t,i.style.height=z(t),i.style.width=z(r),{type:`elem`,elem:i}},UK=.008,WK={type:`kern`,size:-1*UK},GK=new Set([`|`,`\\lvert`,`\\rvert`,`\\vert`]),KK=new Set([`\\|`,`\\lVert`,`\\rVert`,`\\Vert`]),qK=function(e,t,n,r,i,a){var o,s,c,l,u=``,d=0;o=c=l=e,s=null;var f=`Size1-Regular`;e===`\\uparrow`?c=l=`⏐`:e===`\\Uparrow`?c=l=`‖`:e===`\\downarrow`?o=c=`⏐`:e===`\\Downarrow`?o=c=`‖`:e===`\\updownarrow`?(o=`\\uparrow`,c=`⏐`,l=`\\downarrow`):e===`\\Updownarrow`?(o=`\\Uparrow`,c=`‖`,l=`\\Downarrow`):GK.has(e)?(c=`∣`,u=`vert`,d=333):KK.has(e)?(c=`∥`,u=`doublevert`,d=556):e===`[`||e===`\\lbrack`?(o=`⎡`,c=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lbrack`,d=667):e===`]`||e===`\\rbrack`?(o=`⎤`,c=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rbrack`,d=667):e===`\\lfloor`||e===`⌊`?(c=o=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lfloor`,d=667):e===`\\lceil`||e===`⌈`?(o=`⎡`,c=l=`⎢`,f=`Size4-Regular`,u=`lceil`,d=667):e===`\\rfloor`||e===`⌋`?(c=o=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rfloor`,d=667):e===`\\rceil`||e===`⌉`?(o=`⎤`,c=l=`⎥`,f=`Size4-Regular`,u=`rceil`,d=667):e===`(`||e===`\\lparen`?(o=`⎛`,c=`⎜`,l=`⎝`,f=`Size4-Regular`,u=`lparen`,d=875):e===`)`||e===`\\rparen`?(o=`⎞`,c=`⎟`,l=`⎠`,f=`Size4-Regular`,u=`rparen`,d=875):e===`\\{`||e===`\\lbrace`?(o=`⎧`,s=`⎨`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\}`||e===`\\rbrace`?(o=`⎫`,s=`⎬`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lgroup`||e===`⟮`?(o=`⎧`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\rgroup`||e===`⟯`?(o=`⎫`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lmoustache`||e===`⎰`?(o=`⎧`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):(e===`\\rmoustache`||e===`⎱`)&&(o=`⎫`,l=`⎩`,c=`⎪`,f=`Size4-Regular`);var p=FK(o,f,i),m=p.height+p.depth,h=FK(c,f,i),g=h.height+h.depth,_=FK(l,f,i),v=_.height+_.depth,y=0,b=1;if(s!==null){var x=FK(s,f,i);y=x.height+x.depth,b=2}var S=m+v+y,C=S+Math.max(0,Math.ceil((t-S)/(b*g)))*b*g,ee=r.fontMetrics().axisHeight;n&&(ee*=r.sizeMultiplier);var te=C/2-ee,ne=[];if(u.length>0){var re=C-m-v,ie=Math.round(C*1e3),ae=DU(u,Math.round(re*1e3)),oe=new KU(u,ae),se=z(d/1e3),ce=z(ie/1e3),le=QW([],[new GU([oe],{width:se,height:ce,viewBox:`0 0 `+d+` `+ie})],r);le.height=ie/1e3,le.style.width=se,le.style.height=ce,ne.push({type:`elem`,elem:le})}else{if(ne.push(VK(l,f,i)),ne.push(WK),s===null){var ue=C-m-v+2*UK;ne.push(HK(c,ue,r))}else{var de=(C-m-v-y)/2+2*UK;ne.push(HK(c,de,r)),ne.push(WK),ne.push(VK(s,f,i)),ne.push(WK),ne.push(HK(c,de,r))}ne.push(WK),ne.push(VK(o,f,i))}var fe=r.havingBaseStyle(R.TEXT);return IK(X([`delimsizing`,`mult`],[iG({positionType:`bottom`,positionData:te,children:ne})],fe),R.TEXT,r,a)},JK=80,YK=.08,XK=function(e,t,n,r,i){return QW([`hide-tail`],[new GU([new KU(e,wU(e,r,n))],{width:`400em`,height:z(t),viewBox:`0 0 400000 `+n,preserveAspectRatio:`xMinYMin slice`})],i)},ZK=function(e,t){var n=t.havingBaseSizing(),r=sq(`\\surd`,e*n.sizeMultiplier,aq,n),i=n.sizeMultiplier,a=Math.max(0,t.minRuleThickness-t.fontMetrics().sqrtRuleThickness),o,s,c,l,u;return r.type===`small`?(l=1e3+1e3*a+JK,e<1?i=1:e<1.4&&(i=.7),s=(1+a+YK)/i,c=(1+a)/i,o=XK(`sqrtMain`,s,l,a,t),o.style.minWidth=`0.853em`,u=.833/i):r.type===`large`?(l=(1e3+JK)*tq[r.size],c=(tq[r.size]+a)/i,s=(tq[r.size]+a+YK)/i,o=XK(`sqrtSize`+r.size,s,l,a,t),o.style.minWidth=`1.02em`,u=1/i):(s=e+a+YK,c=e+a,l=Math.floor(1e3*e+a)+JK,o=XK(`sqrtTall`,s,l,a,t),o.style.minWidth=`0.742em`,u=1.056),o.height=c,o.style.height=z(s),{span:o,advanceWidth:u,ruleWidth:(t.fontMetrics().sqrtRuleThickness+a)*i}},QK=new Set([`(`,`\\lparen`,`)`,`\\rparen`,`[`,`\\lbrack`,`]`,`\\rbrack`,`\\{`,`\\lbrace`,`\\}`,`\\rbrace`,`\\lfloor`,`\\rfloor`,`⌊`,`⌋`,`\\lceil`,`\\rceil`,`⌈`,`⌉`,`\\surd`]),$K=new Set([`\\uparrow`,`\\downarrow`,`\\updownarrow`,`\\Uparrow`,`\\Downarrow`,`\\Updownarrow`,`|`,`\\|`,`\\vert`,`\\Vert`,`\\lvert`,`\\rvert`,`\\lVert`,`\\rVert`,`\\lgroup`,`\\rgroup`,`⟮`,`⟯`,`\\lmoustache`,`\\rmoustache`,`⎰`,`⎱`]),eq=new Set([`<`,`>`,`\\langle`,`\\rangle`,`/`,`\\backslash`,`\\lt`,`\\gt`]),tq=[0,1.2,1.8,2.4,3],nq=function(e,t,n,r,i){if(e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`),QK.has(e)||eq.has(e))return BK(e,t,!1,n,r,i);if($K.has(e))return qK(e,tq[t],!1,n,r,i);throw new L(`Illegal delimiter: '`+e+`'`)},rq=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4}],iq=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`stack`}],aq=[{type:`small`,style:R.SCRIPTSCRIPT},{type:`small`,style:R.SCRIPT},{type:`small`,style:R.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4},{type:`stack`}],oq=function(e){if(e.type===`small`)return`Main-Regular`;if(e.type===`large`)return`Size`+e.size+`-Regular`;if(e.type===`stack`)return`Size4-Regular`;var t=e.type;throw Error(`Add support for delim type '`+t+`' here.`)},sq=function(e,t,n,r){for(var i=Math.min(2,3-r.style.size);it)return a}return n[n.length-1]},cq=function(e,t,n,r,i,a){e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`);var o=eq.has(e)?rq:QK.has(e)?aq:iq,s=sq(e,t,o,r);return s.type===`small`?RK(e,s.style,n,r,i,a):s.type===`large`?BK(e,s.size,n,r,i,a):qK(e,t,n,r,i,a)},lq=function(e,t,n,r,i,a){var o=r.fontMetrics().axisHeight*r.sizeMultiplier,s=901,c=5/r.fontMetrics().ptPerEm,l=Math.max(t-o,n+o);return cq(e,Math.max(l/500*s,2*l-c),!0,r,i,a)},uq={"\\bigl":{mclass:`mopen`,size:1},"\\Bigl":{mclass:`mopen`,size:2},"\\biggl":{mclass:`mopen`,size:3},"\\Biggl":{mclass:`mopen`,size:4},"\\bigr":{mclass:`mclose`,size:1},"\\Bigr":{mclass:`mclose`,size:2},"\\biggr":{mclass:`mclose`,size:3},"\\Biggr":{mclass:`mclose`,size:4},"\\bigm":{mclass:`mrel`,size:1},"\\Bigm":{mclass:`mrel`,size:2},"\\biggm":{mclass:`mrel`,size:3},"\\Biggm":{mclass:`mrel`,size:4},"\\big":{mclass:`mord`,size:1},"\\Big":{mclass:`mord`,size:2},"\\bigg":{mclass:`mord`,size:3},"\\Bigg":{mclass:`mord`,size:4}},dq=new Set(`(,\\lparen,),\\rparen,[,\\lbrack,],\\rbrack,\\{,\\lbrace,\\},\\rbrace,\\lfloor,\\rfloor,⌊,⌋,\\lceil,\\rceil,⌈,⌉,<,>,\\langle,⟨,\\rangle,⟩,\\lt,\\gt,\\lvert,\\rvert,\\lVert,\\rVert,\\lgroup,\\rgroup,⟮,⟯,\\lmoustache,\\rmoustache,⎰,⎱,/,\\backslash,|,\\vert,\\|,\\Vert,\\uparrow,\\Uparrow,\\downarrow,\\Downarrow,\\updownarrow,\\Updownarrow,.`.split(`,`));function fq(e){return`isMiddle`in e}function pq(e,t){var n=hK(e);if(n&&dq.has(n.text))return n;throw n?new L(`Invalid delimiter '`+n.text+`' after '`+t.funcName+`'`,e):new L(`Invalid delimiter type '`+e.type+`'`,e)}Z({type:`delimsizing`,names:[`\\bigl`,`\\Bigl`,`\\biggl`,`\\Biggl`,`\\bigr`,`\\Bigr`,`\\biggr`,`\\Biggr`,`\\bigm`,`\\Bigm`,`\\biggm`,`\\Biggm`,`\\big`,`\\Big`,`\\bigg`,`\\Bigg`],numArgs:1,argTypes:[`primitive`],handler:(e,t)=>{var n=pq(yG(t[0]),e);return{type:`delimsizing`,mode:e.parser.mode,size:uq[e.funcName].size,mclass:uq[e.funcName].mclass,delim:n.text}},htmlBuilder:(e,t)=>e.delim===`.`?X([e.mclass]):nq(e.delim,e.size,t,e.mode,[e.mclass]),mathmlBuilder:e=>{var t=[];e.delim!==`.`&&t.push(zG(e.delim,e.mode));var n=new Q(`mo`,t);e.mclass===`mopen`||e.mclass===`mclose`?n.setAttribute(`fence`,`true`):n.setAttribute(`fence`,`false`),n.setAttribute(`stretchy`,`true`);var r=z(tq[e.size]);return n.setAttribute(`minsize`,r),n.setAttribute(`maxsize`,r),n}});function mq(e){if(!e.body)throw Error(`Bug: The leftright ParseNode wasn't fully parsed.`)}Z({type:`leftright-right`,names:[`\\right`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser.gullet.macros.get(`\\current@color`);if(n&&typeof n!=`string`)throw new L(`\\current@color set to non-string in \\right`);return{type:`leftright-right`,mode:e.parser.mode,delim:pq(t[0],e).text,color:n}}}),Z({type:`leftright`,names:[`\\left`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=pq(t[0],e),r=e.parser;++r.leftrightDepth;var i=r.parseExpression(!1);--r.leftrightDepth,r.expect(`\\right`,!1);var a=pK(r.parseFunction(),`leftright-right`);return{type:`leftright`,mode:r.mode,body:i,left:n.text,right:a.delim,rightColor:a.color}},htmlBuilder:(e,t)=>{mq(e);for(var n=TG(e.body,t,!0,[`mopen`,`mclose`]),r=0,i=0,a=!1,o=0;o{mq(e);var n=WG(e.body,t);if(e.left!==`.`){var r=new Q(`mo`,[zG(e.left,e.mode)]);r.setAttribute(`fence`,`true`),n.unshift(r)}if(e.right!==`.`){var i=new Q(`mo`,[zG(e.right,e.mode)]);i.setAttribute(`fence`,`true`),e.rightColor&&i.setAttribute(`mathcolor`,e.rightColor),n.push(i)}return BG(n)}}),Z({type:`middle`,names:[`\\middle`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=pq(t[0],e);if(!e.parser.leftrightDepth)throw new L(`\\middle without preceding \\left`,n);return{type:`middle`,mode:e.parser.mode,delim:n.text}},htmlBuilder:(e,t)=>{var n;return e.delim===`.`?n=AG(t,[]):(n=nq(e.delim,1,t,e.mode,[]),n.isMiddle={delim:e.delim,options:t}),n},mathmlBuilder:(e,t)=>{var n=new Q(`mo`,[e.delim===`\\vert`||e.delim===`|`?zG(`|`,`text`):zG(e.delim,e.mode)]);return n.setAttribute(`fence`,`true`),n.setAttribute(`lspace`,`0.05em`),n.setAttribute(`rspace`,`0.05em`),n}}),Z({type:`enclose`,names:[`\\colorbox`],numArgs:2,allowedInText:!0,argTypes:[`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=pK(t[0],`color-token`).color,o=t[1];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:a,body:o}},htmlBuilder:(e,t)=>{var n=nG(jG(e.body,t),t),r=e.label.slice(1),i=t.sizeMultiplier,a,o,s=HH(e.body);if(r===`sout`)a=X([`katex-stretchy`,`katex-sout`]),a.height=t.fontMetrics().defaultRuleThickness/i,o=-.5*t.fontMetrics().xHeight;else if(r===`phase`){var c=NU({number:.6,unit:`pt`},t),l=NU({number:.35,unit:`ex`},t),u=t.havingBaseSizing();i/=u.sizeMultiplier;var d=n.height+n.depth+c+l;n.style.paddingLeft=z(d/2+c);var f=Math.floor(1e3*d*i);a=QW([`hide-tail`],[new GU([new KU(`phase`,SU(f))],{width:`400em`,height:z(f/1e3),viewBox:`0 0 400000 `+f,preserveAspectRatio:`xMinYMin slice`})],t),a.style.height=z(d),o=n.depth+c+l}else{/cancel/.test(r)?s||n.classes.push(`cancel-pad`):r===`angl`?n.classes.push(`anglpad`):n.classes.push(`boxpad`);var p,m,h=0;/box/.test(r)?(h=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness),p=t.fontMetrics().fboxsep+(r===`colorbox`?0:h),m=p):r===`angl`?(h=Math.max(t.fontMetrics().defaultRuleThickness,t.minRuleThickness),p=4*h,m=Math.max(0,.25-n.depth)):(p=s?.2:0,m=p),a=sK(n,r,p,m,t),/fbox|boxed|fcolorbox/.test(r)?(a.style.borderStyle=`solid`,a.style.borderWidth=z(h)):r===`angl`&&h!==.049&&(a.style.borderTopWidth=z(h),a.style.borderRightWidth=z(h)),o=n.depth+m,e.backgroundColor&&(a.style.backgroundColor=e.backgroundColor,e.borderColor&&(a.style.borderColor=e.borderColor))}var g;if(e.backgroundColor)g=iG({positionType:`individualShift`,children:[{type:`elem`,elem:a,shift:o},{type:`elem`,elem:n,shift:0}]});else{var _=/cancel|phase/.test(r)?[`svg-align`]:[];g=iG({positionType:`individualShift`,children:[{type:`elem`,elem:n,shift:0},{type:`elem`,elem:a,shift:o,wrapperClasses:_}]})}return/cancel/.test(r)&&(g.height=n.height,g.depth=n.depth),/cancel/.test(r)&&!s?X([`mord`,`cancel-lap`],[g],t):X([`mord`],[g],t)},mathmlBuilder:(e,t)=>{var n,r=new Q(e.label.includes(`colorbox`)?`mpadded`:`menclose`,[KG(e.body,t)]);switch(e.label){case`\\cancel`:r.setAttribute(`notation`,`updiagonalstrike`);break;case`\\bcancel`:r.setAttribute(`notation`,`downdiagonalstrike`);break;case`\\phase`:r.setAttribute(`notation`,`phasorangle`);break;case`\\sout`:r.setAttribute(`notation`,`horizontalstrike`);break;case`\\fbox`:r.setAttribute(`notation`,`box`);break;case`\\angl`:r.setAttribute(`notation`,`actuarial`);break;case`\\fcolorbox`:case`\\colorbox`:if(n=t.fontMetrics().fboxsep*t.fontMetrics().ptPerEm,r.setAttribute(`width`,`+`+2*n+`pt`),r.setAttribute(`height`,`+`+2*n+`pt`),r.setAttribute(`lspace`,n+`pt`),r.setAttribute(`voffset`,n+`pt`),e.label===`\\fcolorbox`){var i=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness);r.setAttribute(`style`,`border: `+z(i)+` solid `+e.borderColor)}break;case`\\xcancel`:r.setAttribute(`notation`,`updiagonalstrike downdiagonalstrike`)}return e.backgroundColor&&r.setAttribute(`mathbackground`,e.backgroundColor),r}}),Z({type:`enclose`,names:[`\\fcolorbox`],numArgs:3,allowedInText:!0,argTypes:[`color`,`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=pK(t[0],`color-token`).color,o=pK(t[1],`color-token`).color,s=t[2];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:o,borderColor:a,body:s}}}),Z({type:`enclose`,names:[`\\fbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\fbox`,body:t[0]}}}),Z({type:`enclose`,names:[`\\cancel`,`\\bcancel`,`\\xcancel`,`\\phase`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\sout`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName;n.mode===`math`&&n.settings.reportNonstrict(`mathVsSout`,`LaTeX's \\sout works only in text mode`);var i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\angl`],numArgs:1,argTypes:[`hbox`],allowedInText:!1,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\angl`,body:t[0]}}});var hq={};function gq(e){for(var t=e.type,n=e.names,r=e.props,i=e.handler,a=e.htmlBuilder,o=e.mathmlBuilder,s={type:t,numArgs:r.numArgs||0,allowedInText:!1,numOptionalArgs:0,handler:i},c=0;c{if(!e.parser.settings.displayMode)throw new L(`{`+e.envName+`} can be used only in display mode.`)},Sq=new Set([`gather`,`gather*`]);function Cq(e){if(!e.includes(`ed`))return!e.includes(`*`)}function wq(e,t,n){var r=t.hskipBeforeAndAfter,i=t.addJot,a=t.cols,o=t.arraystretch,s=t.colSeparationType,c=t.autoTag,l=t.singleRow,u=t.emptySingleRow,d=t.maxNumCols,f=t.leqno;if(e.gullet.beginGroup(),l||e.gullet.macros.set(`\\cr`,`\\\\\\relax`),!o){var p=e.gullet.expandMacroAsText(`\\arraystretch`);if(p==null)o=1;else if(o=parseFloat(p),!o||o<0)throw new L(`Invalid \\arraystretch: `+p)}e.gullet.beginGroup();var m=[],h=[m],g=[],_=[],v=c==null?void 0:[];function y(){c&&e.gullet.macros.set(`\\@eqnsw`,`1`,!0)}function b(){v&&(e.gullet.macros.get(`\\df@tag`)?(v.push(e.subparse([new yq(`\\df@tag`)])),e.gullet.macros.set(`\\df@tag`,void 0,!0)):v.push(!!c&&e.gullet.macros.get(`\\@eqnsw`)===`1`))}for(y(),_.push(bq(e));;){var x=e.parseExpression(!1,l?`\\end`:`\\\\`);e.gullet.endGroup(),e.gullet.beginGroup();var S={type:`ordgroup`,mode:e.mode,body:x};n&&(S={type:`styling`,mode:e.mode,style:n,resetFont:!0,body:[S]}),m.push(S);var C=e.fetch().text;if(C===`&`){if(d&&m.length===d){if(l||s)throw new L(`Too many tab characters: &`,e.nextToken);e.settings.reportNonstrict(`textEnv`,`Too few columns specified in the {array} column argument.`)}e.consume()}else if(C===`\\end`){b(),m.length===1&&S.type===`styling`&&S.body.length===1&&S.body[0].type===`ordgroup`&&S.body[0].body.length===0&&(h.length>1||!u)&&!Array.isArray(v?.[v.length-1])&&!(c&&v?.[v.length-1]===!0)&&h.pop(),_.length0&&(_+=.25),c.push({pos:_,isDashed:e[t]})}for(v(a[0]),n=0;n0&&(te+=g,xe))for(n=0;n=o)){var ve=void 0;(r>0||e.hskipBeforeAndAfter)&&(ve=fe?.pregap??d,ve!==0&&(ae=X([`arraycolsep`],[]),ae.style.width=z(ve),ie.push(ae)));var ye=[];for(n=0;n0){for(var Ee=$W(`katex-hline`,t,l),De=$W(`katex-hdashline`,t,l),Oe=[{type:`elem`,elem:Te,shift:0}];c.length>0;){var ke=c.pop(),Ae=ke.pos-ne;ke.isDashed?Oe.push({type:`elem`,elem:De,shift:Ae}):Oe.push({type:`elem`,elem:Ee,shift:Ae})}Te=iG({positionType:`individualShift`,children:Oe})}if(se.length===0)return X([`mord`],[Te],t);var je=X([`katex-tag`],[iG({positionType:`individualShift`,children:se})],t);return tG([Te,je])},Dq={c:`center `,l:`left `,r:`right `},Oq=function(e,t){for(var n=[],r=new Q(`mtd`,[],[`mtr-glue`]),i=new Q(`mtd`,[],[`mml-eqn-num`]),a=0;a0){var p=e.cols,m=``,h=!1,g=0,_=p.length;p[0].type===`separator`&&(d+=`top `,g=1),p[p.length-1].type===`separator`&&(d+=`bottom `,--_);for(var v=g;v<_;v++){var y=p[v];y.type===`align`?(f+=Dq[y.align],h&&(m+=`none `),h=!0):y.type===`separator`&&(h&&=(m+=y.separator===`|`?`solid `:`dashed `,!1))}l.setAttribute(`columnalign`,f.trim()),/[sd]/.test(m)&&l.setAttribute(`columnlines`,m.trim())}if(e.colSeparationType===`align`){for(var b=e.cols||[],x=``,S=1;S0?`left `:``,d+=ee[ee.length-1].length>0?`right `:``;for(var te=1;te0&&u&&(p=1),n[d]={type:`align`,align:f,pregap:p,postgap:0}}return i.colSeparationType=u?`align`:`alignat`,i};gq({type:`array`,names:[`array`,`darray`],props:{numArgs:1},handler(e,t){var n=(hK(t[0])?[t[0]]:pK(t[0],`ordgroup`).body).map(function(e){var t=mK(e).text;if(`lcr`.includes(t))return{type:`align`,align:t};if(t===`|`)return{type:`separator`,separator:`|`};if(t===`:`)return{type:`separator`,separator:`:`};throw new L(`Unknown column alignment: `+t,e)}),r={cols:n,hskipBeforeAndAfter:!0,maxNumCols:n.length};return wq(e.parser,r,Tq(e.envName))},htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`matrix`,`pmatrix`,`bmatrix`,`Bmatrix`,`vmatrix`,`Vmatrix`,`matrix*`,`pmatrix*`,`bmatrix*`,`Bmatrix*`,`vmatrix*`,`Vmatrix*`],props:{numArgs:0},handler(e){var t={matrix:null,pmatrix:[`(`,`)`],bmatrix:[`[`,`]`],Bmatrix:[`\\{`,`\\}`],vmatrix:[`|`,`|`],Vmatrix:[`\\Vert`,`\\Vert`]}[e.envName.replace(`*`,``)],n=`c`,r={hskipBeforeAndAfter:!1,cols:[{type:`align`,align:n}]};if(e.envName.charAt(e.envName.length-1)===`*`){var i=e.parser;if(i.consumeSpaces(),i.fetch().text===`[`){if(i.consume(),i.consumeSpaces(),n=i.fetch().text,!`lcr`.includes(n))throw new L(`Expected l or c or r`,i.nextToken);i.consume(),i.consumeSpaces(),i.expect(`]`),i.consume(),r.cols=[{type:`align`,align:n}]}}var a=wq(e.parser,r,Tq(e.envName)),o=Math.max(0,...a.body.map(e=>e.length));return a.cols=Array(o).fill({type:`align`,align:n}),t?{type:`leftright`,mode:e.mode,body:[a],left:t[0],right:t[1],rightColor:void 0}:a},htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`smallmatrix`],props:{numArgs:0},handler(e){var t=wq(e.parser,{arraystretch:.5},`script`);return t.colSeparationType=`small`,t},htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`subarray`],props:{numArgs:1},handler(e,t){var n=(hK(t[0])?[t[0]]:pK(t[0],`ordgroup`).body).map(function(e){var t=mK(e).text;if(`lc`.includes(t))return{type:`align`,align:t};throw new L(`Unknown column alignment: `+t,e)});if(n.length>1)throw new L(`{subarray} can contain only one column`);var r={cols:n,hskipBeforeAndAfter:!1,arraystretch:.5},i=wq(e.parser,r,`script`);if(i.body.length>0&&i.body[0].length>1)throw new L(`{subarray} can contain only one column`);return i},htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`cases`,`dcases`,`rcases`,`drcases`],props:{numArgs:0},handler(e){var t=wq(e.parser,{arraystretch:1.2,cols:[{type:`align`,align:`l`,pregap:0,postgap:1},{type:`align`,align:`l`,pregap:0,postgap:0}]},Tq(e.envName));return{type:`leftright`,mode:e.mode,body:[t],left:e.envName.includes(`r`)?`.`:`\\{`,right:e.envName.includes(`r`)?`\\}`:`.`,rightColor:void 0}},htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`align`,`align*`,`aligned`,`split`],props:{numArgs:0},handler:kq,htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`gathered`,`gather`,`gather*`],props:{numArgs:0},handler(e){Sq.has(e.envName)&&xq(e);var t={cols:[{type:`align`,align:`c`}],addJot:!0,colSeparationType:`gather`,autoTag:Cq(e.envName),emptySingleRow:!0,leqno:e.parser.settings.leqno};return wq(e.parser,t,`display`)},htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`alignat`,`alignat*`,`alignedat`],props:{numArgs:1},handler:kq,htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`equation`,`equation*`],props:{numArgs:0},handler(e){xq(e);var t={autoTag:Cq(e.envName),emptySingleRow:!0,singleRow:!0,maxNumCols:1,leqno:e.parser.settings.leqno};return wq(e.parser,t,`display`)},htmlBuilder:Eq,mathmlBuilder:Oq}),gq({type:`array`,names:[`CD`],props:{numArgs:0},handler(e){return xq(e),AK(e.parser)},htmlBuilder:Eq,mathmlBuilder:Oq}),$(`\\nonumber`,`\\gdef\\@eqnsw{0}`),$(`\\notag`,`\\nonumber`),Z({type:`text`,names:[`\\hline`,`\\hdashline`],numArgs:0,allowedInText:!0,allowedInMath:!0,handler(e,t){throw new L(e.funcName+` valid only within array environment`)}});var Aq=hq;Z({type:`environment`,names:[`\\begin`,`\\end`],numArgs:1,argTypes:[`text`],handler(e,t){var n=e.parser,r=e.funcName,i=t[0];if(i.type!==`ordgroup`)throw new L(`Invalid environment name`,i);var a=gK(i,`Environment name should contain only text characters and spaces`,!0);if(r===`\\begin`){if(!Object.prototype.hasOwnProperty.call(Aq,a))throw new L(`No such environment: `+a,i);var o=Aq[a],s=n.parseArguments(`\\begin{`+a+`}`,o),c=s.args,l=s.optArgs,u={mode:n.mode,envName:a,parser:n},d=o.handler(u,c,l);n.expect(`\\end`,!1);var f=n.nextToken,p=pK(n.parseFunction(),`environment`);if(p.name!==a)throw new L(`Mismatch: \\begin{`+a+`} matched by \\end{`+p.name+`}`,f);return d}return{type:`environment`,mode:n.mode,name:a,nameGroup:i}}});var jq=(e,t)=>{var n=e.font,r=t.withFont(n);return jG(e.body,r)},Mq=(e,t)=>{var n=e.font,r=t.withFont(n);return KG(e.body,r)},Nq={"\\Bbb":`\\mathbb`,"\\bold":`\\mathbf`,"\\frak":`\\mathfrak`};Z({type:`font`,names:[`\\mathrm`,`\\mathit`,`\\mathbf`,`\\mathnormal`,`\\mathsfit`,`\\mathbb`,`\\mathcal`,`\\mathfrak`,`\\mathscr`,`\\mathsf`,`\\mathtt`,`\\Bbb`,`\\bold`,`\\frak`],numArgs:1,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=yG(t[0]),a=r in Nq?Nq[r]:r;return{type:`font`,mode:n.mode,font:a.slice(1),body:i}},htmlBuilder:jq,mathmlBuilder:Mq}),Z({type:`mclass`,names:[`\\boldsymbol`,`\\bm`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`mclass`,mode:n.mode,mclass:wK(r),body:[{type:`font`,mode:n.mode,font:`boldsymbol`,body:r}],isCharacterBox:HH(r)}}}),Z({type:`font`,names:[`\\rm`,`\\sf`,`\\tt`,`\\bf`,`\\it`,`\\cal`],numArgs:0,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=e.breakOnTokenText,a=n.mode,o=n.parseExpression(!0,i);return{type:`font`,mode:a,font:`math`+r.slice(1),body:{type:`ordgroup`,mode:n.mode,body:o}}}});var Pq=(e,t)=>{var n=t.style,r=n.fracNum(),i=n.fracDen(),a=t.havingStyle(r),o=jG(e.numer,a,t);if(e.continued){var s=8.5/t.fontMetrics().ptPerEm,c=3.5/t.fontMetrics().ptPerEm;o.height=o.height0?3*f:7*f,h=t.fontMetrics().denom1):(d>0?(p=t.fontMetrics().num2,m=f):(p=t.fontMetrics().num3,m=3*f),h=t.fontMetrics().denom2);var g;if(u){var _=t.fontMetrics().axisHeight;p-o.depth-(_+.5*d){var n=new Q(`mfrac`,[KG(e.numer,t),KG(e.denom,t)]);if(!e.hasBarLine)n.setAttribute(`linethickness`,`0px`);else if(e.barSize){var r=NU(e.barSize,t);n.setAttribute(`linethickness`,z(r))}if(e.leftDelim!=null||e.rightDelim!=null){var i=[];if(e.leftDelim!=null){var a=new Q(`mo`,[new FG(e.leftDelim.replace(`\\`,``))]);a.setAttribute(`fence`,`true`),i.push(a)}if(i.push(n),e.rightDelim!=null){var o=new Q(`mo`,[new FG(e.rightDelim.replace(`\\`,``))]);o.setAttribute(`fence`,`true`),i.push(o)}return BG(i)}return n},Iq=(e,t)=>t?{type:`styling`,mode:e.mode,style:t,body:[e]}:e;Z({type:`genfrac`,names:[`\\cfrac`,`\\dfrac`,`\\frac`,`\\tfrac`,`\\dbinom`,`\\binom`,`\\tbinom`,`\\\\atopfrac`,`\\\\bracefrac`,`\\\\brackfrac`],numArgs:2,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0],a=t[1],o,s=null,c=null;switch(r){case`\\cfrac`:case`\\dfrac`:case`\\frac`:case`\\tfrac`:o=!0;break;case`\\\\atopfrac`:o=!1;break;case`\\dbinom`:case`\\binom`:case`\\tbinom`:o=!1,s=`(`,c=`)`;break;case`\\\\bracefrac`:o=!1,s=`\\{`,c=`\\}`;break;case`\\\\brackfrac`:o=!1,s=`[`,c=`]`;break;default:throw Error(`Unrecognized genfrac command`)}var l=r===`\\cfrac`,u=null;return l||r.startsWith(`\\d`)?u=`display`:r.startsWith(`\\t`)&&(u=`text`),Iq({type:`genfrac`,mode:n.mode,numer:i,denom:a,continued:l,hasBarLine:o,leftDelim:s,rightDelim:c,barSize:null},u)},htmlBuilder:Pq,mathmlBuilder:Fq}),Z({type:`infix`,names:[`\\over`,`\\choose`,`\\atop`,`\\brace`,`\\brack`],numArgs:0,infix:!0,handler(e){var t=e.parser,n=e.funcName,r=e.token,i;switch(n){case`\\over`:i=`\\frac`;break;case`\\choose`:i=`\\binom`;break;case`\\atop`:i=`\\\\atopfrac`;break;case`\\brace`:i=`\\\\bracefrac`;break;case`\\brack`:i=`\\\\brackfrac`;break;default:throw Error(`Unrecognized infix genfrac command`)}return{type:`infix`,mode:t.mode,replaceWith:i,token:r}}});var Lq=[`display`,`text`,`script`,`scriptscript`],Rq=function(e){var t=null;return e.length>0&&(t=e,t=t===`.`?null:t),t};Z({type:`genfrac`,names:[`\\genfrac`],numArgs:6,allowedInArgument:!0,argTypes:[`math`,`math`,`size`,`text`,`math`,`math`],handler(e,t){var n=e.parser,r=t[4],i=t[5],a=yG(t[0]),o=a.type===`atom`&&a.family===`open`?Rq(a.text):null,s=yG(t[1]),c=s.type===`atom`&&s.family===`close`?Rq(s.text):null,l=pK(t[2],`size`),u,d=null;l.isBlank?u=!0:(d=l.value,u=d.number>0);var f=null,p=t[3];if(p.type===`ordgroup`){if(p.body.length>0){var m=pK(p.body[0],`textord`);f=Lq[Number(m.text)]}}else p=pK(p,`textord`),f=Lq[Number(p.text)];return Iq({type:`genfrac`,mode:n.mode,numer:r,denom:i,continued:!1,hasBarLine:u,barSize:d,leftDelim:o,rightDelim:c},f)}}),Z({type:`infix`,names:[`\\above`],numArgs:1,argTypes:[`size`],infix:!0,handler(e,t){var n=e.parser;e.funcName;var r=e.token;return{type:`infix`,mode:n.mode,replaceWith:`\\\\abovefrac`,size:pK(t[0],`size`).value,token:r}}}),Z({type:`genfrac`,names:[`\\\\abovefrac`],numArgs:3,argTypes:[`math`,`size`,`math`],handler:(e,t)=>{var n=e.parser;e.funcName;var r=t[0],i=pK(t[1],`infix`).size;if(!i)throw Error(`\\\\abovefrac expected size, but got `+String(i));var a=t[2],o=i.number>0;return{type:`genfrac`,mode:n.mode,numer:r,denom:a,continued:!1,hasBarLine:o,barSize:i,leftDelim:null,rightDelim:null}}});var zq=(e,t)=>{var n=t.style,r,i;e.type===`supsub`?(r=e.sup?jG(e.sup,t.havingStyle(n.sup()),t):jG(e.sub,t.havingStyle(n.sub()),t),i=pK(e.base,`horizBrace`)):i=pK(e,`horizBrace`);var a=jG(i.base,t.havingBaseStyle(R.DISPLAY)),o=oK(i,t),s=i.isOver?iG({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:.1},{type:`elem`,elem:o,wrapperClasses:[`svg-align`]}]}):iG({positionType:`bottom`,positionData:a.depth+.1+o.height,children:[{type:`elem`,elem:o,wrapperClasses:[`svg-align`]},{type:`kern`,size:.1},{type:`elem`,elem:a}]});if(r){var c=X([`minner`,i.isOver?`mover`:`munder`],[s],t);s=i.isOver?iG({positionType:`firstBaseline`,children:[{type:`elem`,elem:c},{type:`kern`,size:.2},{type:`elem`,elem:r}]}):iG({positionType:`bottom`,positionData:c.depth+.2+r.height+r.depth,children:[{type:`elem`,elem:r},{type:`kern`,size:.2},{type:`elem`,elem:c}]})}return X([`minner`,i.isOver?`mover`:`munder`],[s],t)};Z({type:`horizBrace`,names:[`\\overbrace`,`\\underbrace`,`\\overbracket`,`\\underbracket`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`horizBrace`,mode:n.mode,label:r,isOver:r.includes(`\\over`),base:t[0]}},htmlBuilder:zq,mathmlBuilder:(e,t)=>{var n=rK(e.label);return new Q(e.isOver?`mover`:`munder`,[KG(e.base,t),n])}}),Z({type:`href`,names:[`\\href`],numArgs:2,argTypes:[`url`,`original`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[1],i=pK(t[0],`url`).url;return n.settings.isTrusted({command:`\\href`,url:i})?{type:`href`,mode:n.mode,href:i,body:bG(r)}:n.formatUnsupportedCmd(`\\href`)},htmlBuilder:(e,t)=>{var n=TG(e.body,t,!1);return eG(e.href,[],n,t)},mathmlBuilder:(e,t)=>{var n=GG(e.body,t);return n instanceof Q||(n=new Q(`mrow`,[n])),n.setAttribute(`href`,e.href),n}}),Z({type:`href`,names:[`\\url`],numArgs:1,argTypes:[`url`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=pK(t[0],`url`).url;if(!n.settings.isTrusted({command:`\\url`,url:r}))return n.formatUnsupportedCmd(`\\url`);for(var i=[],a=0;a{var n=e.parser,r=e.funcName;e.token;var i=pK(t[0],`raw`).string,a=t[1];n.settings.strict&&n.settings.reportNonstrict(`htmlExtension`,`HTML extension is disabled on strict mode`);var o,s={};switch(r){case`\\htmlClass`:s.class=i,o={command:`\\htmlClass`,class:i};break;case`\\htmlId`:s.id=i,o={command:`\\htmlId`,id:i};break;case`\\htmlStyle`:s.style=i,o={command:`\\htmlStyle`,style:i};break;case`\\htmlData`:for(var c=`{,}`,l=[],u=``,d=0;d{var n=TG(e.body,t,!1),r=[`enclosing`];e.attributes.class&&r.push(...e.attributes.class.trim().split(/\s+/));var i=X(r,n,t);for(var a of Object.entries(e.attributes)){var o=a[0],s=a[1];o!==`class`&&i.setAttribute(o,s)}return i},mathmlBuilder:(e,t)=>GG(e.body,t)}),Z({type:`htmlmathml`,names:[`\\html@mathml`],numArgs:2,allowedInArgument:!0,allowedInText:!0,handler:(e,t)=>({type:`htmlmathml`,mode:e.parser.mode,html:bG(t[0]),mathml:bG(t[1])}),htmlBuilder:(e,t)=>tG(TG(e.html,t,!1)),mathmlBuilder:(e,t)=>GG(e.mathml,t)});var Bq=function(e){if(/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(e))return{number:+e,unit:`bp`};var t=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(e);if(!t)throw new L(`Invalid size: '`+e+`' in \\includegraphics`);var n={number:+(t[1]+t[2]),unit:t[3]};if(!MU(n))throw new L(`Invalid unit: '`+n.unit+`' in \\includegraphics.`);return n};Z({type:`includegraphics`,names:[`\\includegraphics`],numArgs:1,numOptionalArgs:1,argTypes:[`raw`,`url`],allowedInText:!1,handler:(e,t,n)=>{var r=e.parser,i={number:0,unit:`em`},a={number:.9,unit:`em`},o={number:0,unit:`em`},s=``;if(n[0])for(var c=pK(n[0],`raw`).string.split(`,`),l=0;l{var n=NU(e.height,t),r=0;e.totalheight.number>0&&(r=NU(e.totalheight,t)-n);var i=0;e.width.number>0&&(i=NU(e.width,t));var a={height:z(n+r)};i>0&&(a.width=z(i)),r>0&&(a.verticalAlign=z(-r));var o=new HU(e.src,e.alt,a);return o.height=n,o.depth=r,o},mathmlBuilder:(e,t)=>{var n=new Q(`mglyph`,[]);n.setAttribute(`alt`,e.alt);var r=NU(e.height,t),i=0;if(e.totalheight.number>0&&(i=NU(e.totalheight,t)-r,n.setAttribute(`valign`,z(-i))),n.setAttribute(`height`,z(r+i)),e.width.number>0){var a=NU(e.width,t);n.setAttribute(`width`,z(a))}return n.setAttribute(`src`,e.src),n}}),Z({type:`kern`,names:[`\\kern`,`\\mkern`,`\\hskip`,`\\mskip`],numArgs:1,argTypes:[`size`],primitive:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=pK(t[0],`size`);if(n.settings.strict){var a=r[1]===`m`,o=i.value.unit===`mu`;a?(o||n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` supports only mu units, `+(`not `+i.value.unit+` units`)),n.mode!==`math`&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` works only in math mode`)):o&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` doesn't support mu units`)}return{type:`kern`,mode:n.mode,dimension:i.value}},htmlBuilder(e,t){return aG(e.dimension,t)},mathmlBuilder(e,t){return new IG(NU(e.dimension,t))}}),Z({type:`lap`,names:[`\\mathllap`,`\\mathrlap`,`\\mathclap`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`lap`,mode:n.mode,alignment:r.slice(5),body:i}},htmlBuilder:(e,t)=>{var n;e.alignment===`clap`?(n=X([],[jG(e.body,t)]),n=X([`katex-inner`],[n],t)):n=X([`katex-inner`],[jG(e.body,t)]);var r=X([`katex-fix`],[]),i=X([e.alignment],[n,r],t),a=X([`katex-strut`]);return a.style.height=z(i.height+i.depth),i.depth&&(a.style.verticalAlign=z(-i.depth)),i.children.unshift(a),i=X([`katex-thinbox`],[i],t),X([`mord`,`katex-vbox`],[i],t)},mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[KG(e.body,t)]);if(e.alignment!==`rlap`){var r=e.alignment===`llap`?`-1`:`-0.5`;n.setAttribute(`lspace`,r+`width`)}return n.setAttribute(`width`,`0px`),n}}),Z({type:`styling`,names:[`\\(`,`$`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){var n=e.funcName,r=e.parser,i=r.mode;r.switchMode(`math`);var a=n===`\\(`?`\\)`:`$`,o=r.parseExpression(!1,a);return r.expect(a),r.switchMode(i),{type:`styling`,mode:r.mode,style:`text`,resetFont:!0,body:o}}}),Z({type:`text`,names:[`\\)`,`\\]`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){throw new L(`Mismatched `+e.funcName)}});var Vq=(e,t)=>{switch(t.style.size){case R.DISPLAY.size:return e.display;case R.TEXT.size:return e.text;case R.SCRIPT.size:return e.script;case R.SCRIPTSCRIPT.size:return e.scriptscript;default:return e.text}};Z({type:`mathchoice`,names:[`\\mathchoice`],numArgs:4,primitive:!0,handler:(e,t)=>({type:`mathchoice`,mode:e.parser.mode,display:bG(t[0]),text:bG(t[1]),script:bG(t[2]),scriptscript:bG(t[3])}),htmlBuilder:(e,t)=>tG(TG(Vq(e,t),t,!1)),mathmlBuilder:(e,t)=>GG(Vq(e,t),t)});var Hq=(e,t,n,r,i,a,o)=>{e=X([],[e]);var s=n&&HH(n),c,l;if(t){var u=jG(t,r.havingStyle(i.sup()),r);l={elem:u,kern:Math.max(r.fontMetrics().bigOpSpacing1,r.fontMetrics().bigOpSpacing3-u.depth)}}if(n){var d=jG(n,r.havingStyle(i.sub()),r);c={elem:d,kern:Math.max(r.fontMetrics().bigOpSpacing2,r.fontMetrics().bigOpSpacing4-d.height)}}var f;if(l&&c)f=iG({positionType:`bottom`,positionData:r.fontMetrics().bigOpSpacing5+c.elem.height+c.elem.depth+c.kern+e.depth+o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else if(c)f=iG({positionType:`top`,positionData:e.height-o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e}]});else if(l)f=iG({positionType:`bottom`,positionData:e.depth+o,children:[{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else return e;var p=[f];if(c&&a!==0&&!s){var m=X([`mspace`],[],r);m.style.marginRight=z(a),p.unshift(m)}return X([`mop`,`op-limits`],p,r)},Uq=new Set([`\\smallint`]),Wq=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=pK(e.base,`op`),i=!0):a=pK(e,`op`);var o=t.style,s=!1;o.size===R.DISPLAY.size&&a.symbol&&!Uq.has(a.name)&&(s=!0);var c,l;if(a.symbol){var u=s?`Size2-Regular`:`Size1-Regular`,d=``;if((a.name===`\\oiint`||a.name===`\\oiiint`)&&(d=a.name.slice(1),a.name=d===`oiint`?`\\iint`:`\\iiint`),c=GW(a.name,u,`math`,t,[`mop`,`op-symbol`,s?`large-op`:`small-op`]),l=c.italic,d.length>0){var f=lG(d+`Size`+(s?`2`:`1`),t);c=iG({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:0},{type:`elem`,elem:f,shift:s?.08:0}]}),a.name=`\\`+d,c.classes.unshift(`mop`),c.italic=l}}else if(a.body){var p=TG(a.body,t,!0);p.length===1&&p[0]instanceof WU?(c=p[0],c.classes[0]=`mop`):c=X([`mop`],p,t)}else{for(var m=[],h=1;h{var n;if(e.symbol)n=new Q(`mo`,[zG(e.name,e.mode)]),Uq.has(e.name)&&n.setAttribute(`largeop`,`false`);else if(e.body)n=new Q(`mo`,WG(e.body,t));else{n=new Q(`mi`,[new FG(e.name.slice(1))]);var r=new Q(`mo`,[zG(`⁡`,`text`)]);n=e.parentIsSupSub?new Q(`mrow`,[n,r]):PG([n,r])}return n},Kq={"∏":`\\prod`,"∐":`\\coprod`,"∑":`\\sum`,"⋀":`\\bigwedge`,"⋁":`\\bigvee`,"⋂":`\\bigcap`,"⋃":`\\bigcup`,"⨀":`\\bigodot`,"⨁":`\\bigoplus`,"⨂":`\\bigotimes`,"⨄":`\\biguplus`,"⨆":`\\bigsqcup`};Z({type:`op`,names:`\\coprod.\\bigvee.\\bigwedge.\\biguplus.\\bigcap.\\bigcup.\\intop.\\prod.\\sum.\\bigotimes.\\bigoplus.\\bigodot.\\bigsqcup.\\smallint.∏.∐.∑.⋀.⋁.⋂.⋃.⨀.⨁.⨂.⨄.⨆`.split(`.`),numArgs:0,handler:(e,t)=>{var n=e.parser,r=e.funcName;return r.length===1&&(r=Kq[r]),{type:`op`,mode:n.mode,limits:!0,parentIsSupSub:!1,symbol:!0,name:r}},htmlBuilder:Wq,mathmlBuilder:Gq}),Z({type:`op`,names:[`\\mathop`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`op`,mode:n.mode,limits:!1,parentIsSupSub:!1,symbol:!1,body:bG(r)}}});var qq={"∫":`\\int`,"∬":`\\iint`,"∭":`\\iiint`,"∮":`\\oint`,"∯":`\\oiint`,"∰":`\\oiiint`};Z({type:`op`,names:`\\arcsin.\\arccos.\\arctan.\\arctg.\\arcctg.\\arg.\\ch.\\cos.\\cosec.\\cosh.\\cot.\\cotg.\\coth.\\csc.\\ctg.\\cth.\\deg.\\dim.\\exp.\\hom.\\ker.\\lg.\\ln.\\log.\\sec.\\sin.\\sinh.\\sh.\\tan.\\tanh.\\tg.\\th`.split(`.`),numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\det`,`\\gcd`,`\\inf`,`\\lim`,`\\max`,`\\min`,`\\Pr`,`\\sup`],numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!0,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\int`,`\\iint`,`\\iiint`,`\\oint`,`\\oiint`,`\\oiiint`,`∫`,`∬`,`∭`,`∮`,`∯`,`∰`],numArgs:0,allowedInArgument:!0,handler(e){var t=e.parser,n=e.funcName;return n.length===1&&(n=qq[n]),{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!0,name:n}}});var Jq=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=pK(e.base,`operatorname`),i=!0):a=pK(e,`operatorname`);var o;if(a.body.length>0){for(var s=TG(a.body.map(e=>{var t=`text`in e?e.text:void 0;return typeof t==`string`?{type:`textord`,mode:e.mode,text:t}:e}),t.withFont(`mathrm`),!0),c=0;c{var n=e.parser,r=e.funcName,i=t[0];return{type:`operatorname`,mode:n.mode,body:bG(i),alwaysHandleSupSub:r===`\\operatornamewithlimits`,limits:!1,parentIsSupSub:!1}},htmlBuilder:Jq,mathmlBuilder:(e,t)=>{for(var n=WG(e.body,t.withFont(`mathrm`)),r=!0,i=0;ie.toText()).join(``))]);var s=new Q(`mi`,n);s.setAttribute(`mathvariant`,`normal`);var c=new Q(`mo`,[zG(`⁡`,`text`)]);return e.parentIsSupSub?new Q(`mrow`,[s,c]):PG([s,c])}}),$(`\\operatorname`,`\\@ifstar\\operatornamewithlimits\\operatorname@`),vG({type:`ordgroup`,htmlBuilder(e,t){return e.semisimple?tG(TG(e.body,t,!1)):X([`mord`],TG(e.body,t,!0),t)},mathmlBuilder(e,t){return GG(e.body,t,!0)}}),Z({type:`overline`,names:[`\\overline`],numArgs:1,handler(e,t){var n=e.parser,r=t[0];return{type:`overline`,mode:n.mode,body:r}},htmlBuilder(e,t){var n=jG(e.body,t.havingCrampedStyle()),r=$W(`overline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-overline`],[iG({positionType:`firstBaseline`,children:[{type:`elem`,elem:n},{type:`kern`,size:3*i},{type:`elem`,elem:r},{type:`kern`,size:i}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new FG(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`mover`,[KG(e.body,t),n]);return r.setAttribute(`accent`,`true`),r}}),Z({type:`phantom`,names:[`\\phantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`phantom`,mode:n.mode,body:bG(r)}},htmlBuilder:(e,t)=>tG(TG(e.body,t.withPhantom(),!1)),mathmlBuilder:(e,t)=>new Q(`mphantom`,WG(e.body,t))}),$(`\\hphantom`,`\\smash{\\phantom{#1}}`),Z({type:`vphantom`,names:[`\\vphantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`vphantom`,mode:n.mode,body:r}},htmlBuilder:(e,t)=>X([`mord`,`rlap`],[X([`katex-inner`],[jG(e.body,t.withPhantom())]),X([`katex-fix`],[])],t),mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[new Q(`mphantom`,WG(bG(e.body),t))]);return n.setAttribute(`width`,`0px`),n}}),Z({type:`raisebox`,names:[`\\raisebox`],numArgs:2,argTypes:[`size`,`hbox`],allowedInText:!0,handler(e,t){var n=e.parser,r=pK(t[0],`size`).value,i=t[1];return{type:`raisebox`,mode:n.mode,dy:r,body:i}},htmlBuilder(e,t){var n=jG(e.body,t);return iG({positionType:`shift`,positionData:-NU(e.dy,t),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){var n=new Q(`mpadded`,[KG(e.body,t)]),r=e.dy.number+e.dy.unit;return n.setAttribute(`voffset`,r),n}});var Yq=(e,t)=>({type:`reflectbox`,mode:e.parser.mode,body:t[0]});Z({type:`reflectbox`,names:[`\\reflectbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler:Yq,htmlBuilder(e,t){return X([`mord`,`reflectbox`],[jG(e.body,t)],t)},mathmlBuilder(e,t){return KG(e.body,t)}}),Z({type:`reflectbox`,names:[`\\mathreflectbox`],numArgs:1,argTypes:[`math`],handler:Yq}),Z({type:`internal`,names:[`\\relax`],numArgs:0,allowedInText:!0,allowedInArgument:!0,handler(e){return{type:`internal`,mode:e.parser.mode}}}),Z({type:`rule`,names:[`\\rule`],numArgs:2,numOptionalArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`size`,`size`,`size`],handler(e,t,n){var r=e.parser,i=n[0],a=pK(t[0],`size`),o=pK(t[1],`size`);return{type:`rule`,mode:r.mode,shift:i&&pK(i,`size`).value,width:a.value,height:o.value}},htmlBuilder(e,t){var n=X([`mord`,`katex-rule`],[],t),r=NU(e.width,t),i=NU(e.height,t),a=e.shift?NU(e.shift,t):0;return n.style.borderRightWidth=z(r),n.style.borderTopWidth=z(i),n.style.bottom=z(a),n.width=r,n.height=i+a,n.depth=-a,n.maxFontSize=i*1.125*t.sizeMultiplier,n},mathmlBuilder(e,t){var n=NU(e.width,t),r=NU(e.height,t),i=e.shift?NU(e.shift,t):0,a=t.color&&t.getColor()||`black`,o=new Q(`mspace`);o.setAttribute(`mathbackground`,a),o.setAttribute(`width`,z(n)),o.setAttribute(`height`,z(r));var s=new Q(`mpadded`,[o]);return i>=0?s.setAttribute(`height`,z(i)):(s.setAttribute(`height`,z(i)),s.setAttribute(`depth`,z(-i))),s.setAttribute(`voffset`,z(i)),s}});function Xq(e,t,n){for(var r=TG(e,t,!1),i=t.sizeMultiplier/n.sizeMultiplier,a=0;a{var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!1,n);return{type:`sizing`,mode:i.mode,size:Zq.indexOf(r)+1,body:a}},htmlBuilder:(e,t)=>{var n=t.havingSize(e.size);return Xq(e.body,n,t)},mathmlBuilder:(e,t)=>{var n=t.havingSize(e.size),r=new Q(`mstyle`,WG(e.body,n));return r.setAttribute(`mathsize`,z(n.sizeMultiplier)),r}}),Z({type:`smash`,names:[`\\smash`],numArgs:1,numOptionalArgs:1,allowedInText:!0,handler:(e,t,n)=>{var r=e.parser,i=!1,a=!1,o=n[0]&&pK(n[0],`ordgroup`);if(o)for(var s,c=0;c{var n=X([],[jG(e.body,t)]);if(!e.smashHeight&&!e.smashDepth)return n;if(e.smashHeight&&(n.height=0),e.smashDepth&&(n.depth=0),e.smashHeight&&e.smashDepth)return X([`mord`,`katex-smash`],[n],t);if(n.children)for(var r=0;r{var n=new Q(`mpadded`,[KG(e.body,t)]);return e.smashHeight&&n.setAttribute(`height`,`0px`),e.smashDepth&&n.setAttribute(`depth`,`0px`),n}}),Z({type:`sqrt`,names:[`\\sqrt`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=n[0],a=t[0];return{type:`sqrt`,mode:r.mode,body:a,index:i}},htmlBuilder(e,t){var n=jG(e.body,t.havingCrampedStyle());n.height===0&&(n.height=t.fontMetrics().xHeight),n=nG(n,t);var r=t.fontMetrics().defaultRuleThickness,i=r;t.style.idn.height+n.depth+a&&(a=(a+u-n.height-n.depth)/2);var d=s.height-n.height-a-c;n.style.paddingLeft=z(l);var f=iG({positionType:`firstBaseline`,children:[{type:`elem`,elem:n,wrapperClasses:[`svg-align`]},{type:`kern`,size:-(n.height+d)},{type:`elem`,elem:s},{type:`kern`,size:c}]});if(e.index){var p=t.havingStyle(R.SCRIPTSCRIPT),m=jG(e.index,p,t);return X([`mord`,`sqrt`],[X([`katex-root`],[iG({positionType:`shift`,positionData:-(.6*(f.height-f.depth)),children:[{type:`elem`,elem:m}]})]),f],t)}return X([`mord`,`sqrt`],[f],t)},mathmlBuilder(e,t){var n=e.body,r=e.index;return r?new Q(`mroot`,[KG(n,t),KG(r,t)]):new Q(`msqrt`,[KG(n,t)])}});var Qq={display:R.DISPLAY,text:R.TEXT,script:R.SCRIPT,scriptscript:R.SCRIPTSCRIPT};function $q(e){return e in Qq}Z({type:`styling`,names:[`\\displaystyle`,`\\textstyle`,`\\scriptstyle`,`\\scriptscriptstyle`],numArgs:0,allowedInText:!0,primitive:!0,handler(e,t){var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!0,n),o=r.slice(1,r.length-5);if(!$q(o))throw Error(`Unknown style: `+o);return{type:`styling`,mode:i.mode,style:o,body:a}},htmlBuilder(e,t){var n=Qq[e.style],r=t.havingStyle(n);return e.resetFont&&(r=r.withFont(``)),Xq(e.body,r,t)},mathmlBuilder(e,t){var n=Qq[e.style],r=t.havingStyle(n);e.resetFont&&(r=r.withFont(``));var i=new Q(`mstyle`,WG(e.body,r)),a={display:[`0`,`true`],text:[`0`,`false`],script:[`1`,`false`],scriptscript:[`2`,`false`]}[e.style];return i.setAttribute(`scriptlevel`,a[0]),i.setAttribute(`displaystyle`,a[1]),i}});var eJ=function(e,t){var n=e.base;return n?n.type===`op`?n.limits&&(t.style.size===R.DISPLAY.size||n.alwaysHandleSupSub)?Wq:null:n.type===`operatorname`?n.alwaysHandleSupSub&&(t.style.size===R.DISPLAY.size||n.limits)?Jq:null:n.type===`accent`?HH(n.base)?vK:null:n.type===`horizBrace`&&!e.sub===n.isOver?zq:null:null};vG({type:`supsub`,htmlBuilder(e,t){var n=eJ(e,t);if(n)return n(e,t);var r=e.base,i=e.sup,a=e.sub,o=jG(r,t),s,c,l=t.fontMetrics(),u=0,d=0,f=r&&HH(r);if(i){var p=t.havingStyle(t.style.sup());s=jG(i,p,t),f||(u=o.height-p.fontMetrics().supDrop*p.sizeMultiplier/t.sizeMultiplier)}if(a){var m=t.havingStyle(t.style.sub());c=jG(a,m,t),f||(d=o.depth+m.fontMetrics().subDrop*m.sizeMultiplier/t.sizeMultiplier)}var h=t.style===R.DISPLAY?l.sup1:t.style.cramped?l.sup3:l.sup2,g=t.sizeMultiplier,_=z(.5/l.ptPerEm/g),v=null;if(c){var y=e.base&&e.base.type===`op`&&e.base.name&&(e.base.name===`\\oiint`||e.base.name===`\\oiiint`);(o instanceof WU||y)&&(v=z(-(o.italic??0)))}var b;if(s&&c){u=Math.max(u,h,s.depth+.25*l.xHeight),d=Math.max(d,l.sub2);var x=4*l.defaultRuleThickness;if(u-s.depth-(c.height-d)0&&(u+=S,d-=S)}b=iG({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:d,marginRight:_,marginLeft:v},{type:`elem`,elem:s,shift:-u,marginRight:_}]})}else if(c)d=Math.max(d,l.sub1,c.height-.8*l.xHeight),b=iG({positionType:`shift`,positionData:d,children:[{type:`elem`,elem:c,marginLeft:v,marginRight:_}]});else if(s)u=Math.max(u,h,s.depth+.25*l.xHeight),b=iG({positionType:`shift`,positionData:-u,children:[{type:`elem`,elem:s,marginRight:_}]});else throw Error(`supsub must have either sup or sub.`);return X([kG(o,`right`)||`mord`],[o,X([`msupsub`],[b])],t)},mathmlBuilder(e,t){var n=!1,r,i;e.base&&e.base.type===`horizBrace`&&(i=!!e.sup,i===e.base.isOver&&(n=!0,r=e.base.isOver)),e.base&&(e.base.type===`op`||e.base.type===`operatorname`)&&(e.base.parentIsSupSub=!0);var a=[KG(e.base,t)];e.sub&&a.push(KG(e.sub,t)),e.sup&&a.push(KG(e.sup,t));var o;if(n)o=r?`mover`:`munder`;else if(!e.sub){var s=e.base;o=s&&s.type===`op`&&s.limits&&(t.style===R.DISPLAY||s.alwaysHandleSupSub)||s&&s.type===`operatorname`&&s.alwaysHandleSupSub&&(s.limits||t.style===R.DISPLAY)?`mover`:`msup`}else if(e.sup){var c=e.base;o=c&&c.type===`op`&&c.limits&&t.style===R.DISPLAY||c&&c.type===`operatorname`&&c.alwaysHandleSupSub&&(t.style===R.DISPLAY||c.limits)?`munderover`:`msubsup`}else{var l=e.base;o=l&&l.type===`op`&&l.limits&&(t.style===R.DISPLAY||l.alwaysHandleSupSub)||l&&l.type===`operatorname`&&l.alwaysHandleSupSub&&(l.limits||t.style===R.DISPLAY)?`munder`:`msub`}return new Q(o,a)}}),vG({type:`atom`,htmlBuilder(e,t){return KW(e.text,e.mode,t,[`m`+e.family])},mathmlBuilder(e,t){var n=new Q(`mo`,[zG(e.text,e.mode)]);if(e.family===`bin`){var r=HG(e,t);r===`bold-italic`&&n.setAttribute(`mathvariant`,r)}else e.family===`punct`?n.setAttribute(`separator`,`true`):(e.family===`open`||e.family===`close`)&&n.setAttribute(`stretchy`,`false`);return n}});var tJ={mi:`italic`,mn:`normal`,mtext:`normal`};vG({type:`mathord`,htmlBuilder(e,t){return JW(e,t)},mathmlBuilder(e,t){var n=new Q(`mi`,[zG(e.text,e.mode,t)]),r=HG(e,t)||`italic`;return r!==tJ[n.type]&&n.setAttribute(`mathvariant`,r),n}}),vG({type:`textord`,htmlBuilder(e,t){return JW(e,t)},mathmlBuilder(e,t){var n=zG(e.text,e.mode,t),r=HG(e,t)||`normal`,i=e.mode===`text`?new Q(`mtext`,[n]):/[0-9]/.test(e.text)?new Q(`mn`,[n]):e.text===`\\prime`?new Q(`mo`,[n]):new Q(`mi`,[n]);return r!==tJ[i.type]&&i.setAttribute(`mathvariant`,r),i}});var nJ=new Map([[`\\nobreak`,`nobreak`],[`\\allowbreak`,`allowbreak`]]),rJ=new Map([[` `,{}],[`\\ `,{}],[`~`,{className:`nobreak`}],[`\\space`,{}],[`\\nobreakspace`,{className:`nobreak`}]]);vG({type:`spacing`,htmlBuilder(e,t){var n=rJ.get(e.text),r=nJ.get(e.text);if(n){var i=n.className||``;if(e.mode===`text`){var a=JW(e,t);return a.classes.push(i),a}return X([`mspace`,i],[KW(e.text,e.mode,t)],t)}if(r)return X([`mspace`,r],[],t);throw new L(`Unknown type of space "`+e.text+`"`)},mathmlBuilder(e,t){var n;if(rJ.has(e.text))n=new Q(`mtext`,[new FG(`\xA0`)]);else if(nJ.has(e.text))return new Q(`mspace`);else throw new L(`Unknown type of space "`+e.text+`"`);return n}});var iJ=()=>{var e=new Q(`mtd`,[]);return e.setAttribute(`width`,`50%`),e};vG({type:`tag`,mathmlBuilder(e,t){var n=new Q(`mtable`,[new Q(`mtr`,[iJ(),new Q(`mtd`,[GG(e.body,t)]),iJ(),new Q(`mtd`,[GG(e.tag,t)])])]);return n.setAttribute(`width`,`100%`),n}});var aJ={"\\text":void 0,"\\textrm":`textrm`,"\\textsf":`textsf`,"\\texttt":`texttt`,"\\textnormal":`textrm`},oJ={"\\textbf":`textbf`,"\\textmd":`textmd`},sJ={"\\textit":`textit`,"\\textup":`textup`},cJ=(e,t)=>{var n=e.font;return n?aJ[n]?t.withTextFontFamily(aJ[n]):oJ[n]?t.withTextFontWeight(oJ[n]):n===`\\emph`?t.fontShape===`textit`?t.withTextFontShape(`textup`):t.withTextFontShape(`textit`):t.withTextFontShape(sJ[n]):t};Z({type:`text`,names:[`\\text`,`\\textrm`,`\\textsf`,`\\texttt`,`\\textnormal`,`\\textbf`,`\\textmd`,`\\textit`,`\\textup`,`\\emph`],numArgs:1,argTypes:[`text`],allowedInArgument:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`text`,mode:n.mode,body:bG(i),font:r}},htmlBuilder(e,t){var n=cJ(e,t);return X([`mord`,`text`],TG(e.body,n,!0),n)},mathmlBuilder(e,t){var n=cJ(e,t);return GG(e.body,n)}}),Z({type:`underline`,names:[`\\underline`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`underline`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=jG(e.body,t),r=$W(`underline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-underline`],[iG({positionType:`top`,positionData:n.height,children:[{type:`kern`,size:i},{type:`elem`,elem:r},{type:`kern`,size:3*i},{type:`elem`,elem:n}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new FG(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`munder`,[KG(e.body,t),n]);return r.setAttribute(`accentunder`,`true`),r}}),Z({type:`vcenter`,names:[`\\vcenter`],numArgs:1,argTypes:[`original`],allowedInText:!1,handler(e,t){return{type:`vcenter`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=jG(e.body,t),r=t.fontMetrics().axisHeight;return iG({positionType:`shift`,positionData:.5*(n.height-r-(n.depth+r)),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){return new Q(`mrow`,[new Q(`mpadded`,[KG(e.body,t)],[`vcenter`])])}}),Z({type:`verb`,names:[`\\verb`],numArgs:0,allowedInText:!0,handler(e,t,n){throw new L(`\\verb ended by end of line instead of matching delimiter`)},htmlBuilder(e,t){for(var n=lJ(e),r=[],i=t.havingStyle(t.style.text()),a=0;ae.body.replace(/ /g,e.star?`␣`:`\xA0`),uJ=hG,dJ=`[ \r - ]`,fJ=`\\\\[a-zA-Z@]+`,pJ=`\\\\[^\ud800-\udfff]`,mJ=`(`+fJ+`)`+dJ+`*`,hJ=`\\\\( +-470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z`;default:throw Error(`Unknown stretchy delimiter.`)}};function aG(e){return`toText`in e}var oG=class{constructor(e){this.children=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.children=e,this.classes=[],this.height=0,this.depth=0,this.maxFontSize=0,this.style={}}hasClass(e){return this.classes.includes(e)}toNode(){for(var e=document.createDocumentFragment(),t=0;t{if(aG(e))return e.toText();throw Error(`Expected MathDomNode with toText, got `+e.constructor.name)}).join(``)}},sG={pt:1,mm:7227/2540,cm:7227/254,in:72.27,bp:803/800,pc:12,dd:1238/1157,cc:14856/1157,nd:685/642,nc:1370/107,sp:1/65536,px:803/800},cG={ex:!0,em:!0,mu:!0},lG=function(e){return typeof e!=`string`&&(e=e.unit),e in sG||e in cG||e===`ex`},uG=function(e,t){var n;if(e.unit in sG)n=sG[e.unit]/t.fontMetrics().ptPerEm/t.sizeMultiplier;else if(e.unit===`mu`)n=t.fontMetrics().cssEmPerMu;else{var r=t.style.isTight()?t.havingStyle(t.style.text()):t;if(e.unit===`ex`)n=r.fontMetrics().xHeight;else if(e.unit===`em`)n=r.fontMetrics().quad;else throw new R(`Invalid unit: '`+e.unit+`'`);r!==t&&(n*=r.sizeMultiplier/t.sizeMultiplier)}return Math.min(e.number*n,t.maxSize)},z=function(e){return+e.toFixed(4)+`em`},dG=function(e){return e.filter(e=>e).join(` `)},fG=function(e){var t=``;for(var n of Object.keys(e)){var r=e[n];r!==void 0&&(t+=fW(n)+`:`+r+`;`)}return t},pG=function(e,t,n){if(this.classes=e||[],this.attributes={},this.height=0,this.depth=0,this.maxFontSize=0,this.style=n||{},t){t.style.isTight()&&this.classes.push(`mtight`);var r=t.getColor();r&&(this.style.color=r)}},mG=function(e){var t=document.createElement(e);t.className=dG(this.classes),Object.assign(t.style,this.style);for(var n of Object.keys(this.attributes))t.setAttribute(n,this.attributes[n]);for(var r=0;r/=\x00-\x1f]/,gG=function(e){var t=`<`+e;this.classes.length&&(t+=` class="`+hW(dG(this.classes))+`"`);var n=fG(this.style);n&&(t+=` style="`+hW(n)+`"`);for(var r of Object.keys(this.attributes)){if(hG.test(r))throw new R(`Invalid attribute name '`+r+`'`);t+=` `+r+`="`+hW(this.attributes[r])+`"`}t+=`>`;for(var i=0;i`,t},_G=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.width=void 0,this.maxFontSize=void 0,this.style=void 0,this.italic=void 0,pG.call(this,e,n,r),this.children=t||[]}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return mG.call(this,`span`)}toMarkup(){return gG.call(this,`span`)}},vG=class{constructor(e,t,n,r){this.children=void 0,this.attributes=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,pG.call(this,t,r),this.children=n||[],this.setAttribute(`href`,e)}setAttribute(e,t){this.attributes[e]=t}hasClass(e){return this.classes.includes(e)}toNode(){return mG.call(this,`a`)}toMarkup(){return gG.call(this,`a`)}},yG=class{constructor(e,t,n){this.src=void 0,this.alt=void 0,this.classes=void 0,this.height=void 0,this.depth=void 0,this.maxFontSize=void 0,this.style=void 0,this.alt=t,this.src=e,this.classes=[`mord`],this.height=0,this.depth=0,this.maxFontSize=0,this.style=n}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createElement(`img`);return e.src=this.src,e.alt=this.alt,e.className=`mord`,Object.assign(e.style,this.style),e}toMarkup(){var e=``+hW(this.alt)+``,e}},bG={î:`ı̂`,ï:`ı̈`,í:`ı́`,ì:`ı̀`},xG=class{constructor(e,t,n,r,i,a,o,s){this.text=void 0,this.height=void 0,this.depth=void 0,this.italic=void 0,this.skew=void 0,this.width=void 0,this.maxFontSize=void 0,this.classes=void 0,this.style=void 0,this.text=e,this.height=t||0,this.depth=n||0,this.italic=r||0,this.skew=i||0,this.width=a||0,this.classes=o||[],this.style=s||{},this.maxFontSize=0;var c=UW(this.text.charCodeAt(0));c&&this.classes.push(c+`_fallback`),/[îïíì]/.test(this.text)&&(this.text=bG[this.text])}hasClass(e){return this.classes.includes(e)}toNode(){var e=document.createTextNode(this.text),t=null;return this.italic>0&&(t=document.createElement(`span`),t.style.marginRight=z(this.italic)),this.classes.length>0&&(t||=document.createElement(`span`),t.className=dG(this.classes)),Object.keys(this.style).length>0&&(t||=document.createElement(`span`),Object.assign(t.style,this.style)),t?(t.appendChild(e),t):e}toMarkup(){var e=!1,t=`0&&(n+=`margin-right:`+z(this.italic)+`;`),n+=fG(this.style),n&&(e=!0,t+=` style="`+hW(n)+`"`);var r=hW(this.text);return e?(t+=`>`,t+=r,t+=``,t):r}},SG=class{constructor(e,t){this.children=void 0,this.attributes=void 0,this.children=e||[],this.attributes=t||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);for(var n=0;n`;for(var n=0;n`,e}},CG=class{constructor(e,t){this.pathName=void 0,this.alternate=void 0,this.pathName=e,this.alternate=t}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return this.alternate?e.setAttribute(`d`,this.alternate):e.setAttribute(`d`,rG[this.pathName]),e}toMarkup(){return this.alternate?``:``}},wG=class{constructor(e){this.attributes=void 0,this.attributes=e||{}}toNode(){var e=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);for(var t of Object.keys(this.attributes))e.setAttribute(t,this.attributes[t]);return e}toMarkup(){var e=``,e}};function TG(e){if(e instanceof xG)return e;throw Error(`Expected symbolNode but got `+String(e)+`.`)}function EG(e){if(e instanceof _G)return e;throw Error(`Expected span but got `+String(e)+`.`)}var DG=e=>e instanceof _G||e instanceof vG||e instanceof oG,OG={"AMS-Regular":{32:[0,0,0,0,.25],65:[0,.68889,0,0,.72222],66:[0,.68889,0,0,.66667],67:[0,.68889,0,0,.72222],68:[0,.68889,0,0,.72222],69:[0,.68889,0,0,.66667],70:[0,.68889,0,0,.61111],71:[0,.68889,0,0,.77778],72:[0,.68889,0,0,.77778],73:[0,.68889,0,0,.38889],74:[.16667,.68889,0,0,.5],75:[0,.68889,0,0,.77778],76:[0,.68889,0,0,.66667],77:[0,.68889,0,0,.94445],78:[0,.68889,0,0,.72222],79:[.16667,.68889,0,0,.77778],80:[0,.68889,0,0,.61111],81:[.16667,.68889,0,0,.77778],82:[0,.68889,0,0,.72222],83:[0,.68889,0,0,.55556],84:[0,.68889,0,0,.66667],85:[0,.68889,0,0,.72222],86:[0,.68889,0,0,.72222],87:[0,.68889,0,0,1],88:[0,.68889,0,0,.72222],89:[0,.68889,0,0,.72222],90:[0,.68889,0,0,.66667],107:[0,.68889,0,0,.55556],160:[0,0,0,0,.25],165:[0,.675,.025,0,.75],174:[.15559,.69224,0,0,.94666],240:[0,.68889,0,0,.55556],295:[0,.68889,0,0,.54028],710:[0,.825,0,0,2.33334],732:[0,.9,0,0,2.33334],770:[0,.825,0,0,2.33334],771:[0,.9,0,0,2.33334],989:[.08167,.58167,0,0,.77778],1008:[0,.43056,.04028,0,.66667],8245:[0,.54986,0,0,.275],8463:[0,.68889,0,0,.54028],8487:[0,.68889,0,0,.72222],8498:[0,.68889,0,0,.55556],8502:[0,.68889,0,0,.66667],8503:[0,.68889,0,0,.44445],8504:[0,.68889,0,0,.66667],8513:[0,.68889,0,0,.63889],8592:[-.03598,.46402,0,0,.5],8594:[-.03598,.46402,0,0,.5],8602:[-.13313,.36687,0,0,1],8603:[-.13313,.36687,0,0,1],8606:[.01354,.52239,0,0,1],8608:[.01354,.52239,0,0,1],8610:[.01354,.52239,0,0,1.11111],8611:[.01354,.52239,0,0,1.11111],8619:[0,.54986,0,0,1],8620:[0,.54986,0,0,1],8621:[-.13313,.37788,0,0,1.38889],8622:[-.13313,.36687,0,0,1],8624:[0,.69224,0,0,.5],8625:[0,.69224,0,0,.5],8630:[0,.43056,0,0,1],8631:[0,.43056,0,0,1],8634:[.08198,.58198,0,0,.77778],8635:[.08198,.58198,0,0,.77778],8638:[.19444,.69224,0,0,.41667],8639:[.19444,.69224,0,0,.41667],8642:[.19444,.69224,0,0,.41667],8643:[.19444,.69224,0,0,.41667],8644:[.1808,.675,0,0,1],8646:[.1808,.675,0,0,1],8647:[.1808,.675,0,0,1],8648:[.19444,.69224,0,0,.83334],8649:[.1808,.675,0,0,1],8650:[.19444,.69224,0,0,.83334],8651:[.01354,.52239,0,0,1],8652:[.01354,.52239,0,0,1],8653:[-.13313,.36687,0,0,1],8654:[-.13313,.36687,0,0,1],8655:[-.13313,.36687,0,0,1],8666:[.13667,.63667,0,0,1],8667:[.13667,.63667,0,0,1],8669:[-.13313,.37788,0,0,1],8672:[-.064,.437,0,0,1.334],8674:[-.064,.437,0,0,1.334],8705:[0,.825,0,0,.5],8708:[0,.68889,0,0,.55556],8709:[.08167,.58167,0,0,.77778],8717:[0,.43056,0,0,.42917],8722:[-.03598,.46402,0,0,.5],8724:[.08198,.69224,0,0,.77778],8726:[.08167,.58167,0,0,.77778],8733:[0,.69224,0,0,.77778],8736:[0,.69224,0,0,.72222],8737:[0,.69224,0,0,.72222],8738:[.03517,.52239,0,0,.72222],8739:[.08167,.58167,0,0,.22222],8740:[.25142,.74111,0,0,.27778],8741:[.08167,.58167,0,0,.38889],8742:[.25142,.74111,0,0,.5],8756:[0,.69224,0,0,.66667],8757:[0,.69224,0,0,.66667],8764:[-.13313,.36687,0,0,.77778],8765:[-.13313,.37788,0,0,.77778],8769:[-.13313,.36687,0,0,.77778],8770:[-.03625,.46375,0,0,.77778],8774:[.30274,.79383,0,0,.77778],8776:[-.01688,.48312,0,0,.77778],8778:[.08167,.58167,0,0,.77778],8782:[.06062,.54986,0,0,.77778],8783:[.06062,.54986,0,0,.77778],8785:[.08198,.58198,0,0,.77778],8786:[.08198,.58198,0,0,.77778],8787:[.08198,.58198,0,0,.77778],8790:[0,.69224,0,0,.77778],8791:[.22958,.72958,0,0,.77778],8796:[.08198,.91667,0,0,.77778],8806:[.25583,.75583,0,0,.77778],8807:[.25583,.75583,0,0,.77778],8808:[.25142,.75726,0,0,.77778],8809:[.25142,.75726,0,0,.77778],8812:[.25583,.75583,0,0,.5],8814:[.20576,.70576,0,0,.77778],8815:[.20576,.70576,0,0,.77778],8816:[.30274,.79383,0,0,.77778],8817:[.30274,.79383,0,0,.77778],8818:[.22958,.72958,0,0,.77778],8819:[.22958,.72958,0,0,.77778],8822:[.1808,.675,0,0,.77778],8823:[.1808,.675,0,0,.77778],8828:[.13667,.63667,0,0,.77778],8829:[.13667,.63667,0,0,.77778],8830:[.22958,.72958,0,0,.77778],8831:[.22958,.72958,0,0,.77778],8832:[.20576,.70576,0,0,.77778],8833:[.20576,.70576,0,0,.77778],8840:[.30274,.79383,0,0,.77778],8841:[.30274,.79383,0,0,.77778],8842:[.13597,.63597,0,0,.77778],8843:[.13597,.63597,0,0,.77778],8847:[.03517,.54986,0,0,.77778],8848:[.03517,.54986,0,0,.77778],8858:[.08198,.58198,0,0,.77778],8859:[.08198,.58198,0,0,.77778],8861:[.08198,.58198,0,0,.77778],8862:[0,.675,0,0,.77778],8863:[0,.675,0,0,.77778],8864:[0,.675,0,0,.77778],8865:[0,.675,0,0,.77778],8872:[0,.69224,0,0,.61111],8873:[0,.69224,0,0,.72222],8874:[0,.69224,0,0,.88889],8876:[0,.68889,0,0,.61111],8877:[0,.68889,0,0,.61111],8878:[0,.68889,0,0,.72222],8879:[0,.68889,0,0,.72222],8882:[.03517,.54986,0,0,.77778],8883:[.03517,.54986,0,0,.77778],8884:[.13667,.63667,0,0,.77778],8885:[.13667,.63667,0,0,.77778],8888:[0,.54986,0,0,1.11111],8890:[.19444,.43056,0,0,.55556],8891:[.19444,.69224,0,0,.61111],8892:[.19444,.69224,0,0,.61111],8901:[0,.54986,0,0,.27778],8903:[.08167,.58167,0,0,.77778],8905:[.08167,.58167,0,0,.77778],8906:[.08167,.58167,0,0,.77778],8907:[0,.69224,0,0,.77778],8908:[0,.69224,0,0,.77778],8909:[-.03598,.46402,0,0,.77778],8910:[0,.54986,0,0,.76042],8911:[0,.54986,0,0,.76042],8912:[.03517,.54986,0,0,.77778],8913:[.03517,.54986,0,0,.77778],8914:[0,.54986,0,0,.66667],8915:[0,.54986,0,0,.66667],8916:[0,.69224,0,0,.66667],8918:[.0391,.5391,0,0,.77778],8919:[.0391,.5391,0,0,.77778],8920:[.03517,.54986,0,0,1.33334],8921:[.03517,.54986,0,0,1.33334],8922:[.38569,.88569,0,0,.77778],8923:[.38569,.88569,0,0,.77778],8926:[.13667,.63667,0,0,.77778],8927:[.13667,.63667,0,0,.77778],8928:[.30274,.79383,0,0,.77778],8929:[.30274,.79383,0,0,.77778],8934:[.23222,.74111,0,0,.77778],8935:[.23222,.74111,0,0,.77778],8936:[.23222,.74111,0,0,.77778],8937:[.23222,.74111,0,0,.77778],8938:[.20576,.70576,0,0,.77778],8939:[.20576,.70576,0,0,.77778],8940:[.30274,.79383,0,0,.77778],8941:[.30274,.79383,0,0,.77778],8994:[.19444,.69224,0,0,.77778],8995:[.19444,.69224,0,0,.77778],9416:[.15559,.69224,0,0,.90222],9484:[0,.69224,0,0,.5],9488:[0,.69224,0,0,.5],9492:[0,.37788,0,0,.5],9496:[0,.37788,0,0,.5],9585:[.19444,.68889,0,0,.88889],9586:[.19444,.74111,0,0,.88889],9632:[0,.675,0,0,.77778],9633:[0,.675,0,0,.77778],9650:[0,.54986,0,0,.72222],9651:[0,.54986,0,0,.72222],9654:[.03517,.54986,0,0,.77778],9660:[0,.54986,0,0,.72222],9661:[0,.54986,0,0,.72222],9664:[.03517,.54986,0,0,.77778],9674:[.11111,.69224,0,0,.66667],9733:[.19444,.69224,0,0,.94445],10003:[0,.69224,0,0,.83334],10016:[0,.69224,0,0,.83334],10731:[.11111,.69224,0,0,.66667],10846:[.19444,.75583,0,0,.61111],10877:[.13667,.63667,0,0,.77778],10878:[.13667,.63667,0,0,.77778],10885:[.25583,.75583,0,0,.77778],10886:[.25583,.75583,0,0,.77778],10887:[.13597,.63597,0,0,.77778],10888:[.13597,.63597,0,0,.77778],10889:[.26167,.75726,0,0,.77778],10890:[.26167,.75726,0,0,.77778],10891:[.48256,.98256,0,0,.77778],10892:[.48256,.98256,0,0,.77778],10901:[.13667,.63667,0,0,.77778],10902:[.13667,.63667,0,0,.77778],10933:[.25142,.75726,0,0,.77778],10934:[.25142,.75726,0,0,.77778],10935:[.26167,.75726,0,0,.77778],10936:[.26167,.75726,0,0,.77778],10937:[.26167,.75726,0,0,.77778],10938:[.26167,.75726,0,0,.77778],10949:[.25583,.75583,0,0,.77778],10950:[.25583,.75583,0,0,.77778],10955:[.28481,.79383,0,0,.77778],10956:[.28481,.79383,0,0,.77778],57350:[.08167,.58167,0,0,.22222],57351:[.08167,.58167,0,0,.38889],57352:[.08167,.58167,0,0,.77778],57353:[0,.43056,.04028,0,.66667],57356:[.25142,.75726,0,0,.77778],57357:[.25142,.75726,0,0,.77778],57358:[.41951,.91951,0,0,.77778],57359:[.30274,.79383,0,0,.77778],57360:[.30274,.79383,0,0,.77778],57361:[.41951,.91951,0,0,.77778],57366:[.25142,.75726,0,0,.77778],57367:[.25142,.75726,0,0,.77778],57368:[.25142,.75726,0,0,.77778],57369:[.25142,.75726,0,0,.77778],57370:[.13597,.63597,0,0,.77778],57371:[.13597,.63597,0,0,.77778]},"Caligraphic-Regular":{32:[0,0,0,0,.25],65:[0,.68333,0,.19445,.79847],66:[0,.68333,.03041,.13889,.65681],67:[0,.68333,.05834,.13889,.52653],68:[0,.68333,.02778,.08334,.77139],69:[0,.68333,.08944,.11111,.52778],70:[0,.68333,.09931,.11111,.71875],71:[.09722,.68333,.0593,.11111,.59487],72:[0,.68333,.00965,.11111,.84452],73:[0,.68333,.07382,0,.54452],74:[.09722,.68333,.18472,.16667,.67778],75:[0,.68333,.01445,.05556,.76195],76:[0,.68333,0,.13889,.68972],77:[0,.68333,0,.13889,1.2009],78:[0,.68333,.14736,.08334,.82049],79:[0,.68333,.02778,.11111,.79611],80:[0,.68333,.08222,.08334,.69556],81:[.09722,.68333,0,.11111,.81667],82:[0,.68333,0,.08334,.8475],83:[0,.68333,.075,.13889,.60556],84:[0,.68333,.25417,0,.54464],85:[0,.68333,.09931,.08334,.62583],86:[0,.68333,.08222,0,.61278],87:[0,.68333,.08222,.08334,.98778],88:[0,.68333,.14643,.13889,.7133],89:[.09722,.68333,.08222,.08334,.66834],90:[0,.68333,.07944,.13889,.72473],160:[0,0,0,0,.25]},"Fraktur-Regular":{32:[0,0,0,0,.25],33:[0,.69141,0,0,.29574],34:[0,.69141,0,0,.21471],38:[0,.69141,0,0,.73786],39:[0,.69141,0,0,.21201],40:[.24982,.74947,0,0,.38865],41:[.24982,.74947,0,0,.38865],42:[0,.62119,0,0,.27764],43:[.08319,.58283,0,0,.75623],44:[0,.10803,0,0,.27764],45:[.08319,.58283,0,0,.75623],46:[0,.10803,0,0,.27764],47:[.24982,.74947,0,0,.50181],48:[0,.47534,0,0,.50181],49:[0,.47534,0,0,.50181],50:[0,.47534,0,0,.50181],51:[.18906,.47534,0,0,.50181],52:[.18906,.47534,0,0,.50181],53:[.18906,.47534,0,0,.50181],54:[0,.69141,0,0,.50181],55:[.18906,.47534,0,0,.50181],56:[0,.69141,0,0,.50181],57:[.18906,.47534,0,0,.50181],58:[0,.47534,0,0,.21606],59:[.12604,.47534,0,0,.21606],61:[-.13099,.36866,0,0,.75623],63:[0,.69141,0,0,.36245],65:[0,.69141,0,0,.7176],66:[0,.69141,0,0,.88397],67:[0,.69141,0,0,.61254],68:[0,.69141,0,0,.83158],69:[0,.69141,0,0,.66278],70:[.12604,.69141,0,0,.61119],71:[0,.69141,0,0,.78539],72:[.06302,.69141,0,0,.7203],73:[0,.69141,0,0,.55448],74:[.12604,.69141,0,0,.55231],75:[0,.69141,0,0,.66845],76:[0,.69141,0,0,.66602],77:[0,.69141,0,0,1.04953],78:[0,.69141,0,0,.83212],79:[0,.69141,0,0,.82699],80:[.18906,.69141,0,0,.82753],81:[.03781,.69141,0,0,.82699],82:[0,.69141,0,0,.82807],83:[0,.69141,0,0,.82861],84:[0,.69141,0,0,.66899],85:[0,.69141,0,0,.64576],86:[0,.69141,0,0,.83131],87:[0,.69141,0,0,1.04602],88:[0,.69141,0,0,.71922],89:[.18906,.69141,0,0,.83293],90:[.12604,.69141,0,0,.60201],91:[.24982,.74947,0,0,.27764],93:[.24982,.74947,0,0,.27764],94:[0,.69141,0,0,.49965],97:[0,.47534,0,0,.50046],98:[0,.69141,0,0,.51315],99:[0,.47534,0,0,.38946],100:[0,.62119,0,0,.49857],101:[0,.47534,0,0,.40053],102:[.18906,.69141,0,0,.32626],103:[.18906,.47534,0,0,.5037],104:[.18906,.69141,0,0,.52126],105:[0,.69141,0,0,.27899],106:[0,.69141,0,0,.28088],107:[0,.69141,0,0,.38946],108:[0,.69141,0,0,.27953],109:[0,.47534,0,0,.76676],110:[0,.47534,0,0,.52666],111:[0,.47534,0,0,.48885],112:[.18906,.52396,0,0,.50046],113:[.18906,.47534,0,0,.48912],114:[0,.47534,0,0,.38919],115:[0,.47534,0,0,.44266],116:[0,.62119,0,0,.33301],117:[0,.47534,0,0,.5172],118:[0,.52396,0,0,.5118],119:[0,.52396,0,0,.77351],120:[.18906,.47534,0,0,.38865],121:[.18906,.47534,0,0,.49884],122:[.18906,.47534,0,0,.39054],160:[0,0,0,0,.25],8216:[0,.69141,0,0,.21471],8217:[0,.69141,0,0,.21471],58112:[0,.62119,0,0,.49749],58113:[0,.62119,0,0,.4983],58114:[.18906,.69141,0,0,.33328],58115:[.18906,.69141,0,0,.32923],58116:[.18906,.47534,0,0,.50343],58117:[0,.69141,0,0,.33301],58118:[0,.62119,0,0,.33409],58119:[0,.47534,0,0,.50073]},"Main-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.35],34:[0,.69444,0,0,.60278],35:[.19444,.69444,0,0,.95833],36:[.05556,.75,0,0,.575],37:[.05556,.75,0,0,.95833],38:[0,.69444,0,0,.89444],39:[0,.69444,0,0,.31944],40:[.25,.75,0,0,.44722],41:[.25,.75,0,0,.44722],42:[0,.75,0,0,.575],43:[.13333,.63333,0,0,.89444],44:[.19444,.15556,0,0,.31944],45:[0,.44444,0,0,.38333],46:[0,.15556,0,0,.31944],47:[.25,.75,0,0,.575],48:[0,.64444,0,0,.575],49:[0,.64444,0,0,.575],50:[0,.64444,0,0,.575],51:[0,.64444,0,0,.575],52:[0,.64444,0,0,.575],53:[0,.64444,0,0,.575],54:[0,.64444,0,0,.575],55:[0,.64444,0,0,.575],56:[0,.64444,0,0,.575],57:[0,.64444,0,0,.575],58:[0,.44444,0,0,.31944],59:[.19444,.44444,0,0,.31944],60:[.08556,.58556,0,0,.89444],61:[-.10889,.39111,0,0,.89444],62:[.08556,.58556,0,0,.89444],63:[0,.69444,0,0,.54305],64:[0,.69444,0,0,.89444],65:[0,.68611,0,0,.86944],66:[0,.68611,0,0,.81805],67:[0,.68611,0,0,.83055],68:[0,.68611,0,0,.88194],69:[0,.68611,0,0,.75555],70:[0,.68611,0,0,.72361],71:[0,.68611,0,0,.90416],72:[0,.68611,0,0,.9],73:[0,.68611,0,0,.43611],74:[0,.68611,0,0,.59444],75:[0,.68611,0,0,.90138],76:[0,.68611,0,0,.69166],77:[0,.68611,0,0,1.09166],78:[0,.68611,0,0,.9],79:[0,.68611,0,0,.86388],80:[0,.68611,0,0,.78611],81:[.19444,.68611,0,0,.86388],82:[0,.68611,0,0,.8625],83:[0,.68611,0,0,.63889],84:[0,.68611,0,0,.8],85:[0,.68611,0,0,.88472],86:[0,.68611,.01597,0,.86944],87:[0,.68611,.01597,0,1.18888],88:[0,.68611,0,0,.86944],89:[0,.68611,.02875,0,.86944],90:[0,.68611,0,0,.70277],91:[.25,.75,0,0,.31944],92:[.25,.75,0,0,.575],93:[.25,.75,0,0,.31944],94:[0,.69444,0,0,.575],95:[.31,.13444,.03194,0,.575],97:[0,.44444,0,0,.55902],98:[0,.69444,0,0,.63889],99:[0,.44444,0,0,.51111],100:[0,.69444,0,0,.63889],101:[0,.44444,0,0,.52708],102:[0,.69444,.10903,0,.35139],103:[.19444,.44444,.01597,0,.575],104:[0,.69444,0,0,.63889],105:[0,.69444,0,0,.31944],106:[.19444,.69444,0,0,.35139],107:[0,.69444,0,0,.60694],108:[0,.69444,0,0,.31944],109:[0,.44444,0,0,.95833],110:[0,.44444,0,0,.63889],111:[0,.44444,0,0,.575],112:[.19444,.44444,0,0,.63889],113:[.19444,.44444,0,0,.60694],114:[0,.44444,0,0,.47361],115:[0,.44444,0,0,.45361],116:[0,.63492,0,0,.44722],117:[0,.44444,0,0,.63889],118:[0,.44444,.01597,0,.60694],119:[0,.44444,.01597,0,.83055],120:[0,.44444,0,0,.60694],121:[.19444,.44444,.01597,0,.60694],122:[0,.44444,0,0,.51111],123:[.25,.75,0,0,.575],124:[.25,.75,0,0,.31944],125:[.25,.75,0,0,.575],126:[.35,.34444,0,0,.575],160:[0,0,0,0,.25],163:[0,.69444,0,0,.86853],168:[0,.69444,0,0,.575],172:[0,.44444,0,0,.76666],176:[0,.69444,0,0,.86944],177:[.13333,.63333,0,0,.89444],184:[.17014,0,0,0,.51111],198:[0,.68611,0,0,1.04166],215:[.13333,.63333,0,0,.89444],216:[.04861,.73472,0,0,.89444],223:[0,.69444,0,0,.59722],230:[0,.44444,0,0,.83055],247:[.13333,.63333,0,0,.89444],248:[.09722,.54167,0,0,.575],305:[0,.44444,0,0,.31944],338:[0,.68611,0,0,1.16944],339:[0,.44444,0,0,.89444],567:[.19444,.44444,0,0,.35139],710:[0,.69444,0,0,.575],711:[0,.63194,0,0,.575],713:[0,.59611,0,0,.575],714:[0,.69444,0,0,.575],715:[0,.69444,0,0,.575],728:[0,.69444,0,0,.575],729:[0,.69444,0,0,.31944],730:[0,.69444,0,0,.86944],732:[0,.69444,0,0,.575],733:[0,.69444,0,0,.575],915:[0,.68611,0,0,.69166],916:[0,.68611,0,0,.95833],920:[0,.68611,0,0,.89444],923:[0,.68611,0,0,.80555],926:[0,.68611,0,0,.76666],928:[0,.68611,0,0,.9],931:[0,.68611,0,0,.83055],933:[0,.68611,0,0,.89444],934:[0,.68611,0,0,.83055],936:[0,.68611,0,0,.89444],937:[0,.68611,0,0,.83055],8211:[0,.44444,.03194,0,.575],8212:[0,.44444,.03194,0,1.14999],8216:[0,.69444,0,0,.31944],8217:[0,.69444,0,0,.31944],8220:[0,.69444,0,0,.60278],8221:[0,.69444,0,0,.60278],8224:[.19444,.69444,0,0,.51111],8225:[.19444,.69444,0,0,.51111],8242:[0,.55556,0,0,.34444],8407:[0,.72444,.15486,0,.575],8463:[0,.69444,0,0,.66759],8465:[0,.69444,0,0,.83055],8467:[0,.69444,0,0,.47361],8472:[.19444,.44444,0,0,.74027],8476:[0,.69444,0,0,.83055],8501:[0,.69444,0,0,.70277],8592:[-.10889,.39111,0,0,1.14999],8593:[.19444,.69444,0,0,.575],8594:[-.10889,.39111,0,0,1.14999],8595:[.19444,.69444,0,0,.575],8596:[-.10889,.39111,0,0,1.14999],8597:[.25,.75,0,0,.575],8598:[.19444,.69444,0,0,1.14999],8599:[.19444,.69444,0,0,1.14999],8600:[.19444,.69444,0,0,1.14999],8601:[.19444,.69444,0,0,1.14999],8636:[-.10889,.39111,0,0,1.14999],8637:[-.10889,.39111,0,0,1.14999],8640:[-.10889,.39111,0,0,1.14999],8641:[-.10889,.39111,0,0,1.14999],8656:[-.10889,.39111,0,0,1.14999],8657:[.19444,.69444,0,0,.70277],8658:[-.10889,.39111,0,0,1.14999],8659:[.19444,.69444,0,0,.70277],8660:[-.10889,.39111,0,0,1.14999],8661:[.25,.75,0,0,.70277],8704:[0,.69444,0,0,.63889],8706:[0,.69444,.06389,0,.62847],8707:[0,.69444,0,0,.63889],8709:[.05556,.75,0,0,.575],8711:[0,.68611,0,0,.95833],8712:[.08556,.58556,0,0,.76666],8715:[.08556,.58556,0,0,.76666],8722:[.13333,.63333,0,0,.89444],8723:[.13333,.63333,0,0,.89444],8725:[.25,.75,0,0,.575],8726:[.25,.75,0,0,.575],8727:[-.02778,.47222,0,0,.575],8728:[-.02639,.47361,0,0,.575],8729:[-.02639,.47361,0,0,.575],8730:[.18,.82,0,0,.95833],8733:[0,.44444,0,0,.89444],8734:[0,.44444,0,0,1.14999],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.31944],8741:[.25,.75,0,0,.575],8743:[0,.55556,0,0,.76666],8744:[0,.55556,0,0,.76666],8745:[0,.55556,0,0,.76666],8746:[0,.55556,0,0,.76666],8747:[.19444,.69444,.12778,0,.56875],8764:[-.10889,.39111,0,0,.89444],8768:[.19444,.69444,0,0,.31944],8771:[.00222,.50222,0,0,.89444],8773:[.027,.638,0,0,.894],8776:[.02444,.52444,0,0,.89444],8781:[.00222,.50222,0,0,.89444],8801:[.00222,.50222,0,0,.89444],8804:[.19667,.69667,0,0,.89444],8805:[.19667,.69667,0,0,.89444],8810:[.08556,.58556,0,0,1.14999],8811:[.08556,.58556,0,0,1.14999],8826:[.08556,.58556,0,0,.89444],8827:[.08556,.58556,0,0,.89444],8834:[.08556,.58556,0,0,.89444],8835:[.08556,.58556,0,0,.89444],8838:[.19667,.69667,0,0,.89444],8839:[.19667,.69667,0,0,.89444],8846:[0,.55556,0,0,.76666],8849:[.19667,.69667,0,0,.89444],8850:[.19667,.69667,0,0,.89444],8851:[0,.55556,0,0,.76666],8852:[0,.55556,0,0,.76666],8853:[.13333,.63333,0,0,.89444],8854:[.13333,.63333,0,0,.89444],8855:[.13333,.63333,0,0,.89444],8856:[.13333,.63333,0,0,.89444],8857:[.13333,.63333,0,0,.89444],8866:[0,.69444,0,0,.70277],8867:[0,.69444,0,0,.70277],8868:[0,.69444,0,0,.89444],8869:[0,.69444,0,0,.89444],8900:[-.02639,.47361,0,0,.575],8901:[-.02639,.47361,0,0,.31944],8902:[-.02778,.47222,0,0,.575],8968:[.25,.75,0,0,.51111],8969:[.25,.75,0,0,.51111],8970:[.25,.75,0,0,.51111],8971:[.25,.75,0,0,.51111],8994:[-.13889,.36111,0,0,1.14999],8995:[-.13889,.36111,0,0,1.14999],9651:[.19444,.69444,0,0,1.02222],9657:[-.02778,.47222,0,0,.575],9661:[.19444,.69444,0,0,1.02222],9667:[-.02778,.47222,0,0,.575],9711:[.19444,.69444,0,0,1.14999],9824:[.12963,.69444,0,0,.89444],9825:[.12963,.69444,0,0,.89444],9826:[.12963,.69444,0,0,.89444],9827:[.12963,.69444,0,0,.89444],9837:[0,.75,0,0,.44722],9838:[.19444,.69444,0,0,.44722],9839:[.19444,.69444,0,0,.44722],10216:[.25,.75,0,0,.44722],10217:[.25,.75,0,0,.44722],10815:[0,.68611,0,0,.9],10927:[.19667,.69667,0,0,.89444],10928:[.19667,.69667,0,0,.89444],57376:[.19444,.69444,0,0,0]},"Main-BoldItalic":{32:[0,0,0,0,.25],33:[0,.69444,.11417,0,.38611],34:[0,.69444,.07939,0,.62055],35:[.19444,.69444,.06833,0,.94444],37:[.05556,.75,.12861,0,.94444],38:[0,.69444,.08528,0,.88555],39:[0,.69444,.12945,0,.35555],40:[.25,.75,.15806,0,.47333],41:[.25,.75,.03306,0,.47333],42:[0,.75,.14333,0,.59111],43:[.10333,.60333,.03306,0,.88555],44:[.19444,.14722,0,0,.35555],45:[0,.44444,.02611,0,.41444],46:[0,.14722,0,0,.35555],47:[.25,.75,.15806,0,.59111],48:[0,.64444,.13167,0,.59111],49:[0,.64444,.13167,0,.59111],50:[0,.64444,.13167,0,.59111],51:[0,.64444,.13167,0,.59111],52:[.19444,.64444,.13167,0,.59111],53:[0,.64444,.13167,0,.59111],54:[0,.64444,.13167,0,.59111],55:[.19444,.64444,.13167,0,.59111],56:[0,.64444,.13167,0,.59111],57:[0,.64444,.13167,0,.59111],58:[0,.44444,.06695,0,.35555],59:[.19444,.44444,.06695,0,.35555],61:[-.10889,.39111,.06833,0,.88555],63:[0,.69444,.11472,0,.59111],64:[0,.69444,.09208,0,.88555],65:[0,.68611,0,0,.86555],66:[0,.68611,.0992,0,.81666],67:[0,.68611,.14208,0,.82666],68:[0,.68611,.09062,0,.87555],69:[0,.68611,.11431,0,.75666],70:[0,.68611,.12903,0,.72722],71:[0,.68611,.07347,0,.89527],72:[0,.68611,.17208,0,.8961],73:[0,.68611,.15681,0,.47166],74:[0,.68611,.145,0,.61055],75:[0,.68611,.14208,0,.89499],76:[0,.68611,0,0,.69777],77:[0,.68611,.17208,0,1.07277],78:[0,.68611,.17208,0,.8961],79:[0,.68611,.09062,0,.85499],80:[0,.68611,.0992,0,.78721],81:[.19444,.68611,.09062,0,.85499],82:[0,.68611,.02559,0,.85944],83:[0,.68611,.11264,0,.64999],84:[0,.68611,.12903,0,.7961],85:[0,.68611,.17208,0,.88083],86:[0,.68611,.18625,0,.86555],87:[0,.68611,.18625,0,1.15999],88:[0,.68611,.15681,0,.86555],89:[0,.68611,.19803,0,.86555],90:[0,.68611,.14208,0,.70888],91:[.25,.75,.1875,0,.35611],93:[.25,.75,.09972,0,.35611],94:[0,.69444,.06709,0,.59111],95:[.31,.13444,.09811,0,.59111],97:[0,.44444,.09426,0,.59111],98:[0,.69444,.07861,0,.53222],99:[0,.44444,.05222,0,.53222],100:[0,.69444,.10861,0,.59111],101:[0,.44444,.085,0,.53222],102:[.19444,.69444,.21778,0,.4],103:[.19444,.44444,.105,0,.53222],104:[0,.69444,.09426,0,.59111],105:[0,.69326,.11387,0,.35555],106:[.19444,.69326,.1672,0,.35555],107:[0,.69444,.11111,0,.53222],108:[0,.69444,.10861,0,.29666],109:[0,.44444,.09426,0,.94444],110:[0,.44444,.09426,0,.64999],111:[0,.44444,.07861,0,.59111],112:[.19444,.44444,.07861,0,.59111],113:[.19444,.44444,.105,0,.53222],114:[0,.44444,.11111,0,.50167],115:[0,.44444,.08167,0,.48694],116:[0,.63492,.09639,0,.385],117:[0,.44444,.09426,0,.62055],118:[0,.44444,.11111,0,.53222],119:[0,.44444,.11111,0,.76777],120:[0,.44444,.12583,0,.56055],121:[.19444,.44444,.105,0,.56166],122:[0,.44444,.13889,0,.49055],126:[.35,.34444,.11472,0,.59111],160:[0,0,0,0,.25],168:[0,.69444,.11473,0,.59111],176:[0,.69444,0,0,.94888],184:[.17014,0,0,0,.53222],198:[0,.68611,.11431,0,1.02277],216:[.04861,.73472,.09062,0,.88555],223:[.19444,.69444,.09736,0,.665],230:[0,.44444,.085,0,.82666],248:[.09722,.54167,.09458,0,.59111],305:[0,.44444,.09426,0,.35555],338:[0,.68611,.11431,0,1.14054],339:[0,.44444,.085,0,.82666],567:[.19444,.44444,.04611,0,.385],710:[0,.69444,.06709,0,.59111],711:[0,.63194,.08271,0,.59111],713:[0,.59444,.10444,0,.59111],714:[0,.69444,.08528,0,.59111],715:[0,.69444,0,0,.59111],728:[0,.69444,.10333,0,.59111],729:[0,.69444,.12945,0,.35555],730:[0,.69444,0,0,.94888],732:[0,.69444,.11472,0,.59111],733:[0,.69444,.11472,0,.59111],915:[0,.68611,.12903,0,.69777],916:[0,.68611,0,0,.94444],920:[0,.68611,.09062,0,.88555],923:[0,.68611,0,0,.80666],926:[0,.68611,.15092,0,.76777],928:[0,.68611,.17208,0,.8961],931:[0,.68611,.11431,0,.82666],933:[0,.68611,.10778,0,.88555],934:[0,.68611,.05632,0,.82666],936:[0,.68611,.10778,0,.88555],937:[0,.68611,.0992,0,.82666],8211:[0,.44444,.09811,0,.59111],8212:[0,.44444,.09811,0,1.18221],8216:[0,.69444,.12945,0,.35555],8217:[0,.69444,.12945,0,.35555],8220:[0,.69444,.16772,0,.62055],8221:[0,.69444,.07939,0,.62055]},"Main-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.12417,0,.30667],34:[0,.69444,.06961,0,.51444],35:[.19444,.69444,.06616,0,.81777],37:[.05556,.75,.13639,0,.81777],38:[0,.69444,.09694,0,.76666],39:[0,.69444,.12417,0,.30667],40:[.25,.75,.16194,0,.40889],41:[.25,.75,.03694,0,.40889],42:[0,.75,.14917,0,.51111],43:[.05667,.56167,.03694,0,.76666],44:[.19444,.10556,0,0,.30667],45:[0,.43056,.02826,0,.35778],46:[0,.10556,0,0,.30667],47:[.25,.75,.16194,0,.51111],48:[0,.64444,.13556,0,.51111],49:[0,.64444,.13556,0,.51111],50:[0,.64444,.13556,0,.51111],51:[0,.64444,.13556,0,.51111],52:[.19444,.64444,.13556,0,.51111],53:[0,.64444,.13556,0,.51111],54:[0,.64444,.13556,0,.51111],55:[.19444,.64444,.13556,0,.51111],56:[0,.64444,.13556,0,.51111],57:[0,.64444,.13556,0,.51111],58:[0,.43056,.0582,0,.30667],59:[.19444,.43056,.0582,0,.30667],61:[-.13313,.36687,.06616,0,.76666],63:[0,.69444,.1225,0,.51111],64:[0,.69444,.09597,0,.76666],65:[0,.68333,0,0,.74333],66:[0,.68333,.10257,0,.70389],67:[0,.68333,.14528,0,.71555],68:[0,.68333,.09403,0,.755],69:[0,.68333,.12028,0,.67833],70:[0,.68333,.13305,0,.65277],71:[0,.68333,.08722,0,.77361],72:[0,.68333,.16389,0,.74333],73:[0,.68333,.15806,0,.38555],74:[0,.68333,.14028,0,.525],75:[0,.68333,.14528,0,.76888],76:[0,.68333,0,0,.62722],77:[0,.68333,.16389,0,.89666],78:[0,.68333,.16389,0,.74333],79:[0,.68333,.09403,0,.76666],80:[0,.68333,.10257,0,.67833],81:[.19444,.68333,.09403,0,.76666],82:[0,.68333,.03868,0,.72944],83:[0,.68333,.11972,0,.56222],84:[0,.68333,.13305,0,.71555],85:[0,.68333,.16389,0,.74333],86:[0,.68333,.18361,0,.74333],87:[0,.68333,.18361,0,.99888],88:[0,.68333,.15806,0,.74333],89:[0,.68333,.19383,0,.74333],90:[0,.68333,.14528,0,.61333],91:[.25,.75,.1875,0,.30667],93:[.25,.75,.10528,0,.30667],94:[0,.69444,.06646,0,.51111],95:[.31,.12056,.09208,0,.51111],97:[0,.43056,.07671,0,.51111],98:[0,.69444,.06312,0,.46],99:[0,.43056,.05653,0,.46],100:[0,.69444,.10333,0,.51111],101:[0,.43056,.07514,0,.46],102:[.19444,.69444,.21194,0,.30667],103:[.19444,.43056,.08847,0,.46],104:[0,.69444,.07671,0,.51111],105:[0,.65536,.1019,0,.30667],106:[.19444,.65536,.14467,0,.30667],107:[0,.69444,.10764,0,.46],108:[0,.69444,.10333,0,.25555],109:[0,.43056,.07671,0,.81777],110:[0,.43056,.07671,0,.56222],111:[0,.43056,.06312,0,.51111],112:[.19444,.43056,.06312,0,.51111],113:[.19444,.43056,.08847,0,.46],114:[0,.43056,.10764,0,.42166],115:[0,.43056,.08208,0,.40889],116:[0,.61508,.09486,0,.33222],117:[0,.43056,.07671,0,.53666],118:[0,.43056,.10764,0,.46],119:[0,.43056,.10764,0,.66444],120:[0,.43056,.12042,0,.46389],121:[.19444,.43056,.08847,0,.48555],122:[0,.43056,.12292,0,.40889],126:[.35,.31786,.11585,0,.51111],160:[0,0,0,0,.25],168:[0,.66786,.10474,0,.51111],176:[0,.69444,0,0,.83129],184:[.17014,0,0,0,.46],198:[0,.68333,.12028,0,.88277],216:[.04861,.73194,.09403,0,.76666],223:[.19444,.69444,.10514,0,.53666],230:[0,.43056,.07514,0,.71555],248:[.09722,.52778,.09194,0,.51111],338:[0,.68333,.12028,0,.98499],339:[0,.43056,.07514,0,.71555],710:[0,.69444,.06646,0,.51111],711:[0,.62847,.08295,0,.51111],713:[0,.56167,.10333,0,.51111],714:[0,.69444,.09694,0,.51111],715:[0,.69444,0,0,.51111],728:[0,.69444,.10806,0,.51111],729:[0,.66786,.11752,0,.30667],730:[0,.69444,0,0,.83129],732:[0,.66786,.11585,0,.51111],733:[0,.69444,.1225,0,.51111],915:[0,.68333,.13305,0,.62722],916:[0,.68333,0,0,.81777],920:[0,.68333,.09403,0,.76666],923:[0,.68333,0,0,.69222],926:[0,.68333,.15294,0,.66444],928:[0,.68333,.16389,0,.74333],931:[0,.68333,.12028,0,.71555],933:[0,.68333,.11111,0,.76666],934:[0,.68333,.05986,0,.71555],936:[0,.68333,.11111,0,.76666],937:[0,.68333,.10257,0,.71555],8211:[0,.43056,.09208,0,.51111],8212:[0,.43056,.09208,0,1.02222],8216:[0,.69444,.12417,0,.30667],8217:[0,.69444,.12417,0,.30667],8220:[0,.69444,.1685,0,.51444],8221:[0,.69444,.06961,0,.51444],8463:[0,.68889,0,0,.54028]},"Main-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.27778],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.77778],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.19444,.10556,0,0,.27778],45:[0,.43056,0,0,.33333],46:[0,.10556,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.64444,0,0,.5],49:[0,.64444,0,0,.5],50:[0,.64444,0,0,.5],51:[0,.64444,0,0,.5],52:[0,.64444,0,0,.5],53:[0,.64444,0,0,.5],54:[0,.64444,0,0,.5],55:[0,.64444,0,0,.5],56:[0,.64444,0,0,.5],57:[0,.64444,0,0,.5],58:[0,.43056,0,0,.27778],59:[.19444,.43056,0,0,.27778],60:[.0391,.5391,0,0,.77778],61:[-.13313,.36687,0,0,.77778],62:[.0391,.5391,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.77778],65:[0,.68333,0,0,.75],66:[0,.68333,0,0,.70834],67:[0,.68333,0,0,.72222],68:[0,.68333,0,0,.76389],69:[0,.68333,0,0,.68056],70:[0,.68333,0,0,.65278],71:[0,.68333,0,0,.78472],72:[0,.68333,0,0,.75],73:[0,.68333,0,0,.36111],74:[0,.68333,0,0,.51389],75:[0,.68333,0,0,.77778],76:[0,.68333,0,0,.625],77:[0,.68333,0,0,.91667],78:[0,.68333,0,0,.75],79:[0,.68333,0,0,.77778],80:[0,.68333,0,0,.68056],81:[.19444,.68333,0,0,.77778],82:[0,.68333,0,0,.73611],83:[0,.68333,0,0,.55556],84:[0,.68333,0,0,.72222],85:[0,.68333,0,0,.75],86:[0,.68333,.01389,0,.75],87:[0,.68333,.01389,0,1.02778],88:[0,.68333,0,0,.75],89:[0,.68333,.025,0,.75],90:[0,.68333,0,0,.61111],91:[.25,.75,0,0,.27778],92:[.25,.75,0,0,.5],93:[.25,.75,0,0,.27778],94:[0,.69444,0,0,.5],95:[.31,.12056,.02778,0,.5],97:[0,.43056,0,0,.5],98:[0,.69444,0,0,.55556],99:[0,.43056,0,0,.44445],100:[0,.69444,0,0,.55556],101:[0,.43056,0,0,.44445],102:[0,.69444,.07778,0,.30556],103:[.19444,.43056,.01389,0,.5],104:[0,.69444,0,0,.55556],105:[0,.66786,0,0,.27778],106:[.19444,.66786,0,0,.30556],107:[0,.69444,0,0,.52778],108:[0,.69444,0,0,.27778],109:[0,.43056,0,0,.83334],110:[0,.43056,0,0,.55556],111:[0,.43056,0,0,.5],112:[.19444,.43056,0,0,.55556],113:[.19444,.43056,0,0,.52778],114:[0,.43056,0,0,.39167],115:[0,.43056,0,0,.39445],116:[0,.61508,0,0,.38889],117:[0,.43056,0,0,.55556],118:[0,.43056,.01389,0,.52778],119:[0,.43056,.01389,0,.72222],120:[0,.43056,0,0,.52778],121:[.19444,.43056,.01389,0,.52778],122:[0,.43056,0,0,.44445],123:[.25,.75,0,0,.5],124:[.25,.75,0,0,.27778],125:[.25,.75,0,0,.5],126:[.35,.31786,0,0,.5],160:[0,0,0,0,.25],163:[0,.69444,0,0,.76909],167:[.19444,.69444,0,0,.44445],168:[0,.66786,0,0,.5],172:[0,.43056,0,0,.66667],176:[0,.69444,0,0,.75],177:[.08333,.58333,0,0,.77778],182:[.19444,.69444,0,0,.61111],184:[.17014,0,0,0,.44445],198:[0,.68333,0,0,.90278],215:[.08333,.58333,0,0,.77778],216:[.04861,.73194,0,0,.77778],223:[0,.69444,0,0,.5],230:[0,.43056,0,0,.72222],247:[.08333,.58333,0,0,.77778],248:[.09722,.52778,0,0,.5],305:[0,.43056,0,0,.27778],338:[0,.68333,0,0,1.01389],339:[0,.43056,0,0,.77778],567:[.19444,.43056,0,0,.30556],710:[0,.69444,0,0,.5],711:[0,.62847,0,0,.5],713:[0,.56778,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.66786,0,0,.27778],730:[0,.69444,0,0,.75],732:[0,.66786,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.68333,0,0,.625],916:[0,.68333,0,0,.83334],920:[0,.68333,0,0,.77778],923:[0,.68333,0,0,.69445],926:[0,.68333,0,0,.66667],928:[0,.68333,0,0,.75],931:[0,.68333,0,0,.72222],933:[0,.68333,0,0,.77778],934:[0,.68333,0,0,.72222],936:[0,.68333,0,0,.77778],937:[0,.68333,0,0,.72222],8211:[0,.43056,.02778,0,.5],8212:[0,.43056,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5],8224:[.19444,.69444,0,0,.44445],8225:[.19444,.69444,0,0,.44445],8230:[0,.123,0,0,1.172],8242:[0,.55556,0,0,.275],8407:[0,.71444,.15382,0,.5],8463:[0,.68889,0,0,.54028],8465:[0,.69444,0,0,.72222],8467:[0,.69444,0,.11111,.41667],8472:[.19444,.43056,0,.11111,.63646],8476:[0,.69444,0,0,.72222],8501:[0,.69444,0,0,.61111],8592:[-.13313,.36687,0,0,1],8593:[.19444,.69444,0,0,.5],8594:[-.13313,.36687,0,0,1],8595:[.19444,.69444,0,0,.5],8596:[-.13313,.36687,0,0,1],8597:[.25,.75,0,0,.5],8598:[.19444,.69444,0,0,1],8599:[.19444,.69444,0,0,1],8600:[.19444,.69444,0,0,1],8601:[.19444,.69444,0,0,1],8614:[.011,.511,0,0,1],8617:[.011,.511,0,0,1.126],8618:[.011,.511,0,0,1.126],8636:[-.13313,.36687,0,0,1],8637:[-.13313,.36687,0,0,1],8640:[-.13313,.36687,0,0,1],8641:[-.13313,.36687,0,0,1],8652:[.011,.671,0,0,1],8656:[-.13313,.36687,0,0,1],8657:[.19444,.69444,0,0,.61111],8658:[-.13313,.36687,0,0,1],8659:[.19444,.69444,0,0,.61111],8660:[-.13313,.36687,0,0,1],8661:[.25,.75,0,0,.61111],8704:[0,.69444,0,0,.55556],8706:[0,.69444,.05556,.08334,.5309],8707:[0,.69444,0,0,.55556],8709:[.05556,.75,0,0,.5],8711:[0,.68333,0,0,.83334],8712:[.0391,.5391,0,0,.66667],8715:[.0391,.5391,0,0,.66667],8722:[.08333,.58333,0,0,.77778],8723:[.08333,.58333,0,0,.77778],8725:[.25,.75,0,0,.5],8726:[.25,.75,0,0,.5],8727:[-.03472,.46528,0,0,.5],8728:[-.05555,.44445,0,0,.5],8729:[-.05555,.44445,0,0,.5],8730:[.2,.8,0,0,.83334],8733:[0,.43056,0,0,.77778],8734:[0,.43056,0,0,1],8736:[0,.69224,0,0,.72222],8739:[.25,.75,0,0,.27778],8741:[.25,.75,0,0,.5],8743:[0,.55556,0,0,.66667],8744:[0,.55556,0,0,.66667],8745:[0,.55556,0,0,.66667],8746:[0,.55556,0,0,.66667],8747:[.19444,.69444,.11111,0,.41667],8764:[-.13313,.36687,0,0,.77778],8768:[.19444,.69444,0,0,.27778],8771:[-.03625,.46375,0,0,.77778],8773:[-.022,.589,0,0,.778],8776:[-.01688,.48312,0,0,.77778],8781:[-.03625,.46375,0,0,.77778],8784:[-.133,.673,0,0,.778],8801:[-.03625,.46375,0,0,.77778],8804:[.13597,.63597,0,0,.77778],8805:[.13597,.63597,0,0,.77778],8810:[.0391,.5391,0,0,1],8811:[.0391,.5391,0,0,1],8826:[.0391,.5391,0,0,.77778],8827:[.0391,.5391,0,0,.77778],8834:[.0391,.5391,0,0,.77778],8835:[.0391,.5391,0,0,.77778],8838:[.13597,.63597,0,0,.77778],8839:[.13597,.63597,0,0,.77778],8846:[0,.55556,0,0,.66667],8849:[.13597,.63597,0,0,.77778],8850:[.13597,.63597,0,0,.77778],8851:[0,.55556,0,0,.66667],8852:[0,.55556,0,0,.66667],8853:[.08333,.58333,0,0,.77778],8854:[.08333,.58333,0,0,.77778],8855:[.08333,.58333,0,0,.77778],8856:[.08333,.58333,0,0,.77778],8857:[.08333,.58333,0,0,.77778],8866:[0,.69444,0,0,.61111],8867:[0,.69444,0,0,.61111],8868:[0,.69444,0,0,.77778],8869:[0,.69444,0,0,.77778],8872:[.249,.75,0,0,.867],8900:[-.05555,.44445,0,0,.5],8901:[-.05555,.44445,0,0,.27778],8902:[-.03472,.46528,0,0,.5],8904:[.005,.505,0,0,.9],8942:[.03,.903,0,0,.278],8943:[-.19,.313,0,0,1.172],8945:[-.1,.823,0,0,1.282],8968:[.25,.75,0,0,.44445],8969:[.25,.75,0,0,.44445],8970:[.25,.75,0,0,.44445],8971:[.25,.75,0,0,.44445],8994:[-.14236,.35764,0,0,1],8995:[-.14236,.35764,0,0,1],9136:[.244,.744,0,0,.412],9137:[.244,.745,0,0,.412],9651:[.19444,.69444,0,0,.88889],9657:[-.03472,.46528,0,0,.5],9661:[.19444,.69444,0,0,.88889],9667:[-.03472,.46528,0,0,.5],9711:[.19444,.69444,0,0,1],9824:[.12963,.69444,0,0,.77778],9825:[.12963,.69444,0,0,.77778],9826:[.12963,.69444,0,0,.77778],9827:[.12963,.69444,0,0,.77778],9837:[0,.75,0,0,.38889],9838:[.19444,.69444,0,0,.38889],9839:[.19444,.69444,0,0,.38889],10216:[.25,.75,0,0,.38889],10217:[.25,.75,0,0,.38889],10222:[.244,.744,0,0,.412],10223:[.244,.745,0,0,.412],10229:[.011,.511,0,0,1.609],10230:[.011,.511,0,0,1.638],10231:[.011,.511,0,0,1.859],10232:[.024,.525,0,0,1.609],10233:[.024,.525,0,0,1.638],10234:[.024,.525,0,0,1.858],10236:[.011,.511,0,0,1.638],10815:[0,.68333,0,0,.75],10927:[.13597,.63597,0,0,.77778],10928:[.13597,.63597,0,0,.77778],57376:[.19444,.69444,0,0,0]},"Math-BoldItalic":{32:[0,0,0,0,.25],48:[0,.44444,0,0,.575],49:[0,.44444,0,0,.575],50:[0,.44444,0,0,.575],51:[.19444,.44444,0,0,.575],52:[.19444,.44444,0,0,.575],53:[.19444,.44444,0,0,.575],54:[0,.64444,0,0,.575],55:[.19444,.44444,0,0,.575],56:[0,.64444,0,0,.575],57:[.19444,.44444,0,0,.575],65:[0,.68611,0,0,.86944],66:[0,.68611,.04835,0,.8664],67:[0,.68611,.06979,0,.81694],68:[0,.68611,.03194,0,.93812],69:[0,.68611,.05451,0,.81007],70:[0,.68611,.15972,0,.68889],71:[0,.68611,0,0,.88673],72:[0,.68611,.08229,0,.98229],73:[0,.68611,.07778,0,.51111],74:[0,.68611,.10069,0,.63125],75:[0,.68611,.06979,0,.97118],76:[0,.68611,0,0,.75555],77:[0,.68611,.11424,0,1.14201],78:[0,.68611,.11424,0,.95034],79:[0,.68611,.03194,0,.83666],80:[0,.68611,.15972,0,.72309],81:[.19444,.68611,0,0,.86861],82:[0,.68611,.00421,0,.87235],83:[0,.68611,.05382,0,.69271],84:[0,.68611,.15972,0,.63663],85:[0,.68611,.11424,0,.80027],86:[0,.68611,.25555,0,.67778],87:[0,.68611,.15972,0,1.09305],88:[0,.68611,.07778,0,.94722],89:[0,.68611,.25555,0,.67458],90:[0,.68611,.06979,0,.77257],97:[0,.44444,0,0,.63287],98:[0,.69444,0,0,.52083],99:[0,.44444,0,0,.51342],100:[0,.69444,0,0,.60972],101:[0,.44444,0,0,.55361],102:[.19444,.69444,.11042,0,.56806],103:[.19444,.44444,.03704,0,.5449],104:[0,.69444,0,0,.66759],105:[0,.69326,0,0,.4048],106:[.19444,.69326,.0622,0,.47083],107:[0,.69444,.01852,0,.6037],108:[0,.69444,.0088,0,.34815],109:[0,.44444,0,0,1.0324],110:[0,.44444,0,0,.71296],111:[0,.44444,0,0,.58472],112:[.19444,.44444,0,0,.60092],113:[.19444,.44444,.03704,0,.54213],114:[0,.44444,.03194,0,.5287],115:[0,.44444,0,0,.53125],116:[0,.63492,0,0,.41528],117:[0,.44444,0,0,.68102],118:[0,.44444,.03704,0,.56666],119:[0,.44444,.02778,0,.83148],120:[0,.44444,0,0,.65903],121:[.19444,.44444,.03704,0,.59028],122:[0,.44444,.04213,0,.55509],160:[0,0,0,0,.25],915:[0,.68611,.15972,0,.65694],916:[0,.68611,0,0,.95833],920:[0,.68611,.03194,0,.86722],923:[0,.68611,0,0,.80555],926:[0,.68611,.07458,0,.84125],928:[0,.68611,.08229,0,.98229],931:[0,.68611,.05451,0,.88507],933:[0,.68611,.15972,0,.67083],934:[0,.68611,0,0,.76666],936:[0,.68611,.11653,0,.71402],937:[0,.68611,.04835,0,.8789],945:[0,.44444,0,0,.76064],946:[.19444,.69444,.03403,0,.65972],947:[.19444,.44444,.06389,0,.59003],948:[0,.69444,.03819,0,.52222],949:[0,.44444,0,0,.52882],950:[.19444,.69444,.06215,0,.50833],951:[.19444,.44444,.03704,0,.6],952:[0,.69444,.03194,0,.5618],953:[0,.44444,0,0,.41204],954:[0,.44444,0,0,.66759],955:[0,.69444,0,0,.67083],956:[.19444,.44444,0,0,.70787],957:[0,.44444,.06898,0,.57685],958:[.19444,.69444,.03021,0,.50833],959:[0,.44444,0,0,.58472],960:[0,.44444,.03704,0,.68241],961:[.19444,.44444,0,0,.6118],962:[.09722,.44444,.07917,0,.42361],963:[0,.44444,.03704,0,.68588],964:[0,.44444,.13472,0,.52083],965:[0,.44444,.03704,0,.63055],966:[.19444,.44444,0,0,.74722],967:[.19444,.44444,0,0,.71805],968:[.19444,.69444,.03704,0,.75833],969:[0,.44444,.03704,0,.71782],977:[0,.69444,0,0,.69155],981:[.19444,.69444,0,0,.7125],982:[0,.44444,.03194,0,.975],1009:[.19444,.44444,0,0,.6118],1013:[0,.44444,0,0,.48333],57649:[0,.44444,0,0,.39352],57911:[.19444,.44444,0,0,.43889]},"Math-Italic":{32:[0,0,0,0,.25],48:[0,.43056,0,0,.5],49:[0,.43056,0,0,.5],50:[0,.43056,0,0,.5],51:[.19444,.43056,0,0,.5],52:[.19444,.43056,0,0,.5],53:[.19444,.43056,0,0,.5],54:[0,.64444,0,0,.5],55:[.19444,.43056,0,0,.5],56:[0,.64444,0,0,.5],57:[.19444,.43056,0,0,.5],65:[0,.68333,0,.13889,.75],66:[0,.68333,.05017,.08334,.75851],67:[0,.68333,.07153,.08334,.71472],68:[0,.68333,.02778,.05556,.82792],69:[0,.68333,.05764,.08334,.7382],70:[0,.68333,.13889,.08334,.64306],71:[0,.68333,0,.08334,.78625],72:[0,.68333,.08125,.05556,.83125],73:[0,.68333,.07847,.11111,.43958],74:[0,.68333,.09618,.16667,.55451],75:[0,.68333,.07153,.05556,.84931],76:[0,.68333,0,.02778,.68056],77:[0,.68333,.10903,.08334,.97014],78:[0,.68333,.10903,.08334,.80347],79:[0,.68333,.02778,.08334,.76278],80:[0,.68333,.13889,.08334,.64201],81:[.19444,.68333,0,.08334,.79056],82:[0,.68333,.00773,.08334,.75929],83:[0,.68333,.05764,.08334,.6132],84:[0,.68333,.13889,.08334,.58438],85:[0,.68333,.10903,.02778,.68278],86:[0,.68333,.22222,0,.58333],87:[0,.68333,.13889,0,.94445],88:[0,.68333,.07847,.08334,.82847],89:[0,.68333,.22222,0,.58056],90:[0,.68333,.07153,.08334,.68264],97:[0,.43056,0,0,.52859],98:[0,.69444,0,0,.42917],99:[0,.43056,0,.05556,.43276],100:[0,.69444,0,.16667,.52049],101:[0,.43056,0,.05556,.46563],102:[.19444,.69444,.10764,.16667,.48959],103:[.19444,.43056,.03588,.02778,.47697],104:[0,.69444,0,0,.57616],105:[0,.65952,0,0,.34451],106:[.19444,.65952,.05724,0,.41181],107:[0,.69444,.03148,0,.5206],108:[0,.69444,.01968,.08334,.29838],109:[0,.43056,0,0,.87801],110:[0,.43056,0,0,.60023],111:[0,.43056,0,.05556,.48472],112:[.19444,.43056,0,.08334,.50313],113:[.19444,.43056,.03588,.08334,.44641],114:[0,.43056,.02778,.05556,.45116],115:[0,.43056,0,.05556,.46875],116:[0,.61508,0,.08334,.36111],117:[0,.43056,0,.02778,.57246],118:[0,.43056,.03588,.02778,.48472],119:[0,.43056,.02691,.08334,.71592],120:[0,.43056,0,.02778,.57153],121:[.19444,.43056,.03588,.05556,.49028],122:[0,.43056,.04398,.05556,.46505],160:[0,0,0,0,.25],915:[0,.68333,.13889,.08334,.61528],916:[0,.68333,0,.16667,.83334],920:[0,.68333,.02778,.08334,.76278],923:[0,.68333,0,.16667,.69445],926:[0,.68333,.07569,.08334,.74236],928:[0,.68333,.08125,.05556,.83125],931:[0,.68333,.05764,.08334,.77986],933:[0,.68333,.13889,.05556,.58333],934:[0,.68333,0,.08334,.66667],936:[0,.68333,.11,.05556,.61222],937:[0,.68333,.05017,.08334,.7724],945:[0,.43056,.0037,.02778,.6397],946:[.19444,.69444,.05278,.08334,.56563],947:[.19444,.43056,.05556,0,.51773],948:[0,.69444,.03785,.05556,.44444],949:[0,.43056,0,.08334,.46632],950:[.19444,.69444,.07378,.08334,.4375],951:[.19444,.43056,.03588,.05556,.49653],952:[0,.69444,.02778,.08334,.46944],953:[0,.43056,0,.05556,.35394],954:[0,.43056,0,0,.57616],955:[0,.69444,0,0,.58334],956:[.19444,.43056,0,.02778,.60255],957:[0,.43056,.06366,.02778,.49398],958:[.19444,.69444,.04601,.11111,.4375],959:[0,.43056,0,.05556,.48472],960:[0,.43056,.03588,0,.57003],961:[.19444,.43056,0,.08334,.51702],962:[.09722,.43056,.07986,.08334,.36285],963:[0,.43056,.03588,0,.57141],964:[0,.43056,.1132,.02778,.43715],965:[0,.43056,.03588,.02778,.54028],966:[.19444,.43056,0,.08334,.65417],967:[.19444,.43056,0,.05556,.62569],968:[.19444,.69444,.03588,.11111,.65139],969:[0,.43056,.03588,0,.62245],977:[0,.69444,0,.08334,.59144],981:[.19444,.69444,0,.08334,.59583],982:[0,.43056,.02778,0,.82813],1009:[.19444,.43056,0,.08334,.51702],1013:[0,.43056,0,.05556,.4059],57649:[0,.43056,0,.02778,.32246],57911:[.19444,.43056,0,.08334,.38403]},"SansSerif-Bold":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.36667],34:[0,.69444,0,0,.55834],35:[.19444,.69444,0,0,.91667],36:[.05556,.75,0,0,.55],37:[.05556,.75,0,0,1.02912],38:[0,.69444,0,0,.83056],39:[0,.69444,0,0,.30556],40:[.25,.75,0,0,.42778],41:[.25,.75,0,0,.42778],42:[0,.75,0,0,.55],43:[.11667,.61667,0,0,.85556],44:[.10556,.13056,0,0,.30556],45:[0,.45833,0,0,.36667],46:[0,.13056,0,0,.30556],47:[.25,.75,0,0,.55],48:[0,.69444,0,0,.55],49:[0,.69444,0,0,.55],50:[0,.69444,0,0,.55],51:[0,.69444,0,0,.55],52:[0,.69444,0,0,.55],53:[0,.69444,0,0,.55],54:[0,.69444,0,0,.55],55:[0,.69444,0,0,.55],56:[0,.69444,0,0,.55],57:[0,.69444,0,0,.55],58:[0,.45833,0,0,.30556],59:[.10556,.45833,0,0,.30556],61:[-.09375,.40625,0,0,.85556],63:[0,.69444,0,0,.51945],64:[0,.69444,0,0,.73334],65:[0,.69444,0,0,.73334],66:[0,.69444,0,0,.73334],67:[0,.69444,0,0,.70278],68:[0,.69444,0,0,.79445],69:[0,.69444,0,0,.64167],70:[0,.69444,0,0,.61111],71:[0,.69444,0,0,.73334],72:[0,.69444,0,0,.79445],73:[0,.69444,0,0,.33056],74:[0,.69444,0,0,.51945],75:[0,.69444,0,0,.76389],76:[0,.69444,0,0,.58056],77:[0,.69444,0,0,.97778],78:[0,.69444,0,0,.79445],79:[0,.69444,0,0,.79445],80:[0,.69444,0,0,.70278],81:[.10556,.69444,0,0,.79445],82:[0,.69444,0,0,.70278],83:[0,.69444,0,0,.61111],84:[0,.69444,0,0,.73334],85:[0,.69444,0,0,.76389],86:[0,.69444,.01528,0,.73334],87:[0,.69444,.01528,0,1.03889],88:[0,.69444,0,0,.73334],89:[0,.69444,.0275,0,.73334],90:[0,.69444,0,0,.67223],91:[.25,.75,0,0,.34306],93:[.25,.75,0,0,.34306],94:[0,.69444,0,0,.55],95:[.35,.10833,.03056,0,.55],97:[0,.45833,0,0,.525],98:[0,.69444,0,0,.56111],99:[0,.45833,0,0,.48889],100:[0,.69444,0,0,.56111],101:[0,.45833,0,0,.51111],102:[0,.69444,.07639,0,.33611],103:[.19444,.45833,.01528,0,.55],104:[0,.69444,0,0,.56111],105:[0,.69444,0,0,.25556],106:[.19444,.69444,0,0,.28611],107:[0,.69444,0,0,.53056],108:[0,.69444,0,0,.25556],109:[0,.45833,0,0,.86667],110:[0,.45833,0,0,.56111],111:[0,.45833,0,0,.55],112:[.19444,.45833,0,0,.56111],113:[.19444,.45833,0,0,.56111],114:[0,.45833,.01528,0,.37222],115:[0,.45833,0,0,.42167],116:[0,.58929,0,0,.40417],117:[0,.45833,0,0,.56111],118:[0,.45833,.01528,0,.5],119:[0,.45833,.01528,0,.74445],120:[0,.45833,0,0,.5],121:[.19444,.45833,.01528,0,.5],122:[0,.45833,0,0,.47639],126:[.35,.34444,0,0,.55],160:[0,0,0,0,.25],168:[0,.69444,0,0,.55],176:[0,.69444,0,0,.73334],180:[0,.69444,0,0,.55],184:[.17014,0,0,0,.48889],305:[0,.45833,0,0,.25556],567:[.19444,.45833,0,0,.28611],710:[0,.69444,0,0,.55],711:[0,.63542,0,0,.55],713:[0,.63778,0,0,.55],728:[0,.69444,0,0,.55],729:[0,.69444,0,0,.30556],730:[0,.69444,0,0,.73334],732:[0,.69444,0,0,.55],733:[0,.69444,0,0,.55],915:[0,.69444,0,0,.58056],916:[0,.69444,0,0,.91667],920:[0,.69444,0,0,.85556],923:[0,.69444,0,0,.67223],926:[0,.69444,0,0,.73334],928:[0,.69444,0,0,.79445],931:[0,.69444,0,0,.79445],933:[0,.69444,0,0,.85556],934:[0,.69444,0,0,.79445],936:[0,.69444,0,0,.85556],937:[0,.69444,0,0,.79445],8211:[0,.45833,.03056,0,.55],8212:[0,.45833,.03056,0,1.10001],8216:[0,.69444,0,0,.30556],8217:[0,.69444,0,0,.30556],8220:[0,.69444,0,0,.55834],8221:[0,.69444,0,0,.55834]},"SansSerif-Italic":{32:[0,0,0,0,.25],33:[0,.69444,.05733,0,.31945],34:[0,.69444,.00316,0,.5],35:[.19444,.69444,.05087,0,.83334],36:[.05556,.75,.11156,0,.5],37:[.05556,.75,.03126,0,.83334],38:[0,.69444,.03058,0,.75834],39:[0,.69444,.07816,0,.27778],40:[.25,.75,.13164,0,.38889],41:[.25,.75,.02536,0,.38889],42:[0,.75,.11775,0,.5],43:[.08333,.58333,.02536,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,.01946,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,.13164,0,.5],48:[0,.65556,.11156,0,.5],49:[0,.65556,.11156,0,.5],50:[0,.65556,.11156,0,.5],51:[0,.65556,.11156,0,.5],52:[0,.65556,.11156,0,.5],53:[0,.65556,.11156,0,.5],54:[0,.65556,.11156,0,.5],55:[0,.65556,.11156,0,.5],56:[0,.65556,.11156,0,.5],57:[0,.65556,.11156,0,.5],58:[0,.44444,.02502,0,.27778],59:[.125,.44444,.02502,0,.27778],61:[-.13,.37,.05087,0,.77778],63:[0,.69444,.11809,0,.47222],64:[0,.69444,.07555,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,.08293,0,.66667],67:[0,.69444,.11983,0,.63889],68:[0,.69444,.07555,0,.72223],69:[0,.69444,.11983,0,.59722],70:[0,.69444,.13372,0,.56945],71:[0,.69444,.11983,0,.66667],72:[0,.69444,.08094,0,.70834],73:[0,.69444,.13372,0,.27778],74:[0,.69444,.08094,0,.47222],75:[0,.69444,.11983,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,.08094,0,.875],78:[0,.69444,.08094,0,.70834],79:[0,.69444,.07555,0,.73611],80:[0,.69444,.08293,0,.63889],81:[.125,.69444,.07555,0,.73611],82:[0,.69444,.08293,0,.64584],83:[0,.69444,.09205,0,.55556],84:[0,.69444,.13372,0,.68056],85:[0,.69444,.08094,0,.6875],86:[0,.69444,.1615,0,.66667],87:[0,.69444,.1615,0,.94445],88:[0,.69444,.13372,0,.66667],89:[0,.69444,.17261,0,.66667],90:[0,.69444,.11983,0,.61111],91:[.25,.75,.15942,0,.28889],93:[.25,.75,.08719,0,.28889],94:[0,.69444,.0799,0,.5],95:[.35,.09444,.08616,0,.5],97:[0,.44444,.00981,0,.48056],98:[0,.69444,.03057,0,.51667],99:[0,.44444,.08336,0,.44445],100:[0,.69444,.09483,0,.51667],101:[0,.44444,.06778,0,.44445],102:[0,.69444,.21705,0,.30556],103:[.19444,.44444,.10836,0,.5],104:[0,.69444,.01778,0,.51667],105:[0,.67937,.09718,0,.23889],106:[.19444,.67937,.09162,0,.26667],107:[0,.69444,.08336,0,.48889],108:[0,.69444,.09483,0,.23889],109:[0,.44444,.01778,0,.79445],110:[0,.44444,.01778,0,.51667],111:[0,.44444,.06613,0,.5],112:[.19444,.44444,.0389,0,.51667],113:[.19444,.44444,.04169,0,.51667],114:[0,.44444,.10836,0,.34167],115:[0,.44444,.0778,0,.38333],116:[0,.57143,.07225,0,.36111],117:[0,.44444,.04169,0,.51667],118:[0,.44444,.10836,0,.46111],119:[0,.44444,.10836,0,.68334],120:[0,.44444,.09169,0,.46111],121:[.19444,.44444,.10836,0,.46111],122:[0,.44444,.08752,0,.43472],126:[.35,.32659,.08826,0,.5],160:[0,0,0,0,.25],168:[0,.67937,.06385,0,.5],176:[0,.69444,0,0,.73752],184:[.17014,0,0,0,.44445],305:[0,.44444,.04169,0,.23889],567:[.19444,.44444,.04169,0,.26667],710:[0,.69444,.0799,0,.5],711:[0,.63194,.08432,0,.5],713:[0,.60889,.08776,0,.5],714:[0,.69444,.09205,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,.09483,0,.5],729:[0,.67937,.07774,0,.27778],730:[0,.69444,0,0,.73752],732:[0,.67659,.08826,0,.5],733:[0,.69444,.09205,0,.5],915:[0,.69444,.13372,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,.07555,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,.12816,0,.66667],928:[0,.69444,.08094,0,.70834],931:[0,.69444,.11983,0,.72222],933:[0,.69444,.09031,0,.77778],934:[0,.69444,.04603,0,.72222],936:[0,.69444,.09031,0,.77778],937:[0,.69444,.08293,0,.72222],8211:[0,.44444,.08616,0,.5],8212:[0,.44444,.08616,0,1],8216:[0,.69444,.07816,0,.27778],8217:[0,.69444,.07816,0,.27778],8220:[0,.69444,.14205,0,.5],8221:[0,.69444,.00316,0,.5]},"SansSerif-Regular":{32:[0,0,0,0,.25],33:[0,.69444,0,0,.31945],34:[0,.69444,0,0,.5],35:[.19444,.69444,0,0,.83334],36:[.05556,.75,0,0,.5],37:[.05556,.75,0,0,.83334],38:[0,.69444,0,0,.75834],39:[0,.69444,0,0,.27778],40:[.25,.75,0,0,.38889],41:[.25,.75,0,0,.38889],42:[0,.75,0,0,.5],43:[.08333,.58333,0,0,.77778],44:[.125,.08333,0,0,.27778],45:[0,.44444,0,0,.33333],46:[0,.08333,0,0,.27778],47:[.25,.75,0,0,.5],48:[0,.65556,0,0,.5],49:[0,.65556,0,0,.5],50:[0,.65556,0,0,.5],51:[0,.65556,0,0,.5],52:[0,.65556,0,0,.5],53:[0,.65556,0,0,.5],54:[0,.65556,0,0,.5],55:[0,.65556,0,0,.5],56:[0,.65556,0,0,.5],57:[0,.65556,0,0,.5],58:[0,.44444,0,0,.27778],59:[.125,.44444,0,0,.27778],61:[-.13,.37,0,0,.77778],63:[0,.69444,0,0,.47222],64:[0,.69444,0,0,.66667],65:[0,.69444,0,0,.66667],66:[0,.69444,0,0,.66667],67:[0,.69444,0,0,.63889],68:[0,.69444,0,0,.72223],69:[0,.69444,0,0,.59722],70:[0,.69444,0,0,.56945],71:[0,.69444,0,0,.66667],72:[0,.69444,0,0,.70834],73:[0,.69444,0,0,.27778],74:[0,.69444,0,0,.47222],75:[0,.69444,0,0,.69445],76:[0,.69444,0,0,.54167],77:[0,.69444,0,0,.875],78:[0,.69444,0,0,.70834],79:[0,.69444,0,0,.73611],80:[0,.69444,0,0,.63889],81:[.125,.69444,0,0,.73611],82:[0,.69444,0,0,.64584],83:[0,.69444,0,0,.55556],84:[0,.69444,0,0,.68056],85:[0,.69444,0,0,.6875],86:[0,.69444,.01389,0,.66667],87:[0,.69444,.01389,0,.94445],88:[0,.69444,0,0,.66667],89:[0,.69444,.025,0,.66667],90:[0,.69444,0,0,.61111],91:[.25,.75,0,0,.28889],93:[.25,.75,0,0,.28889],94:[0,.69444,0,0,.5],95:[.35,.09444,.02778,0,.5],97:[0,.44444,0,0,.48056],98:[0,.69444,0,0,.51667],99:[0,.44444,0,0,.44445],100:[0,.69444,0,0,.51667],101:[0,.44444,0,0,.44445],102:[0,.69444,.06944,0,.30556],103:[.19444,.44444,.01389,0,.5],104:[0,.69444,0,0,.51667],105:[0,.67937,0,0,.23889],106:[.19444,.67937,0,0,.26667],107:[0,.69444,0,0,.48889],108:[0,.69444,0,0,.23889],109:[0,.44444,0,0,.79445],110:[0,.44444,0,0,.51667],111:[0,.44444,0,0,.5],112:[.19444,.44444,0,0,.51667],113:[.19444,.44444,0,0,.51667],114:[0,.44444,.01389,0,.34167],115:[0,.44444,0,0,.38333],116:[0,.57143,0,0,.36111],117:[0,.44444,0,0,.51667],118:[0,.44444,.01389,0,.46111],119:[0,.44444,.01389,0,.68334],120:[0,.44444,0,0,.46111],121:[.19444,.44444,.01389,0,.46111],122:[0,.44444,0,0,.43472],126:[.35,.32659,0,0,.5],160:[0,0,0,0,.25],168:[0,.67937,0,0,.5],176:[0,.69444,0,0,.66667],184:[.17014,0,0,0,.44445],305:[0,.44444,0,0,.23889],567:[.19444,.44444,0,0,.26667],710:[0,.69444,0,0,.5],711:[0,.63194,0,0,.5],713:[0,.60889,0,0,.5],714:[0,.69444,0,0,.5],715:[0,.69444,0,0,.5],728:[0,.69444,0,0,.5],729:[0,.67937,0,0,.27778],730:[0,.69444,0,0,.66667],732:[0,.67659,0,0,.5],733:[0,.69444,0,0,.5],915:[0,.69444,0,0,.54167],916:[0,.69444,0,0,.83334],920:[0,.69444,0,0,.77778],923:[0,.69444,0,0,.61111],926:[0,.69444,0,0,.66667],928:[0,.69444,0,0,.70834],931:[0,.69444,0,0,.72222],933:[0,.69444,0,0,.77778],934:[0,.69444,0,0,.72222],936:[0,.69444,0,0,.77778],937:[0,.69444,0,0,.72222],8211:[0,.44444,.02778,0,.5],8212:[0,.44444,.02778,0,1],8216:[0,.69444,0,0,.27778],8217:[0,.69444,0,0,.27778],8220:[0,.69444,0,0,.5],8221:[0,.69444,0,0,.5]},"Script-Regular":{32:[0,0,0,0,.25],65:[0,.7,.22925,0,.80253],66:[0,.7,.04087,0,.90757],67:[0,.7,.1689,0,.66619],68:[0,.7,.09371,0,.77443],69:[0,.7,.18583,0,.56162],70:[0,.7,.13634,0,.89544],71:[0,.7,.17322,0,.60961],72:[0,.7,.29694,0,.96919],73:[0,.7,.19189,0,.80907],74:[.27778,.7,.19189,0,1.05159],75:[0,.7,.31259,0,.91364],76:[0,.7,.19189,0,.87373],77:[0,.7,.15981,0,1.08031],78:[0,.7,.3525,0,.9015],79:[0,.7,.08078,0,.73787],80:[0,.7,.08078,0,1.01262],81:[0,.7,.03305,0,.88282],82:[0,.7,.06259,0,.85],83:[0,.7,.19189,0,.86767],84:[0,.7,.29087,0,.74697],85:[0,.7,.25815,0,.79996],86:[0,.7,.27523,0,.62204],87:[0,.7,.27523,0,.80532],88:[0,.7,.26006,0,.94445],89:[0,.7,.2939,0,.70961],90:[0,.7,.24037,0,.8212],160:[0,0,0,0,.25]},"Size1-Regular":{32:[0,0,0,0,.25],40:[.35001,.85,0,0,.45834],41:[.35001,.85,0,0,.45834],47:[.35001,.85,0,0,.57778],91:[.35001,.85,0,0,.41667],92:[.35001,.85,0,0,.57778],93:[.35001,.85,0,0,.41667],123:[.35001,.85,0,0,.58334],125:[.35001,.85,0,0,.58334],160:[0,0,0,0,.25],710:[0,.72222,0,0,.55556],732:[0,.72222,0,0,.55556],770:[0,.72222,0,0,.55556],771:[0,.72222,0,0,.55556],8214:[-99e-5,.601,0,0,.77778],8593:[1e-5,.6,0,0,.66667],8595:[1e-5,.6,0,0,.66667],8657:[1e-5,.6,0,0,.77778],8659:[1e-5,.6,0,0,.77778],8719:[.25001,.75,0,0,.94445],8720:[.25001,.75,0,0,.94445],8721:[.25001,.75,0,0,1.05556],8730:[.35001,.85,0,0,1],8739:[-.00599,.606,0,0,.33333],8741:[-.00599,.606,0,0,.55556],8747:[.30612,.805,.19445,0,.47222],8748:[.306,.805,.19445,0,.47222],8749:[.306,.805,.19445,0,.47222],8750:[.30612,.805,.19445,0,.47222],8896:[.25001,.75,0,0,.83334],8897:[.25001,.75,0,0,.83334],8898:[.25001,.75,0,0,.83334],8899:[.25001,.75,0,0,.83334],8968:[.35001,.85,0,0,.47222],8969:[.35001,.85,0,0,.47222],8970:[.35001,.85,0,0,.47222],8971:[.35001,.85,0,0,.47222],9168:[-99e-5,.601,0,0,.66667],10216:[.35001,.85,0,0,.47222],10217:[.35001,.85,0,0,.47222],10752:[.25001,.75,0,0,1.11111],10753:[.25001,.75,0,0,1.11111],10754:[.25001,.75,0,0,1.11111],10756:[.25001,.75,0,0,.83334],10758:[.25001,.75,0,0,.83334]},"Size2-Regular":{32:[0,0,0,0,.25],40:[.65002,1.15,0,0,.59722],41:[.65002,1.15,0,0,.59722],47:[.65002,1.15,0,0,.81111],91:[.65002,1.15,0,0,.47222],92:[.65002,1.15,0,0,.81111],93:[.65002,1.15,0,0,.47222],123:[.65002,1.15,0,0,.66667],125:[.65002,1.15,0,0,.66667],160:[0,0,0,0,.25],710:[0,.75,0,0,1],732:[0,.75,0,0,1],770:[0,.75,0,0,1],771:[0,.75,0,0,1],8719:[.55001,1.05,0,0,1.27778],8720:[.55001,1.05,0,0,1.27778],8721:[.55001,1.05,0,0,1.44445],8730:[.65002,1.15,0,0,1],8747:[.86225,1.36,.44445,0,.55556],8748:[.862,1.36,.44445,0,.55556],8749:[.862,1.36,.44445,0,.55556],8750:[.86225,1.36,.44445,0,.55556],8896:[.55001,1.05,0,0,1.11111],8897:[.55001,1.05,0,0,1.11111],8898:[.55001,1.05,0,0,1.11111],8899:[.55001,1.05,0,0,1.11111],8968:[.65002,1.15,0,0,.52778],8969:[.65002,1.15,0,0,.52778],8970:[.65002,1.15,0,0,.52778],8971:[.65002,1.15,0,0,.52778],10216:[.65002,1.15,0,0,.61111],10217:[.65002,1.15,0,0,.61111],10752:[.55001,1.05,0,0,1.51112],10753:[.55001,1.05,0,0,1.51112],10754:[.55001,1.05,0,0,1.51112],10756:[.55001,1.05,0,0,1.11111],10758:[.55001,1.05,0,0,1.11111]},"Size3-Regular":{32:[0,0,0,0,.25],40:[.95003,1.45,0,0,.73611],41:[.95003,1.45,0,0,.73611],47:[.95003,1.45,0,0,1.04445],91:[.95003,1.45,0,0,.52778],92:[.95003,1.45,0,0,1.04445],93:[.95003,1.45,0,0,.52778],123:[.95003,1.45,0,0,.75],125:[.95003,1.45,0,0,.75],160:[0,0,0,0,.25],710:[0,.75,0,0,1.44445],732:[0,.75,0,0,1.44445],770:[0,.75,0,0,1.44445],771:[0,.75,0,0,1.44445],8730:[.95003,1.45,0,0,1],8968:[.95003,1.45,0,0,.58334],8969:[.95003,1.45,0,0,.58334],8970:[.95003,1.45,0,0,.58334],8971:[.95003,1.45,0,0,.58334],10216:[.95003,1.45,0,0,.75],10217:[.95003,1.45,0,0,.75]},"Size4-Regular":{32:[0,0,0,0,.25],40:[1.25003,1.75,0,0,.79167],41:[1.25003,1.75,0,0,.79167],47:[1.25003,1.75,0,0,1.27778],91:[1.25003,1.75,0,0,.58334],92:[1.25003,1.75,0,0,1.27778],93:[1.25003,1.75,0,0,.58334],123:[1.25003,1.75,0,0,.80556],125:[1.25003,1.75,0,0,.80556],160:[0,0,0,0,.25],710:[0,.825,0,0,1.8889],732:[0,.825,0,0,1.8889],770:[0,.825,0,0,1.8889],771:[0,.825,0,0,1.8889],8730:[1.25003,1.75,0,0,1],8968:[1.25003,1.75,0,0,.63889],8969:[1.25003,1.75,0,0,.63889],8970:[1.25003,1.75,0,0,.63889],8971:[1.25003,1.75,0,0,.63889],9115:[.64502,1.155,0,0,.875],9116:[1e-5,.6,0,0,.875],9117:[.64502,1.155,0,0,.875],9118:[.64502,1.155,0,0,.875],9119:[1e-5,.6,0,0,.875],9120:[.64502,1.155,0,0,.875],9121:[.64502,1.155,0,0,.66667],9122:[-99e-5,.601,0,0,.66667],9123:[.64502,1.155,0,0,.66667],9124:[.64502,1.155,0,0,.66667],9125:[-99e-5,.601,0,0,.66667],9126:[.64502,1.155,0,0,.66667],9127:[1e-5,.9,0,0,.88889],9128:[.65002,1.15,0,0,.88889],9129:[.90001,0,0,0,.88889],9130:[0,.3,0,0,.88889],9131:[1e-5,.9,0,0,.88889],9132:[.65002,1.15,0,0,.88889],9133:[.90001,0,0,0,.88889],9143:[.88502,.915,0,0,1.05556],10216:[1.25003,1.75,0,0,.80556],10217:[1.25003,1.75,0,0,.80556],57344:[-.00499,.605,0,0,1.05556],57345:[-.00499,.605,0,0,1.05556],57680:[0,.12,0,0,.45],57681:[0,.12,0,0,.45],57682:[0,.12,0,0,.45],57683:[0,.12,0,0,.45]},"Typewriter-Regular":{32:[0,0,0,0,.525],33:[0,.61111,0,0,.525],34:[0,.61111,0,0,.525],35:[0,.61111,0,0,.525],36:[.08333,.69444,0,0,.525],37:[.08333,.69444,0,0,.525],38:[0,.61111,0,0,.525],39:[0,.61111,0,0,.525],40:[.08333,.69444,0,0,.525],41:[.08333,.69444,0,0,.525],42:[0,.52083,0,0,.525],43:[-.08056,.53055,0,0,.525],44:[.13889,.125,0,0,.525],45:[-.08056,.53055,0,0,.525],46:[0,.125,0,0,.525],47:[.08333,.69444,0,0,.525],48:[0,.61111,0,0,.525],49:[0,.61111,0,0,.525],50:[0,.61111,0,0,.525],51:[0,.61111,0,0,.525],52:[0,.61111,0,0,.525],53:[0,.61111,0,0,.525],54:[0,.61111,0,0,.525],55:[0,.61111,0,0,.525],56:[0,.61111,0,0,.525],57:[0,.61111,0,0,.525],58:[0,.43056,0,0,.525],59:[.13889,.43056,0,0,.525],60:[-.05556,.55556,0,0,.525],61:[-.19549,.41562,0,0,.525],62:[-.05556,.55556,0,0,.525],63:[0,.61111,0,0,.525],64:[0,.61111,0,0,.525],65:[0,.61111,0,0,.525],66:[0,.61111,0,0,.525],67:[0,.61111,0,0,.525],68:[0,.61111,0,0,.525],69:[0,.61111,0,0,.525],70:[0,.61111,0,0,.525],71:[0,.61111,0,0,.525],72:[0,.61111,0,0,.525],73:[0,.61111,0,0,.525],74:[0,.61111,0,0,.525],75:[0,.61111,0,0,.525],76:[0,.61111,0,0,.525],77:[0,.61111,0,0,.525],78:[0,.61111,0,0,.525],79:[0,.61111,0,0,.525],80:[0,.61111,0,0,.525],81:[.13889,.61111,0,0,.525],82:[0,.61111,0,0,.525],83:[0,.61111,0,0,.525],84:[0,.61111,0,0,.525],85:[0,.61111,0,0,.525],86:[0,.61111,0,0,.525],87:[0,.61111,0,0,.525],88:[0,.61111,0,0,.525],89:[0,.61111,0,0,.525],90:[0,.61111,0,0,.525],91:[.08333,.69444,0,0,.525],92:[.08333,.69444,0,0,.525],93:[.08333,.69444,0,0,.525],94:[0,.61111,0,0,.525],95:[.09514,0,0,0,.525],96:[0,.61111,0,0,.525],97:[0,.43056,0,0,.525],98:[0,.61111,0,0,.525],99:[0,.43056,0,0,.525],100:[0,.61111,0,0,.525],101:[0,.43056,0,0,.525],102:[0,.61111,0,0,.525],103:[.22222,.43056,0,0,.525],104:[0,.61111,0,0,.525],105:[0,.61111,0,0,.525],106:[.22222,.61111,0,0,.525],107:[0,.61111,0,0,.525],108:[0,.61111,0,0,.525],109:[0,.43056,0,0,.525],110:[0,.43056,0,0,.525],111:[0,.43056,0,0,.525],112:[.22222,.43056,0,0,.525],113:[.22222,.43056,0,0,.525],114:[0,.43056,0,0,.525],115:[0,.43056,0,0,.525],116:[0,.55358,0,0,.525],117:[0,.43056,0,0,.525],118:[0,.43056,0,0,.525],119:[0,.43056,0,0,.525],120:[0,.43056,0,0,.525],121:[.22222,.43056,0,0,.525],122:[0,.43056,0,0,.525],123:[.08333,.69444,0,0,.525],124:[.08333,.69444,0,0,.525],125:[.08333,.69444,0,0,.525],126:[0,.61111,0,0,.525],127:[0,.61111,0,0,.525],160:[0,0,0,0,.525],176:[0,.61111,0,0,.525],184:[.19445,0,0,0,.525],305:[0,.43056,0,0,.525],567:[.22222,.43056,0,0,.525],711:[0,.56597,0,0,.525],713:[0,.56555,0,0,.525],714:[0,.61111,0,0,.525],715:[0,.61111,0,0,.525],728:[0,.61111,0,0,.525],730:[0,.61111,0,0,.525],770:[0,.61111,0,0,.525],771:[0,.61111,0,0,.525],776:[0,.61111,0,0,.525],915:[0,.61111,0,0,.525],916:[0,.61111,0,0,.525],920:[0,.61111,0,0,.525],923:[0,.61111,0,0,.525],926:[0,.61111,0,0,.525],928:[0,.61111,0,0,.525],931:[0,.61111,0,0,.525],933:[0,.61111,0,0,.525],934:[0,.61111,0,0,.525],936:[0,.61111,0,0,.525],937:[0,.61111,0,0,.525],8216:[0,.61111,0,0,.525],8217:[0,.61111,0,0,.525],8242:[0,.61111,0,0,.525],9251:[.11111,.21944,0,0,.525]}},kG={slant:[.25,.25,.25],space:[0,0,0],stretch:[0,0,0],shrink:[0,0,0],xHeight:[.431,.431,.431],quad:[1,1.171,1.472],extraSpace:[0,0,0],num1:[.677,.732,.925],num2:[.394,.384,.387],num3:[.444,.471,.504],denom1:[.686,.752,1.025],denom2:[.345,.344,.532],sup1:[.413,.503,.504],sup2:[.363,.431,.404],sup3:[.289,.286,.294],sub1:[.15,.143,.2],sub2:[.247,.286,.4],supDrop:[.386,.353,.494],subDrop:[.05,.071,.1],delim1:[2.39,1.7,1.98],delim2:[1.01,1.157,1.42],axisHeight:[.25,.25,.25],defaultRuleThickness:[.04,.049,.049],bigOpSpacing1:[.111,.111,.111],bigOpSpacing2:[.166,.166,.166],bigOpSpacing3:[.2,.2,.2],bigOpSpacing4:[.6,.611,.611],bigOpSpacing5:[.1,.143,.143],sqrtRuleThickness:[.04,.04,.04],ptPerEm:[10,10,10],doubleRuleSep:[.2,.2,.2],arrayRuleWidth:[.04,.04,.04],fboxsep:[.3,.3,.3],fboxrule:[.04,.04,.04]},AG={Å:`A`,Ð:`D`,Þ:`o`,å:`a`,ð:`d`,þ:`o`,А:`A`,Б:`B`,В:`B`,Г:`F`,Д:`A`,Е:`E`,Ж:`K`,З:`3`,И:`N`,Й:`N`,К:`K`,Л:`N`,М:`M`,Н:`H`,О:`O`,П:`N`,Р:`P`,С:`C`,Т:`T`,У:`y`,Ф:`O`,Х:`X`,Ц:`U`,Ч:`h`,Ш:`W`,Щ:`W`,Ъ:`B`,Ы:`X`,Ь:`B`,Э:`3`,Ю:`X`,Я:`R`,а:`a`,б:`b`,в:`a`,г:`r`,д:`y`,е:`e`,ж:`m`,з:`e`,и:`n`,й:`n`,к:`n`,л:`n`,м:`m`,н:`n`,о:`o`,п:`n`,р:`p`,с:`c`,т:`o`,у:`y`,ф:`b`,х:`x`,ц:`n`,ч:`n`,ш:`w`,щ:`w`,ъ:`a`,ы:`m`,ь:`a`,э:`e`,ю:`m`,я:`r`};function jG(e,t){OG[e]=t}function MG(e,t,n){if(!OG[t])throw Error(`Font metrics not found for font: `+t+`.`);var r=e.charCodeAt(0),i=OG[t][r];if(!i&&e[0]in AG&&(r=AG[e[0]].charCodeAt(0),i=OG[t][r]),!i&&n===`text`&&GW(r)&&(i=OG[t][77]),i)return{depth:i[0],height:i[1],italic:i[2],skew:i[3],width:i[4]}}var NG={};function PG(e){var t=e>=5?0:e>=3?1:2;if(!NG[t]){var n=NG[t]={cssEmPerMu:kG.quad[t]/18};for(var r of Object.keys(kG))n[r]=kG[r][t]}return NG[t]}var FG={math:{},text:{}};function B(e,t,n,r,i,a){FG[e][i]={font:t,group:n,replace:r},a&&r&&(FG[e][r]=FG[e][i])}var V=`math`,H=`text`,U=`main`,W=`ams`,IG=`accent-token`,G=`bin`,LG=`close`,RG=`inner`,K=`mathord`,zG=`op-token`,BG=`open`,VG=`punct`,q=`rel`,HG=`spacing`,J=`textord`;B(V,U,q,`≡`,`\\equiv`,!0),B(V,U,q,`≺`,`\\prec`,!0),B(V,U,q,`≻`,`\\succ`,!0),B(V,U,q,`∼`,`\\sim`,!0),B(V,U,q,`⊥`,`\\perp`),B(V,U,q,`⪯`,`\\preceq`,!0),B(V,U,q,`⪰`,`\\succeq`,!0),B(V,U,q,`≃`,`\\simeq`,!0),B(V,U,q,`∣`,`\\mid`,!0),B(V,U,q,`≪`,`\\ll`,!0),B(V,U,q,`≫`,`\\gg`,!0),B(V,U,q,`≍`,`\\asymp`,!0),B(V,U,q,`∥`,`\\parallel`),B(V,U,q,`⋈`,`\\bowtie`,!0),B(V,U,q,`⌣`,`\\smile`,!0),B(V,U,q,`⊑`,`\\sqsubseteq`,!0),B(V,U,q,`⊒`,`\\sqsupseteq`,!0),B(V,U,q,`≐`,`\\doteq`,!0),B(V,U,q,`⌢`,`\\frown`,!0),B(V,U,q,`∋`,`\\ni`,!0),B(V,U,q,`∝`,`\\propto`,!0),B(V,U,q,`⊢`,`\\vdash`,!0),B(V,U,q,`⊣`,`\\dashv`,!0),B(V,U,q,`∋`,`\\owns`),B(V,U,VG,`.`,`\\ldotp`),B(V,U,VG,`⋅`,`\\cdotp`),B(V,U,VG,`⋅`,`·`),B(H,U,J,`⋅`,`·`),B(V,U,J,`#`,`\\#`),B(H,U,J,`#`,`\\#`),B(V,U,J,`&`,`\\&`),B(H,U,J,`&`,`\\&`),B(V,U,J,`ℵ`,`\\aleph`,!0),B(V,U,J,`∀`,`\\forall`,!0),B(V,U,J,`ℏ`,`\\hbar`,!0),B(V,U,J,`∃`,`\\exists`,!0),B(V,U,J,`∇`,`\\nabla`,!0),B(V,U,J,`♭`,`\\flat`,!0),B(V,U,J,`ℓ`,`\\ell`,!0),B(V,U,J,`♮`,`\\natural`,!0),B(V,U,J,`♣`,`\\clubsuit`,!0),B(V,U,J,`℘`,`\\wp`,!0),B(V,U,J,`♯`,`\\sharp`,!0),B(V,U,J,`♢`,`\\diamondsuit`,!0),B(V,U,J,`ℜ`,`\\Re`,!0),B(V,U,J,`♡`,`\\heartsuit`,!0),B(V,U,J,`ℑ`,`\\Im`,!0),B(V,U,J,`♠`,`\\spadesuit`,!0),B(V,U,J,`§`,`\\S`,!0),B(H,U,J,`§`,`\\S`),B(V,U,J,`¶`,`\\P`,!0),B(H,U,J,`¶`,`\\P`),B(V,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\dag`),B(H,U,J,`†`,`\\textdagger`),B(V,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\ddag`),B(H,U,J,`‡`,`\\textdaggerdbl`),B(V,U,LG,`⎱`,`\\rmoustache`,!0),B(V,U,BG,`⎰`,`\\lmoustache`,!0),B(V,U,LG,`⟯`,`\\rgroup`,!0),B(V,U,BG,`⟮`,`\\lgroup`,!0),B(V,U,G,`∓`,`\\mp`,!0),B(V,U,G,`⊖`,`\\ominus`,!0),B(V,U,G,`⊎`,`\\uplus`,!0),B(V,U,G,`⊓`,`\\sqcap`,!0),B(V,U,G,`∗`,`\\ast`),B(V,U,G,`⊔`,`\\sqcup`,!0),B(V,U,G,`◯`,`\\bigcirc`,!0),B(V,U,G,`∙`,`\\bullet`,!0),B(V,U,G,`‡`,`\\ddagger`),B(V,U,G,`≀`,`\\wr`,!0),B(V,U,G,`⨿`,`\\amalg`),B(V,U,G,`&`,`\\And`),B(V,U,q,`⟵`,`\\longleftarrow`,!0),B(V,U,q,`⇐`,`\\Leftarrow`,!0),B(V,U,q,`⟸`,`\\Longleftarrow`,!0),B(V,U,q,`⟶`,`\\longrightarrow`,!0),B(V,U,q,`⇒`,`\\Rightarrow`,!0),B(V,U,q,`⟹`,`\\Longrightarrow`,!0),B(V,U,q,`↔`,`\\leftrightarrow`,!0),B(V,U,q,`⟷`,`\\longleftrightarrow`,!0),B(V,U,q,`⇔`,`\\Leftrightarrow`,!0),B(V,U,q,`⟺`,`\\Longleftrightarrow`,!0),B(V,U,q,`↦`,`\\mapsto`,!0),B(V,U,q,`⟼`,`\\longmapsto`,!0),B(V,U,q,`↗`,`\\nearrow`,!0),B(V,U,q,`↩`,`\\hookleftarrow`,!0),B(V,U,q,`↪`,`\\hookrightarrow`,!0),B(V,U,q,`↘`,`\\searrow`,!0),B(V,U,q,`↼`,`\\leftharpoonup`,!0),B(V,U,q,`⇀`,`\\rightharpoonup`,!0),B(V,U,q,`↙`,`\\swarrow`,!0),B(V,U,q,`↽`,`\\leftharpoondown`,!0),B(V,U,q,`⇁`,`\\rightharpoondown`,!0),B(V,U,q,`↖`,`\\nwarrow`,!0),B(V,U,q,`⇌`,`\\rightleftharpoons`,!0),B(V,W,q,`≮`,`\\nless`,!0),B(V,W,q,``,`\\@nleqslant`),B(V,W,q,``,`\\@nleqq`),B(V,W,q,`⪇`,`\\lneq`,!0),B(V,W,q,`≨`,`\\lneqq`,!0),B(V,W,q,``,`\\@lvertneqq`),B(V,W,q,`⋦`,`\\lnsim`,!0),B(V,W,q,`⪉`,`\\lnapprox`,!0),B(V,W,q,`⊀`,`\\nprec`,!0),B(V,W,q,`⋠`,`\\npreceq`,!0),B(V,W,q,`⋨`,`\\precnsim`,!0),B(V,W,q,`⪹`,`\\precnapprox`,!0),B(V,W,q,`≁`,`\\nsim`,!0),B(V,W,q,``,`\\@nshortmid`),B(V,W,q,`∤`,`\\nmid`,!0),B(V,W,q,`⊬`,`\\nvdash`,!0),B(V,W,q,`⊭`,`\\nvDash`,!0),B(V,W,q,`⋪`,`\\ntriangleleft`),B(V,W,q,`⋬`,`\\ntrianglelefteq`,!0),B(V,W,q,`⊊`,`\\subsetneq`,!0),B(V,W,q,``,`\\@varsubsetneq`),B(V,W,q,`⫋`,`\\subsetneqq`,!0),B(V,W,q,``,`\\@varsubsetneqq`),B(V,W,q,`≯`,`\\ngtr`,!0),B(V,W,q,``,`\\@ngeqslant`),B(V,W,q,``,`\\@ngeqq`),B(V,W,q,`⪈`,`\\gneq`,!0),B(V,W,q,`≩`,`\\gneqq`,!0),B(V,W,q,``,`\\@gvertneqq`),B(V,W,q,`⋧`,`\\gnsim`,!0),B(V,W,q,`⪊`,`\\gnapprox`,!0),B(V,W,q,`⊁`,`\\nsucc`,!0),B(V,W,q,`⋡`,`\\nsucceq`,!0),B(V,W,q,`⋩`,`\\succnsim`,!0),B(V,W,q,`⪺`,`\\succnapprox`,!0),B(V,W,q,`≆`,`\\ncong`,!0),B(V,W,q,``,`\\@nshortparallel`),B(V,W,q,`∦`,`\\nparallel`,!0),B(V,W,q,`⊯`,`\\nVDash`,!0),B(V,W,q,`⋫`,`\\ntriangleright`),B(V,W,q,`⋭`,`\\ntrianglerighteq`,!0),B(V,W,q,``,`\\@nsupseteqq`),B(V,W,q,`⊋`,`\\supsetneq`,!0),B(V,W,q,``,`\\@varsupsetneq`),B(V,W,q,`⫌`,`\\supsetneqq`,!0),B(V,W,q,``,`\\@varsupsetneqq`),B(V,W,q,`⊮`,`\\nVdash`,!0),B(V,W,q,`⪵`,`\\precneqq`,!0),B(V,W,q,`⪶`,`\\succneqq`,!0),B(V,W,q,``,`\\@nsubseteqq`),B(V,W,G,`⊴`,`\\unlhd`),B(V,W,G,`⊵`,`\\unrhd`),B(V,W,q,`↚`,`\\nleftarrow`,!0),B(V,W,q,`↛`,`\\nrightarrow`,!0),B(V,W,q,`⇍`,`\\nLeftarrow`,!0),B(V,W,q,`⇏`,`\\nRightarrow`,!0),B(V,W,q,`↮`,`\\nleftrightarrow`,!0),B(V,W,q,`⇎`,`\\nLeftrightarrow`,!0),B(V,W,q,`△`,`\\vartriangle`),B(V,W,J,`ℏ`,`\\hslash`),B(V,W,J,`▽`,`\\triangledown`),B(V,W,J,`◊`,`\\lozenge`),B(V,W,J,`Ⓢ`,`\\circledS`),B(V,W,J,`®`,`\\circledR`),B(H,W,J,`®`,`\\circledR`),B(V,W,J,`∡`,`\\measuredangle`,!0),B(V,W,J,`∄`,`\\nexists`),B(V,W,J,`℧`,`\\mho`),B(V,W,J,`Ⅎ`,`\\Finv`,!0),B(V,W,J,`⅁`,`\\Game`,!0),B(V,W,J,`‵`,`\\backprime`),B(V,W,J,`▲`,`\\blacktriangle`),B(V,W,J,`▼`,`\\blacktriangledown`),B(V,W,J,`■`,`\\blacksquare`),B(V,W,J,`⧫`,`\\blacklozenge`),B(V,W,J,`★`,`\\bigstar`),B(V,W,J,`∢`,`\\sphericalangle`,!0),B(V,W,J,`∁`,`\\complement`,!0),B(V,W,J,`ð`,`\\eth`,!0),B(H,U,J,`ð`,`ð`),B(V,W,J,`╱`,`\\diagup`),B(V,W,J,`╲`,`\\diagdown`),B(V,W,J,`□`,`\\square`),B(V,W,J,`□`,`\\Box`),B(V,W,J,`◊`,`\\Diamond`),B(V,W,J,`¥`,`\\yen`,!0),B(H,W,J,`¥`,`\\yen`,!0),B(V,W,J,`✓`,`\\checkmark`,!0),B(H,W,J,`✓`,`\\checkmark`),B(V,W,J,`ℶ`,`\\beth`,!0),B(V,W,J,`ℸ`,`\\daleth`,!0),B(V,W,J,`ℷ`,`\\gimel`,!0),B(V,W,J,`ϝ`,`\\digamma`,!0),B(V,W,J,`ϰ`,`\\varkappa`),B(V,W,BG,`┌`,`\\@ulcorner`,!0),B(V,W,LG,`┐`,`\\@urcorner`,!0),B(V,W,BG,`└`,`\\@llcorner`,!0),B(V,W,LG,`┘`,`\\@lrcorner`,!0),B(V,W,q,`≦`,`\\leqq`,!0),B(V,W,q,`⩽`,`\\leqslant`,!0),B(V,W,q,`⪕`,`\\eqslantless`,!0),B(V,W,q,`≲`,`\\lesssim`,!0),B(V,W,q,`⪅`,`\\lessapprox`,!0),B(V,W,q,`≊`,`\\approxeq`,!0),B(V,W,G,`⋖`,`\\lessdot`),B(V,W,q,`⋘`,`\\lll`,!0),B(V,W,q,`≶`,`\\lessgtr`,!0),B(V,W,q,`⋚`,`\\lesseqgtr`,!0),B(V,W,q,`⪋`,`\\lesseqqgtr`,!0),B(V,W,q,`≑`,`\\doteqdot`),B(V,W,q,`≓`,`\\risingdotseq`,!0),B(V,W,q,`≒`,`\\fallingdotseq`,!0),B(V,W,q,`∽`,`\\backsim`,!0),B(V,W,q,`⋍`,`\\backsimeq`,!0),B(V,W,q,`⫅`,`\\subseteqq`,!0),B(V,W,q,`⋐`,`\\Subset`,!0),B(V,W,q,`⊏`,`\\sqsubset`,!0),B(V,W,q,`≼`,`\\preccurlyeq`,!0),B(V,W,q,`⋞`,`\\curlyeqprec`,!0),B(V,W,q,`≾`,`\\precsim`,!0),B(V,W,q,`⪷`,`\\precapprox`,!0),B(V,W,q,`⊲`,`\\vartriangleleft`),B(V,W,q,`⊴`,`\\trianglelefteq`),B(V,W,q,`⊨`,`\\vDash`,!0),B(V,W,q,`⊪`,`\\Vvdash`,!0),B(V,W,q,`⌣`,`\\smallsmile`),B(V,W,q,`⌢`,`\\smallfrown`),B(V,W,q,`≏`,`\\bumpeq`,!0),B(V,W,q,`≎`,`\\Bumpeq`,!0),B(V,W,q,`≧`,`\\geqq`,!0),B(V,W,q,`⩾`,`\\geqslant`,!0),B(V,W,q,`⪖`,`\\eqslantgtr`,!0),B(V,W,q,`≳`,`\\gtrsim`,!0),B(V,W,q,`⪆`,`\\gtrapprox`,!0),B(V,W,G,`⋗`,`\\gtrdot`),B(V,W,q,`⋙`,`\\ggg`,!0),B(V,W,q,`≷`,`\\gtrless`,!0),B(V,W,q,`⋛`,`\\gtreqless`,!0),B(V,W,q,`⪌`,`\\gtreqqless`,!0),B(V,W,q,`≖`,`\\eqcirc`,!0),B(V,W,q,`≗`,`\\circeq`,!0),B(V,W,q,`≜`,`\\triangleq`,!0),B(V,W,q,`∼`,`\\thicksim`),B(V,W,q,`≈`,`\\thickapprox`),B(V,W,q,`⫆`,`\\supseteqq`,!0),B(V,W,q,`⋑`,`\\Supset`,!0),B(V,W,q,`⊐`,`\\sqsupset`,!0),B(V,W,q,`≽`,`\\succcurlyeq`,!0),B(V,W,q,`⋟`,`\\curlyeqsucc`,!0),B(V,W,q,`≿`,`\\succsim`,!0),B(V,W,q,`⪸`,`\\succapprox`,!0),B(V,W,q,`⊳`,`\\vartriangleright`),B(V,W,q,`⊵`,`\\trianglerighteq`),B(V,W,q,`⊩`,`\\Vdash`,!0),B(V,W,q,`∣`,`\\shortmid`),B(V,W,q,`∥`,`\\shortparallel`),B(V,W,q,`≬`,`\\between`,!0),B(V,W,q,`⋔`,`\\pitchfork`,!0),B(V,W,q,`∝`,`\\varpropto`),B(V,W,q,`◀`,`\\blacktriangleleft`),B(V,W,q,`∴`,`\\therefore`,!0),B(V,W,q,`∍`,`\\backepsilon`),B(V,W,q,`▶`,`\\blacktriangleright`),B(V,W,q,`∵`,`\\because`,!0),B(V,W,q,`⋘`,`\\llless`),B(V,W,q,`⋙`,`\\gggtr`),B(V,W,G,`⊲`,`\\lhd`),B(V,W,G,`⊳`,`\\rhd`),B(V,W,q,`≂`,`\\eqsim`,!0),B(V,U,q,`⋈`,`\\Join`),B(V,W,q,`≑`,`\\Doteq`,!0),B(V,W,G,`∔`,`\\dotplus`,!0),B(V,W,G,`∖`,`\\smallsetminus`),B(V,W,G,`⋒`,`\\Cap`,!0),B(V,W,G,`⋓`,`\\Cup`,!0),B(V,W,G,`⩞`,`\\doublebarwedge`,!0),B(V,W,G,`⊟`,`\\boxminus`,!0),B(V,W,G,`⊞`,`\\boxplus`,!0),B(V,W,G,`⋇`,`\\divideontimes`,!0),B(V,W,G,`⋉`,`\\ltimes`,!0),B(V,W,G,`⋊`,`\\rtimes`,!0),B(V,W,G,`⋋`,`\\leftthreetimes`,!0),B(V,W,G,`⋌`,`\\rightthreetimes`,!0),B(V,W,G,`⋏`,`\\curlywedge`,!0),B(V,W,G,`⋎`,`\\curlyvee`,!0),B(V,W,G,`⊝`,`\\circleddash`,!0),B(V,W,G,`⊛`,`\\circledast`,!0),B(V,W,G,`⋅`,`\\centerdot`),B(V,W,G,`⊺`,`\\intercal`,!0),B(V,W,G,`⋒`,`\\doublecap`),B(V,W,G,`⋓`,`\\doublecup`),B(V,W,G,`⊠`,`\\boxtimes`,!0),B(V,W,q,`⇢`,`\\dashrightarrow`,!0),B(V,W,q,`⇠`,`\\dashleftarrow`,!0),B(V,W,q,`⇇`,`\\leftleftarrows`,!0),B(V,W,q,`⇆`,`\\leftrightarrows`,!0),B(V,W,q,`⇚`,`\\Lleftarrow`,!0),B(V,W,q,`↞`,`\\twoheadleftarrow`,!0),B(V,W,q,`↢`,`\\leftarrowtail`,!0),B(V,W,q,`↫`,`\\looparrowleft`,!0),B(V,W,q,`⇋`,`\\leftrightharpoons`,!0),B(V,W,q,`↶`,`\\curvearrowleft`,!0),B(V,W,q,`↺`,`\\circlearrowleft`,!0),B(V,W,q,`↰`,`\\Lsh`,!0),B(V,W,q,`⇈`,`\\upuparrows`,!0),B(V,W,q,`↿`,`\\upharpoonleft`,!0),B(V,W,q,`⇃`,`\\downharpoonleft`,!0),B(V,U,q,`⊶`,`\\origof`,!0),B(V,U,q,`⊷`,`\\imageof`,!0),B(V,W,q,`⊸`,`\\multimap`,!0),B(V,W,q,`↭`,`\\leftrightsquigarrow`,!0),B(V,W,q,`⇉`,`\\rightrightarrows`,!0),B(V,W,q,`⇄`,`\\rightleftarrows`,!0),B(V,W,q,`↠`,`\\twoheadrightarrow`,!0),B(V,W,q,`↣`,`\\rightarrowtail`,!0),B(V,W,q,`↬`,`\\looparrowright`,!0),B(V,W,q,`↷`,`\\curvearrowright`,!0),B(V,W,q,`↻`,`\\circlearrowright`,!0),B(V,W,q,`↱`,`\\Rsh`,!0),B(V,W,q,`⇊`,`\\downdownarrows`,!0),B(V,W,q,`↾`,`\\upharpoonright`,!0),B(V,W,q,`⇂`,`\\downharpoonright`,!0),B(V,W,q,`⇝`,`\\rightsquigarrow`,!0),B(V,W,q,`⇝`,`\\leadsto`),B(V,W,q,`⇛`,`\\Rrightarrow`,!0),B(V,W,q,`↾`,`\\restriction`),B(V,U,J,`‘`,"`"),B(V,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\$`),B(H,U,J,`$`,`\\textdollar`),B(V,U,J,`%`,`\\%`),B(H,U,J,`%`,`\\%`),B(V,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\_`),B(H,U,J,`_`,`\\textunderscore`),B(V,U,J,`∠`,`\\angle`,!0),B(V,U,J,`∞`,`\\infty`,!0),B(V,U,J,`′`,`\\prime`),B(V,U,J,`△`,`\\triangle`),B(V,U,J,`Γ`,`\\Gamma`,!0),B(V,U,J,`Δ`,`\\Delta`,!0),B(V,U,J,`Θ`,`\\Theta`,!0),B(V,U,J,`Λ`,`\\Lambda`,!0),B(V,U,J,`Ξ`,`\\Xi`,!0),B(V,U,J,`Π`,`\\Pi`,!0),B(V,U,J,`Σ`,`\\Sigma`,!0),B(V,U,J,`Υ`,`\\Upsilon`,!0),B(V,U,J,`Φ`,`\\Phi`,!0),B(V,U,J,`Ψ`,`\\Psi`,!0),B(V,U,J,`Ω`,`\\Omega`,!0),B(V,U,J,`A`,`Α`),B(V,U,J,`B`,`Β`),B(V,U,J,`E`,`Ε`),B(V,U,J,`Z`,`Ζ`),B(V,U,J,`H`,`Η`),B(V,U,J,`I`,`Ι`),B(V,U,J,`K`,`Κ`),B(V,U,J,`M`,`Μ`),B(V,U,J,`N`,`Ν`),B(V,U,J,`O`,`Ο`),B(V,U,J,`P`,`Ρ`),B(V,U,J,`T`,`Τ`),B(V,U,J,`X`,`Χ`),B(V,U,J,`¬`,`\\neg`,!0),B(V,U,J,`¬`,`\\lnot`),B(V,U,J,`⊤`,`\\top`),B(V,U,J,`⊥`,`\\bot`),B(V,U,J,`∅`,`\\emptyset`),B(V,W,J,`∅`,`\\varnothing`),B(V,U,K,`α`,`\\alpha`,!0),B(V,U,K,`β`,`\\beta`,!0),B(V,U,K,`γ`,`\\gamma`,!0),B(V,U,K,`δ`,`\\delta`,!0),B(V,U,K,`ϵ`,`\\epsilon`,!0),B(V,U,K,`ζ`,`\\zeta`,!0),B(V,U,K,`η`,`\\eta`,!0),B(V,U,K,`θ`,`\\theta`,!0),B(V,U,K,`ι`,`\\iota`,!0),B(V,U,K,`κ`,`\\kappa`,!0),B(V,U,K,`λ`,`\\lambda`,!0),B(V,U,K,`μ`,`\\mu`,!0),B(V,U,K,`ν`,`\\nu`,!0),B(V,U,K,`ξ`,`\\xi`,!0),B(V,U,K,`ο`,`\\omicron`,!0),B(V,U,K,`π`,`\\pi`,!0),B(V,U,K,`ρ`,`\\rho`,!0),B(V,U,K,`σ`,`\\sigma`,!0),B(V,U,K,`τ`,`\\tau`,!0),B(V,U,K,`υ`,`\\upsilon`,!0),B(V,U,K,`ϕ`,`\\phi`,!0),B(V,U,K,`χ`,`\\chi`,!0),B(V,U,K,`ψ`,`\\psi`,!0),B(V,U,K,`ω`,`\\omega`,!0),B(V,U,K,`ε`,`\\varepsilon`,!0),B(V,U,K,`ϑ`,`\\vartheta`,!0),B(V,U,K,`ϖ`,`\\varpi`,!0),B(V,U,K,`ϱ`,`\\varrho`,!0),B(V,U,K,`ς`,`\\varsigma`,!0),B(V,U,K,`φ`,`\\varphi`,!0),B(V,U,G,`∗`,`*`,!0),B(V,U,G,`+`,`+`),B(V,U,G,`−`,`-`,!0),B(V,U,G,`⋅`,`\\cdot`,!0),B(V,U,G,`∘`,`\\circ`,!0),B(V,U,G,`÷`,`\\div`,!0),B(V,U,G,`±`,`\\pm`,!0),B(V,U,G,`×`,`\\times`,!0),B(V,U,G,`∩`,`\\cap`,!0),B(V,U,G,`∪`,`\\cup`,!0),B(V,U,G,`∖`,`\\setminus`,!0),B(V,U,G,`∧`,`\\land`),B(V,U,G,`∨`,`\\lor`),B(V,U,G,`∧`,`\\wedge`,!0),B(V,U,G,`∨`,`\\vee`,!0),B(V,U,J,`√`,`\\surd`),B(V,U,BG,`⟨`,`\\langle`,!0),B(V,U,BG,`∣`,`\\lvert`),B(V,U,BG,`∥`,`\\lVert`),B(V,U,LG,`?`,`?`),B(V,U,LG,`!`,`!`),B(V,U,LG,`⟩`,`\\rangle`,!0),B(V,U,LG,`∣`,`\\rvert`),B(V,U,LG,`∥`,`\\rVert`),B(V,U,q,`=`,`=`),B(V,U,q,`:`,`:`),B(V,U,q,`≈`,`\\approx`,!0),B(V,U,q,`≅`,`\\cong`,!0),B(V,U,q,`≥`,`\\ge`),B(V,U,q,`≥`,`\\geq`,!0),B(V,U,q,`←`,`\\gets`),B(V,U,q,`>`,`\\gt`,!0),B(V,U,q,`∈`,`\\in`,!0),B(V,U,q,``,`\\@not`),B(V,U,q,`⊂`,`\\subset`,!0),B(V,U,q,`⊃`,`\\supset`,!0),B(V,U,q,`⊆`,`\\subseteq`,!0),B(V,U,q,`⊇`,`\\supseteq`,!0),B(V,W,q,`⊈`,`\\nsubseteq`,!0),B(V,W,q,`⊉`,`\\nsupseteq`,!0),B(V,U,q,`⊨`,`\\models`),B(V,U,q,`←`,`\\leftarrow`,!0),B(V,U,q,`≤`,`\\le`),B(V,U,q,`≤`,`\\leq`,!0),B(V,U,q,`<`,`\\lt`,!0),B(V,U,q,`→`,`\\rightarrow`,!0),B(V,U,q,`→`,`\\to`),B(V,W,q,`≱`,`\\ngeq`,!0),B(V,W,q,`≰`,`\\nleq`,!0),B(V,U,HG,`\xA0`,`\\ `),B(V,U,HG,`\xA0`,`\\space`),B(V,U,HG,`\xA0`,`\\nobreakspace`),B(H,U,HG,`\xA0`,`\\ `),B(H,U,HG,`\xA0`,` `),B(H,U,HG,`\xA0`,`\\space`),B(H,U,HG,`\xA0`,`\\nobreakspace`),B(V,U,HG,``,`\\nobreak`),B(V,U,HG,``,`\\allowbreak`),B(V,U,VG,`,`,`,`),B(V,U,VG,`;`,`;`),B(V,W,G,`⊼`,`\\barwedge`,!0),B(V,W,G,`⊻`,`\\veebar`,!0),B(V,U,G,`⊙`,`\\odot`,!0),B(V,U,G,`⊕`,`\\oplus`,!0),B(V,U,G,`⊗`,`\\otimes`,!0),B(V,U,J,`∂`,`\\partial`,!0),B(V,U,G,`⊘`,`\\oslash`,!0),B(V,W,G,`⊚`,`\\circledcirc`,!0),B(V,W,G,`⊡`,`\\boxdot`,!0),B(V,U,G,`△`,`\\bigtriangleup`),B(V,U,G,`▽`,`\\bigtriangledown`),B(V,U,G,`†`,`\\dagger`),B(V,U,G,`⋄`,`\\diamond`),B(V,U,G,`⋆`,`\\star`),B(V,U,G,`◃`,`\\triangleleft`),B(V,U,G,`▹`,`\\triangleright`),B(V,U,BG,`{`,`\\{`),B(H,U,J,`{`,`\\{`),B(H,U,J,`{`,`\\textbraceleft`),B(V,U,LG,`}`,`\\}`),B(H,U,J,`}`,`\\}`),B(H,U,J,`}`,`\\textbraceright`),B(V,U,BG,`{`,`\\lbrace`),B(V,U,LG,`}`,`\\rbrace`),B(V,U,BG,`[`,`\\lbrack`,!0),B(H,U,J,`[`,`\\lbrack`,!0),B(V,U,LG,`]`,`\\rbrack`,!0),B(H,U,J,`]`,`\\rbrack`,!0),B(V,U,BG,`(`,`\\lparen`,!0),B(V,U,LG,`)`,`\\rparen`,!0),B(H,U,J,`<`,`\\textless`,!0),B(H,U,J,`>`,`\\textgreater`,!0),B(V,U,BG,`⌊`,`\\lfloor`,!0),B(V,U,LG,`⌋`,`\\rfloor`,!0),B(V,U,BG,`⌈`,`\\lceil`,!0),B(V,U,LG,`⌉`,`\\rceil`,!0),B(V,U,J,`\\`,`\\backslash`),B(V,U,J,`∣`,`|`),B(V,U,J,`∣`,`\\vert`),B(H,U,J,`|`,`\\textbar`,!0),B(V,U,J,`∥`,`\\|`),B(V,U,J,`∥`,`\\Vert`),B(H,U,J,`∥`,`\\textbardbl`),B(H,U,J,`~`,`\\textasciitilde`),B(H,U,J,`\\`,`\\textbackslash`),B(H,U,J,`^`,`\\textasciicircum`),B(V,U,q,`↑`,`\\uparrow`,!0),B(V,U,q,`⇑`,`\\Uparrow`,!0),B(V,U,q,`↓`,`\\downarrow`,!0),B(V,U,q,`⇓`,`\\Downarrow`,!0),B(V,U,q,`↕`,`\\updownarrow`,!0),B(V,U,q,`⇕`,`\\Updownarrow`,!0),B(V,U,zG,`∐`,`\\coprod`),B(V,U,zG,`⋁`,`\\bigvee`),B(V,U,zG,`⋀`,`\\bigwedge`),B(V,U,zG,`⨄`,`\\biguplus`),B(V,U,zG,`⋂`,`\\bigcap`),B(V,U,zG,`⋃`,`\\bigcup`),B(V,U,zG,`∫`,`\\int`),B(V,U,zG,`∫`,`\\intop`),B(V,U,zG,`∬`,`\\iint`),B(V,U,zG,`∭`,`\\iiint`),B(V,U,zG,`∏`,`\\prod`),B(V,U,zG,`∑`,`\\sum`),B(V,U,zG,`⨂`,`\\bigotimes`),B(V,U,zG,`⨁`,`\\bigoplus`),B(V,U,zG,`⨀`,`\\bigodot`),B(V,U,zG,`∮`,`\\oint`),B(V,U,zG,`∯`,`\\oiint`),B(V,U,zG,`∰`,`\\oiiint`),B(V,U,zG,`⨆`,`\\bigsqcup`),B(V,U,zG,`∫`,`\\smallint`),B(H,U,RG,`…`,`\\textellipsis`),B(V,U,RG,`…`,`\\mathellipsis`),B(H,U,RG,`…`,`\\ldots`,!0),B(V,U,RG,`…`,`\\ldots`,!0),B(V,U,RG,`⋯`,`\\@cdots`,!0),B(V,U,RG,`⋱`,`\\ddots`,!0),B(V,U,J,`⋮`,`\\varvdots`),B(H,U,J,`⋮`,`\\varvdots`),B(V,U,IG,`ˊ`,`\\acute`),B(V,U,IG,`ˋ`,`\\grave`),B(V,U,IG,`¨`,`\\ddot`),B(V,U,IG,`~`,`\\tilde`),B(V,U,IG,`ˉ`,`\\bar`),B(V,U,IG,`˘`,`\\breve`),B(V,U,IG,`ˇ`,`\\check`),B(V,U,IG,`^`,`\\hat`),B(V,U,IG,`⃗`,`\\vec`),B(V,U,IG,`˙`,`\\dot`),B(V,U,IG,`˚`,`\\mathring`),B(V,U,K,``,`\\@imath`),B(V,U,K,``,`\\@jmath`),B(V,U,J,`ı`,`ı`),B(V,U,J,`ȷ`,`ȷ`),B(H,U,J,`ı`,`\\i`,!0),B(H,U,J,`ȷ`,`\\j`,!0),B(H,U,J,`ß`,`\\ss`,!0),B(H,U,J,`æ`,`\\ae`,!0),B(H,U,J,`œ`,`\\oe`,!0),B(H,U,J,`ø`,`\\o`,!0),B(H,U,J,`Æ`,`\\AE`,!0),B(H,U,J,`Œ`,`\\OE`,!0),B(H,U,J,`Ø`,`\\O`,!0),B(H,U,IG,`ˊ`,`\\'`),B(H,U,IG,`ˋ`,"\\`"),B(H,U,IG,`ˆ`,`\\^`),B(H,U,IG,`˜`,`\\~`),B(H,U,IG,`ˉ`,`\\=`),B(H,U,IG,`˘`,`\\u`),B(H,U,IG,`˙`,`\\.`),B(H,U,IG,`¸`,`\\c`),B(H,U,IG,`˚`,`\\r`),B(H,U,IG,`ˇ`,`\\v`),B(H,U,IG,`¨`,`\\"`),B(H,U,IG,`˝`,`\\H`),B(H,U,IG,`◯`,`\\textcircled`);var UG={"--":!0,"---":!0,"``":!0,"''":!0};B(H,U,J,`–`,`--`,!0),B(H,U,J,`–`,`\\textendash`),B(H,U,J,`—`,`---`,!0),B(H,U,J,`—`,`\\textemdash`),B(H,U,J,`‘`,"`",!0),B(H,U,J,`‘`,`\\textquoteleft`),B(H,U,J,`’`,`'`,!0),B(H,U,J,`’`,`\\textquoteright`),B(H,U,J,`“`,"``",!0),B(H,U,J,`“`,`\\textquotedblleft`),B(H,U,J,`”`,`''`,!0),B(H,U,J,`”`,`\\textquotedblright`),B(V,U,J,`°`,`\\degree`,!0),B(H,U,J,`°`,`\\degree`),B(H,U,J,`°`,`\\textdegree`,!0),B(V,U,J,`£`,`\\pounds`),B(V,U,J,`£`,`\\mathsterling`,!0),B(H,U,J,`£`,`\\pounds`),B(H,U,J,`£`,`\\textsterling`,!0),B(V,W,J,`✠`,`\\maltese`),B(H,W,J,`✠`,`\\maltese`);for(var WG=`0123456789/@."`,GG=0;GG{var t=e.charCodeAt(0),n=e.charCodeAt(1),r=(t-55296)*1024+(n-56320)+65536;if(119808<=r&&r<120484)return vK[Math.floor((r-119808)/26)];if(120782<=r&&r<=120831)return yK[Math.floor((r-120782)/10)];if(r===120485||r===120486)return vK[0];if(120486{if(dG(e.classes)!==dG(t.classes)||e.skew!==t.skew||e.maxFontSize!==t.maxFontSize||e.italic!==0&&e.hasClass(`mathnormal`))return!1;if(e.classes.length===1){var n=e.classes[0];if(n===`mbin`||n===`mord`)return!1}for(var r of Object.keys(e.style))if(e.style[r]!==t.style[r])return!1;for(var i of Object.keys(t.style))if(e.style[i]!==t.style[i])return!1;return!0},DK=e=>{for(var t=0;tt&&(t=a.height),a.depth>n&&(n=a.depth),a.maxFontSize>r&&(r=a.maxFontSize)}e.height=t,e.depth=n,e.maxFontSize=r},X=function(e,t,n,r){var i=new _G(e,t,n,r);return OK(i),i},kK=(e,t,n,r)=>new _G(e,t,n,r),AK=function(e,t,n){var r=X([e],[],t);return r.height=Math.max(n||t.fontMetrics().defaultRuleThickness,t.minRuleThickness),r.style.borderBottomWidth=z(r.height),r.maxFontSize=1,r},jK=function(e,t,n,r){var i=new vG(e,t,n,r);return OK(i),i},MK=function(e){var t=new oG(e);return OK(t),t},NK=function(e,t){return e instanceof oG?X([],[e],t):e},PK=function(e){if(e.positionType===`individualShift`){for(var t=e.children,n=[t[0]],r=-t[0].shift-t[0].elem.depth,i=r,a=1;a{var n=X([`mspace`],[],t),r=uG(e,t);return n.style.marginRight=z(r),n},LK=(e,t,n)=>{var r,i;switch(e){case`amsrm`:r=`AMS`;break;case`textrm`:r=`Main`;break;case`textsf`:r=`SansSerif`;break;case`texttt`:r=`Typewriter`;break;default:r=e}return i=t===`textbf`&&n===`textit`?`BoldItalic`:t===`textbf`?`Bold`:n===`textit`?`Italic`:`Regular`,r+`-`+i},RK={mathbf:{variant:`bold`,fontName:`Main-Bold`},mathrm:{variant:`normal`,fontName:`Main-Regular`},textit:{variant:`italic`,fontName:`Main-Italic`},mathit:{variant:`italic`,fontName:`Main-Italic`},mathnormal:{variant:`italic`,fontName:`Math-Italic`},mathsfit:{variant:`sans-serif-italic`,fontName:`SansSerif-Italic`},mathbb:{variant:`double-struck`,fontName:`AMS-Regular`},mathcal:{variant:`script`,fontName:`Caligraphic-Regular`},mathfrak:{variant:`fraktur`,fontName:`Fraktur-Regular`},mathscr:{variant:`script`,fontName:`Script-Regular`},mathsf:{variant:`sans-serif`,fontName:`SansSerif-Regular`},mathtt:{variant:`monospace`,fontName:`Typewriter-Regular`}},zK={vec:[`vec`,.471,.714],oiintSize1:[`oiintSize1`,.957,.499],oiintSize2:[`oiintSize2`,1.472,.659],oiiintSize1:[`oiiintSize1`,1.304,.499],oiiintSize2:[`oiiintSize2`,1.98,.659]},BK=function(e,t){var n=zK[e],r=n[0],i=n[1],a=n[2],o=kK([`katex-overlay`],[new SG([new CG(r)],{width:z(i),height:z(a),style:`width:`+z(i),viewBox:`0 0 `+1e3*i+` `+1e3*a,preserveAspectRatio:`xMinYMin`})],t);return o.height=a,o.style.height=z(a),o.style.width=z(i),o},VK={number:3,unit:`mu`},HK={number:4,unit:`mu`},UK={number:5,unit:`mu`},WK={mord:{mop:VK,mbin:HK,mrel:UK,minner:VK},mop:{mord:VK,mop:VK,mrel:UK,minner:VK},mbin:{mord:HK,mop:HK,mopen:HK,minner:HK},mrel:{mord:UK,mop:UK,mopen:UK,minner:UK},mopen:{},mclose:{mop:VK,mbin:HK,mrel:UK,minner:VK},mpunct:{mord:VK,mop:VK,mrel:UK,mopen:VK,mclose:VK,mpunct:VK,minner:VK},minner:{mord:VK,mop:VK,mbin:HK,mrel:UK,mopen:VK,mpunct:VK,minner:VK}},GK={mord:{mop:VK},mop:{mord:VK,mop:VK},mbin:{},mrel:{},mopen:{},mclose:{mop:VK},mpunct:{},minner:{mop:VK}},KK={},qK={},JK={};function Z(e){for(var t=e.type,n=e.names,r=e.htmlBuilder,i=e.mathmlBuilder,a=0;a{var n=t.classes[0],r=e.classes[0];n===`mbin`&&$K.has(r)?t.classes[0]=`mord`:r===`mbin`&&QK.has(n)&&(e.classes[0]=`mord`)},{node:u},d,f),rq(i,(e,t)=>{var n=oq(t),r=oq(e),i=n&&r?e.hasClass(`mtight`)?GK[n]?.[r]:WK[n]?.[r]:null;if(i)return IK(i,c)},{node:u},d,f),i},rq=function(e,t,n,r,i){r&&e.push(r);for(var a=0;an=>{e.splice(t+1,0,n),a++})(a)}}r&&e.pop()},iq=function(e){return e instanceof oG||e instanceof vG||e instanceof _G&&e.hasClass(`enclosing`)?e:null},aq=function(e,t){var n=iq(e);if(n){var r=n.children;if(r.length){if(t===`right`)return aq(r[r.length-1],`right`);if(t===`left`)return aq(r[0],`left`)}}return e},oq=function(e,t){return e?(t&&(e=aq(e,t)),tq[e.classes[0]]||null):null},sq=function(e,t){var n=[`nulldelimiter`].concat(e.baseSizingClasses());return X(t.concat(n))},cq=function(e,t,n){if(!e)return X();if(qK[e.type]){var r=qK[e.type](e,t);if(n&&t.size!==n.size){r=X(t.sizingClasses(n),[r],t);var i=t.sizeMultiplier/n.sizeMultiplier;r.height*=i,r.depth*=i}return r}throw new R(`Got group of unknown type: '`+e.type+`'`)};function lq(e,t){var n=X([`katex-base`],e,t),r=X([`katex-strut`]);return r.style.height=z(n.height+n.depth),n.depth&&(r.style.verticalAlign=z(-n.depth)),n.children.unshift(r),n}function uq(e,t){var n=null;e.length===1&&e[0].type===`tag`&&(n=e[0].tag,e=e[0].body);var r=nq(e,t,`root`),i;r.length===2&&r[1].hasClass(`katex-tag`)&&(i=r.pop());for(var a=[],o=[],s=0;s0&&(a.push(lq(o,t)),o=[]),a.push(r[s]));o.length>0&&a.push(lq(o,t));var l;n?(l=lq(nq(n,t,!0),t),l.classes=[`katex-tag`],a.push(l)):i&&a.push(i);var u=X([`katex-html`],a);if(u.setAttribute(`aria-hidden`,`true`),l){var d=l.children[0];d.style.height=z(u.height+u.depth),u.depth&&(d.style.verticalAlign=z(-u.depth))}return u}function dq(e){return new oG(e)}var Q=class{constructor(e,t,n){this.type=void 0,this.attributes=void 0,this.children=void 0,this.classes=void 0,this.type=e,this.attributes={},this.children=t||[],this.classes=n||[]}setAttribute(e,t){this.attributes[e]=t}getAttribute(e){return this.attributes[e]}toNode(){var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,this.type);for(var t of Object.entries(this.attributes)){var n=t[0],r=t[1];e.setAttribute(n,r)}this.classes.length>0&&(e.className=dG(this.classes));for(var i=0;i0&&(e+=` class ="`+hW(dG(this.classes))+`"`),e+=`>`;for(var i=0;i`,e}toText(){return this.children.map(e=>e.toText()).join(``)}},fq=class{constructor(e){this.text=void 0,this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return hW(this.toText())}toText(){return this.text}},pq=class{constructor(e){this.width=void 0,this.character=void 0,this.width=e,this.character=e>=.05555&&e<=.05556?` `:e>=.1666&&e<=.1667?` `:e>=.2222&&e<=.2223?` `:e>=.2777&&e<=.2778?`  `:e>=-.05556&&e<=-.05555?` ⁣`:e>=-.1667&&e<=-.1666?` ⁣`:e>=-.2223&&e<=-.2222?` ⁣`:e>=-.2778&&e<=-.2777?` ⁣`:null}toNode(){if(this.character)return document.createTextNode(this.character);var e=document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`mspace`);return e.setAttribute(`width`,z(this.width)),e}toMarkup(){return this.character?``+this.character+``:``}toText(){return this.character?this.character:` `}},mq=new Set([`\\imath`,`\\jmath`]),hq=new Set([`mrow`,`mtable`]),gq=function(e,t,n){var r,i;return FG[t][e]&&FG[t][e].replace&&e.charCodeAt(0)!==55349&&(!Object.prototype.hasOwnProperty.call(UG,e)||(n==null||(r=n.fontFamily)==null?void 0:r.slice(4,6))!==`tt`&&(n==null||(i=n.font)==null?void 0:i.slice(4,6))!==`tt`)&&(e=FG[t][e].replace),new fq(e)},_q=function(e){return e.length===1?e[0]:new Q(`mrow`,e)},vq={mathit:`italic`,boldsymbol:e=>e.type===`textord`?`bold`:`bold-italic`,mathbf:`bold`,mathbb:`double-struck`,mathsfit:`sans-serif-italic`,mathfrak:`fraktur`,mathscr:`script`,mathcal:`script`,mathsf:`sans-serif`,mathtt:`monospace`},yq=(e,t)=>{if(e.mode===`text`){if(t.fontFamily===`texttt`)return`monospace`;if(t.fontFamily===`textsf`)return t.fontShape===`textit`&&t.fontWeight===`textbf`?`sans-serif-bold-italic`:t.fontShape===`textit`?`sans-serif-italic`:t.fontWeight===`textbf`?`bold-sans-serif`:`sans-serif`;if(t.fontShape===`textit`&&t.fontWeight===`textbf`)return`bold-italic`;if(t.fontShape===`textit`)return`italic`;if(t.fontWeight===`textbf`)return`bold`}var n=t.font;if(!n||n===`mathnormal`)return null;var r=e.mode,i=vq[n];if(i)return typeof i==`function`?i(e):i;var a=e.text;if(mq.has(a))return null;if(FG[r][a]){var o=FG[r][a].replace;o&&(a=o)}var s=RK[n].fontName;return MG(a,s,r)?RK[n].variant:null};function bq(e){if(!e)return!1;if(e.type===`mi`&&e.children.length===1){var t=e.children[0];return t instanceof fq&&t.text===`.`}if(e.type===`mo`&&e.children.length===1&&e.getAttribute(`separator`)===`true`&&e.getAttribute(`lspace`)===`0em`&&e.getAttribute(`rspace`)===`0em`){var n=e.children[0];return n instanceof fq&&n.text===`,`}return!1}var xq=function(e,t,n){if(e.length===1){var r=Cq(e[0],t);return n&&r instanceof Q&&r.type===`mo`&&(r.setAttribute(`lspace`,`0em`),r.setAttribute(`rspace`,`0em`)),[r]}for(var i=[],a,o=0;o=1&&(a.type===`mn`||bq(a))){var c=s.children[0];c instanceof Q&&c.type===`mn`&&(c.children=[...a.children,...c.children],i.pop())}else if(a.type===`mi`&&a.children.length===1){var l=a.children[0];if(l instanceof fq&&l.text===`̸`&&(s.type===`mo`||s.type===`mi`||s.type===`mn`)){var u=s.children[0];u instanceof fq&&u.text.length>0&&(u.text=u.text.slice(0,1)+`̸`+u.text.slice(1),i.pop())}}}i.push(s),a=s}return i},Sq=function(e,t,n){return _q(xq(e,t,n))},Cq=function(e,t){if(!e)return new Q(`mrow`);if(JK[e.type])return JK[e.type](e,t);throw new R(`Got group of unknown type: '`+e.type+`'`)};function wq(e,t,n,r,i){var a=xq(e,n),o=a.length===1&&a[0]instanceof Q&&hq.has(a[0].type)?a[0]:new Q(`mrow`,a),s=new Q(`annotation`,[new fq(t)]);s.setAttribute(`encoding`,`application/x-tex`);var c=new Q(`math`,[new Q(`semantics`,[o,s])]);return c.setAttribute(`xmlns`,`http://www.w3.org/1998/Math/MathML`),r&&c.setAttribute(`display`,`block`),X([i?`katex`:`katex-mathml`],[c])}var Tq=[[1,1,1],[2,1,1],[3,1,1],[4,2,1],[5,2,1],[6,3,1],[7,4,2],[8,6,3],[9,7,6],[10,8,7],[11,10,9]],Eq=[.5,.6,.7,.8,.9,1,1.2,1.44,1.728,2.074,2.488],Dq=function(e,t){return t.size<2?e:Tq[e-1][t.size-1]},Oq=class e{constructor(t){this.style=void 0,this.color=void 0,this.size=void 0,this.textSize=void 0,this.phantom=void 0,this.font=void 0,this.fontFamily=void 0,this.fontWeight=void 0,this.fontShape=void 0,this.sizeMultiplier=void 0,this.maxSize=void 0,this.minRuleThickness=void 0,this._fontMetrics=void 0,this.style=t.style,this.color=t.color,this.size=t.size||e.BASESIZE,this.textSize=t.textSize||this.size,this.phantom=!!t.phantom,this.font=t.font||``,this.fontFamily=t.fontFamily||``,this.fontWeight=t.fontWeight||``,this.fontShape=t.fontShape||``,this.sizeMultiplier=Eq[this.size-1],this.maxSize=t.maxSize,this.minRuleThickness=t.minRuleThickness,this._fontMetrics=void 0}extend(t){var n={style:this.style,size:this.size,textSize:this.textSize,color:this.color,phantom:this.phantom,font:this.font,fontFamily:this.fontFamily,fontWeight:this.fontWeight,fontShape:this.fontShape,maxSize:this.maxSize,minRuleThickness:this.minRuleThickness};return Object.assign(n,t),new e(n)}havingStyle(e){return this.style===e?this:this.extend({style:e,size:Dq(this.textSize,e)})}havingCrampedStyle(){return this.havingStyle(this.style.cramp())}havingSize(e){return this.size===e&&this.textSize===e?this:this.extend({style:this.style.text(),size:e,textSize:e,sizeMultiplier:Eq[e-1]})}havingBaseStyle(t){t||=this.style.text();var n=Dq(e.BASESIZE,t);return this.size===n&&this.textSize===e.BASESIZE&&this.style===t?this:this.extend({style:t,size:n})}havingBaseSizing(){var e;switch(this.style.id){case 4:case 5:e=3;break;case 6:case 7:e=1;break;default:e=6}return this.extend({style:this.style.text(),size:e})}withColor(e){return this.extend({color:e})}withPhantom(){return this.extend({phantom:!0})}withFont(e){return this.extend({font:e})}withTextFontFamily(e){return this.extend({fontFamily:e,font:``})}withTextFontWeight(e){return this.extend({fontWeight:e,font:``})}withTextFontShape(e){return this.extend({fontShape:e,font:``})}sizingClasses(e){return e.size===this.size?[]:[`katex-sizing`,`reset-size`+e.size,`size`+this.size]}baseSizingClasses(){return this.size===e.BASESIZE?[]:[`katex-sizing`,`reset-size`+this.size,`size`+e.BASESIZE]}fontMetrics(){return this._fontMetrics||=PG(this.size),this._fontMetrics}getColor(){return this.phantom?`transparent`:this.color}};Oq.BASESIZE=6;var kq=function(e){return new Oq({style:e.displayMode?VW.DISPLAY:VW.TEXT,maxSize:e.maxSize,minRuleThickness:e.minRuleThickness})},Aq=function(e,t){if(t.displayMode){var n=[`katex-display`];t.leqno&&n.push(`leqno`),t.fleqn&&n.push(`fleqn`),e=X(n,[e])}return e},jq=function(e,t,n){var r=kq(n),i;return n.output===`mathml`?wq(e,t,r,n.displayMode,!0):(i=n.output===`html`?X([`katex`],[uq(e,r)]):X([`katex`],[wq(e,t,r,n.displayMode,!1),uq(e,r)]),Aq(i,n))},Mq=function(e,t,n){return Aq(X([`katex`],[uq(e,kq(n))]),n)},Nq={widehat:`^`,widecheck:`ˇ`,widetilde:`~`,utilde:`~`,overleftarrow:`←`,underleftarrow:`←`,xleftarrow:`←`,overrightarrow:`→`,underrightarrow:`→`,xrightarrow:`→`,underbrace:`⏟`,overbrace:`⏞`,underbracket:`⎵`,overbracket:`⎴`,overgroup:`⏠`,undergroup:`⏡`,overleftrightarrow:`↔`,underleftrightarrow:`↔`,xleftrightarrow:`↔`,Overrightarrow:`⇒`,xRightarrow:`⇒`,overleftharpoon:`↼`,xleftharpoonup:`↼`,overrightharpoon:`⇀`,xrightharpoonup:`⇀`,xLeftarrow:`⇐`,xLeftrightarrow:`⇔`,xhookleftarrow:`↩`,xhookrightarrow:`↪`,xmapsto:`↦`,xrightharpoondown:`⇁`,xleftharpoondown:`↽`,xrightleftharpoons:`⇌`,xleftrightharpoons:`⇋`,xtwoheadleftarrow:`↞`,xtwoheadrightarrow:`↠`,xlongequal:`=`,xtofrom:`⇄`,xrightleftarrows:`⇄`,xrightequilibrium:`⇌`,xleftequilibrium:`⇋`,"\\cdrightarrow":`→`,"\\cdleftarrow":`←`,"\\cdlongequal":`=`},Pq=function(e){var t=new Q(`mo`,[new fq(Nq[e.replace(/^\\/,``)])]);return t.setAttribute(`stretchy`,`true`),t},Fq={overrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],overleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],underrightarrow:[[`rightarrow`],.888,522,`xMaxYMin`],underleftarrow:[[`leftarrow`],.888,522,`xMinYMin`],xrightarrow:[[`rightarrow`],1.469,522,`xMaxYMin`],"\\cdrightarrow":[[`rightarrow`],3,522,`xMaxYMin`],xleftarrow:[[`leftarrow`],1.469,522,`xMinYMin`],"\\cdleftarrow":[[`leftarrow`],3,522,`xMinYMin`],Overrightarrow:[[`doublerightarrow`],.888,560,`xMaxYMin`],xRightarrow:[[`doublerightarrow`],1.526,560,`xMaxYMin`],xLeftarrow:[[`doubleleftarrow`],1.526,560,`xMinYMin`],overleftharpoon:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoonup:[[`leftharpoon`],.888,522,`xMinYMin`],xleftharpoondown:[[`leftharpoondown`],.888,522,`xMinYMin`],overrightharpoon:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoonup:[[`rightharpoon`],.888,522,`xMaxYMin`],xrightharpoondown:[[`rightharpoondown`],.888,522,`xMaxYMin`],xlongequal:[[`longequal`],.888,334,`xMinYMin`],"\\cdlongequal":[[`longequal`],3,334,`xMinYMin`],xtwoheadleftarrow:[[`twoheadleftarrow`],.888,334,`xMinYMin`],xtwoheadrightarrow:[[`twoheadrightarrow`],.888,334,`xMaxYMin`],overleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],overbrace:[[`leftbrace`,`midbrace`,`rightbrace`],1.6,548],underbrace:[[`leftbraceunder`,`midbraceunder`,`rightbraceunder`],1.6,548],underleftrightarrow:[[`leftarrow`,`rightarrow`],.888,522],xleftrightarrow:[[`leftarrow`,`rightarrow`],1.75,522],xLeftrightarrow:[[`doubleleftarrow`,`doublerightarrow`],1.75,560],xrightleftharpoons:[[`leftharpoondownplus`,`rightharpoonplus`],1.75,716],xleftrightharpoons:[[`leftharpoonplus`,`rightharpoondownplus`],1.75,716],xhookleftarrow:[[`leftarrow`,`righthook`],1.08,522],xhookrightarrow:[[`lefthook`,`rightarrow`],1.08,522],overlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],underlinesegment:[[`leftlinesegment`,`rightlinesegment`],.888,522],overbracket:[[`leftbracketover`,`rightbracketover`],1.6,440],underbracket:[[`leftbracketunder`,`rightbracketunder`],1.6,410],overgroup:[[`leftgroup`,`rightgroup`],.888,342],undergroup:[[`leftgroupunder`,`rightgroupunder`],.888,342],xmapsto:[[`leftmapsto`,`rightarrow`],1.5,522],xtofrom:[[`leftToFrom`,`rightToFrom`],1.75,528],xrightleftarrows:[[`baraboveleftarrow`,`rightarrowabovebar`],1.75,901],xrightequilibrium:[[`baraboveshortleftharpoon`,`rightharpoonaboveshortbar`],1.75,716],xleftequilibrium:[[`shortbaraboveleftharpoon`,`shortrightharpoonabovebar`],1.75,716]},Iq=new Set([`widehat`,`widecheck`,`widetilde`,`utilde`]),Lq=function(e,t){function n(){var n=4e5,r=e.label.slice(1);if(Iq.has(r)&&`base`in e){var i=e.base.type===`ordgroup`?e.base.body.length:1,a,o,s;if(i>5)r===`widehat`||r===`widecheck`?(a=420,n=2364,s=.42,o=r+`4`):(a=312,n=2340,s=.34,o=`tilde4`);else{var c=[1,1,2,2,3,3][i];r===`widehat`||r===`widecheck`?(n=[0,1062,2364,2364,2364][c],a=[0,239,300,360,420][c],s=[0,.24,.3,.3,.36,.42][c],o=r+c):(n=[0,600,1033,2339,2340][c],a=[0,260,286,306,312][c],s=[0,.26,.286,.3,.306,.34][c],o=`tilde`+c)}return{span:kK([],[new SG([new CG(o)],{width:`100%`,height:z(s),viewBox:`0 0 `+n+` `+a,preserveAspectRatio:`none`})],t),minWidth:0,height:s}}var l=[],u=Fq[r];if(!u)throw Error(`No SVG data for "`+r+`".`);var d=u[0],f=u[1],p=u[2],m=p/1e3,h=d.length,g,_;if(h===1){if(u.length!==4)throw Error(`Expected 4-tuple for single-path SVG data "`+r+`".`);g=[`hide-tail`],_=[u[3]]}else if(h===2)g=[`halfarrow-left`,`halfarrow-right`],_=[`xMinYMin`,`xMaxYMin`];else if(h===3)g=[`brace-left`,`brace-center`,`brace-right`],_=[`xMinYMin`,`xMidYMin`,`xMaxYMin`];else throw Error(`Correct katexImagesData or update code here to support + `+h+` children.`);for(var v=0;v0&&(i.style.minWidth=z(a)),i},Rq=function(e,t,n,r,i){var a,o=e.height+e.depth+n+r;if(/fbox|color|angl/.test(t)){if(a=X([`katex-stretchy`,t],[],i),t===`fbox`){var s=i.color&&i.getColor();s&&(a.style.borderColor=s)}}else{var c=[];/^[bx]cancel$/.test(t)&&c.push(new wG({x1:`0`,y1:`0`,x2:`100%`,y2:`100%`,"stroke-width":`0.046em`})),/^x?cancel$/.test(t)&&c.push(new wG({x1:`0`,y1:`100%`,x2:`100%`,y2:`0`,"stroke-width":`0.046em`})),a=kK([],[new SG(c,{width:`100%`,height:z(o)})],i)}return a.height=o,a.style.height=z(o),a},zq=[`bin`,`close`,`inner`,`open`,`punct`,`rel`],Bq=[`accent-token`,`mathord`,`op-token`,`spacing`,`textord`],Vq=new Set(zq),Hq=new Set(Bq);function Uq(e){return Vq.has(e)}function Wq(e,t){if(!e||e.type!==t)throw Error(`Expected node of type `+t+`, but got `+(e?`node of type `+e.type:String(e)));return e}function Gq(e){var t=Kq(e);if(!t)throw Error(`Expected node of symbol group type, but got `+(e?`node of type `+e.type:String(e)));return t}function Kq(e){return e.type===`atom`||Hq.has(e.type)?e:null}function qq(e,t,n){var r=``;for(var i of e.body)if(i.type===`textord`)r+=i.text;else if(n&&i.type===`spacing`&&i.text===` `)r+=` `;else throw new R(t,e);return r}var Jq=e=>{if(e instanceof xG)return e;if(DG(e)&&e.children.length===1)return Jq(e.children[0])},Yq=(e,t)=>{var n,r,i;e&&e.type===`supsub`?(r=Wq(e.base,`accent`),n=r.base,e.base=n,i=EG(cq(e,t)),e.base=r):(r=Wq(e,`accent`),n=r.base);var a=cq(n,t.havingCrampedStyle()),o=r.isShifty&&vW(n),s=0;o&&(s=Jq(a)?.skew??0);var c=r.label===`\\c`,l=c?a.height+a.depth:Math.min(a.height,t.fontMetrics().xHeight),u;if(r.isStretchy)u=Lq(r,t),u=FK({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`elem`,elem:u,wrapperClasses:[`svg-align`],wrapperStyle:s>0?{width:`calc(100% - `+z(2*s)+`)`,marginLeft:z(2*s)}:void 0}]});else{var d,f;r.label===`\\vec`?(d=BK(`vec`,t),f=zK.vec[1]):(d=TK({type:`textord`,mode:r.mode,text:r.label},t),d=TG(d),d.italic=0,f=d.width,c&&(l+=d.depth)),u=X([`accent-body`],[d]);var p=r.label===`\\textcircled`;p&&(u.classes.push(`accent-full`),l=a.height);var m=s;p||(m-=f/2),u.style.left=z(m),r.label===`\\textcircled`&&(u.style.top=`.2em`),u=FK({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:-l},{type:`elem`,elem:u}]})}var h=X([`mord`,`katex-accent`],[u],t);return i?(i.children[0]=h,i.height=Math.max(h.height,i.height),i.classes[0]=`mord`,i):h},Xq=(e,t)=>{var n=e.isStretchy?Pq(e.label):new Q(`mo`,[gq(e.label,e.mode)]),r=new Q(`mover`,[Cq(e.base,t),n]);return r.setAttribute(`accent`,`true`),r},Zq=new RegExp([`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`].map(e=>`\\`+e).join(`|`));Z({type:`accent`,names:[`\\acute`,`\\grave`,`\\ddot`,`\\tilde`,`\\bar`,`\\breve`,`\\check`,`\\hat`,`\\vec`,`\\dot`,`\\mathring`,`\\widecheck`,`\\widehat`,`\\widetilde`,`\\overrightarrow`,`\\overleftarrow`,`\\Overrightarrow`,`\\overleftrightarrow`,`\\overgroup`,`\\overlinesegment`,`\\overleftharpoon`,`\\overrightharpoon`],numArgs:1,handler:(e,t)=>{var n=XK(t[0]),r=!Zq.test(e.funcName),i=!r||e.funcName===`\\widehat`||e.funcName===`\\widetilde`||e.funcName===`\\widecheck`;return{type:`accent`,mode:e.parser.mode,label:e.funcName,isStretchy:r,isShifty:i,base:n}},htmlBuilder:Yq,mathmlBuilder:Xq}),Z({type:`accent`,names:[`\\'`,"\\`",`\\^`,`\\~`,`\\=`,`\\u`,`\\.`,`\\"`,`\\c`,`\\r`,`\\H`,`\\v`,`\\textcircled`],numArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`primitive`],handler:(e,t)=>{var n=t[0],r=e.parser.mode;return r===`math`&&(e.parser.settings.reportNonstrict(`mathVsTextAccents`,`LaTeX's accent `+e.funcName+` works only in text mode`),r=`text`),{type:`accent`,mode:r,label:e.funcName,isStretchy:!1,isShifty:!0,base:n}}}),Z({type:`accentUnder`,names:[`\\underleftarrow`,`\\underrightarrow`,`\\underleftrightarrow`,`\\undergroup`,`\\underlinesegment`,`\\utilde`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`accentUnder`,mode:n.mode,label:r,base:i}},htmlBuilder:(e,t)=>{var n=cq(e.base,t),r=Lq(e,t),i=e.label===`\\utilde`?.12:0;return X([`mord`,`accentunder`],[FK({positionType:`top`,positionData:n.height,children:[{type:`elem`,elem:r,wrapperClasses:[`svg-align`]},{type:`kern`,size:i},{type:`elem`,elem:n}]})],t)},mathmlBuilder:(e,t)=>{var n=Pq(e.label),r=new Q(`munder`,[Cq(e.base,t),n]);return r.setAttribute(`accentunder`,`true`),r}});var Qq=e=>{var t=new Q(`mpadded`,e?[e]:[]);return t.setAttribute(`width`,`+0.6em`),t.setAttribute(`lspace`,`0.3em`),t};Z({type:`xArrow`,names:[`\\xleftarrow`,`\\xrightarrow`,`\\xLeftarrow`,`\\xRightarrow`,`\\xleftrightarrow`,`\\xLeftrightarrow`,`\\xhookleftarrow`,`\\xhookrightarrow`,`\\xmapsto`,`\\xrightharpoondown`,`\\xrightharpoonup`,`\\xleftharpoondown`,`\\xleftharpoonup`,`\\xrightleftharpoons`,`\\xleftrightharpoons`,`\\xlongequal`,`\\xtwoheadrightarrow`,`\\xtwoheadleftarrow`,`\\xtofrom`,`\\xrightleftarrows`,`\\xrightequilibrium`,`\\xleftequilibrium`,`\\\\cdrightarrow`,`\\\\cdleftarrow`,`\\\\cdlongequal`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=e.funcName;return{type:`xArrow`,mode:r.mode,label:i,body:t[0],below:n[0]}},htmlBuilder(e,t){var n=t.style,r=t.havingStyle(n.sup()),i=NK(cq(e.body,r,t),t),a=e.label.slice(0,2)===`\\x`?`x`:`cd`;i.classes.push(a+`-arrow-pad`);var o;e.below&&(r=t.havingStyle(n.sub()),o=NK(cq(e.below,r,t),t),o.classes.push(a+`-arrow-pad`));var s=Lq(e,t),c=-t.fontMetrics().axisHeight+.5*s.height,l=-t.fontMetrics().axisHeight-.5*s.height-.111;(i.depth>.25||e.label===`\\xleftequilibrium`)&&(l-=i.depth);var u;if(o){var d=-t.fontMetrics().axisHeight+o.height+.5*s.height+.111;u=FK({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]},{type:`elem`,elem:o,shift:d}]})}else u=FK({positionType:`individualShift`,children:[{type:`elem`,elem:i,shift:l},{type:`elem`,elem:s,shift:c,wrapperClasses:[`svg-align`]}]});return X([`mrel`,`x-arrow`],[u],t)},mathmlBuilder(e,t){var n=Pq(e.label);n.setAttribute(`minsize`,e.label.charAt(0)===`x`?`1.75em`:`3.0em`);var r;if(e.body){var i=Qq(Cq(e.body,t));r=e.below?new Q(`munderover`,[n,Qq(Cq(e.below,t)),i]):new Q(`mover`,[n,i])}else e.below?r=new Q(`munder`,[n,Qq(Cq(e.below,t))]):(r=Qq(),r=new Q(`mover`,[n,r]));return r}});function $q(e,t){var n=nq(e.body,t,!0);return X([e.mclass],n,t)}function eJ(e,t){var n,r=xq(e.body,t);return e.mclass===`minner`?n=new Q(`mpadded`,r):e.mclass===`mord`?e.isCharacterBox?(n=r[0],n.type=`mi`):n=new Q(`mi`,r):(e.isCharacterBox?(n=r[0],n.type=`mo`):n=new Q(`mo`,r),e.mclass===`mbin`?(n.attributes.lspace=`0.22em`,n.attributes.rspace=`0.22em`):e.mclass===`mpunct`?(n.attributes.lspace=`0em`,n.attributes.rspace=`0.17em`):(e.mclass===`mopen`||e.mclass===`mclose`)&&(n.attributes.lspace=`0em`,n.attributes.rspace=`0em`)),n}Z({type:`mclass`,names:[`\\mathord`,`\\mathbin`,`\\mathrel`,`\\mathopen`,`\\mathclose`,`\\mathpunct`,`\\mathinner`],numArgs:1,primitive:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`mclass`,mode:n.mode,mclass:`m`+r.slice(5),body:ZK(i),isCharacterBox:vW(i)}},htmlBuilder:$q,mathmlBuilder:eJ});var tJ=e=>{var t=e.type===`ordgroup`&&e.body.length?e.body[0]:e;return t.type===`atom`&&(t.family===`bin`||t.family===`rel`)?`m`+t.family:`mord`};Z({type:`mclass`,names:[`\\@binrel`],numArgs:2,handler(e,t){return{type:`mclass`,mode:e.parser.mode,mclass:tJ(t[0]),body:ZK(t[1]),isCharacterBox:vW(t[1])}}}),Z({type:`mclass`,names:[`\\stackrel`,`\\overset`,`\\underset`],numArgs:2,handler(e,t){var n=e.parser,r=e.funcName,i=t[1],a=t[0],o=r===`\\stackrel`?`mrel`:tJ(i),s={type:`op`,mode:i.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,suppressBaseShift:r!==`\\stackrel`,body:ZK(i)},c=r===`\\underset`?{type:`supsub`,mode:a.mode,base:s,sub:a}:{type:`supsub`,mode:a.mode,base:s,sup:a};return{type:`mclass`,mode:n.mode,mclass:o,body:[c],isCharacterBox:vW(c)}}}),Z({type:`pmb`,names:[`\\pmb`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`pmb`,mode:e.parser.mode,mclass:tJ(t[0]),body:ZK(t[0])}},htmlBuilder(e,t){var n=nq(e.body,t,!0),r=X([e.mclass],n,t);return r.style.textShadow=`0.02em 0.01em 0.04px`,r},mathmlBuilder(e,t){var n=new Q(`mstyle`,xq(e.body,t));return n.setAttribute(`style`,`text-shadow: 0.02em 0.01em 0.04px`),n}});var nJ={">":`\\\\cdrightarrow`,"<":`\\\\cdleftarrow`,"=":`\\\\cdlongequal`,A:`\\uparrow`,V:`\\downarrow`,"|":`\\Vert`,".":`no arrow`},rJ=()=>({type:`styling`,body:[],mode:`math`,style:`display`,resetFont:!0}),iJ=e=>e.type===`textord`&&e.text===`@`,aJ=(e,t)=>(e.type===`mathord`||e.type===`atom`)&&e.text===t;function oJ(e,t,n){var r=nJ[e];switch(r){case`\\\\cdrightarrow`:case`\\\\cdleftarrow`:return n.callFunction(r,[t[0]],[t[1]]);case`\\uparrow`:case`\\downarrow`:var i=n.callFunction(`\\\\cdleft`,[t[0]],[]),a={type:`atom`,text:r,mode:`math`,family:`rel`},o={type:`ordgroup`,mode:`math`,body:[i,n.callFunction(`\\Big`,[a],[]),n.callFunction(`\\\\cdright`,[t[1]],[])]};return n.callFunction(`\\\\cdparent`,[o],[]);case`\\\\cdlongequal`:return n.callFunction(`\\\\cdlongequal`,[],[]);case`\\Vert`:return n.callFunction(`\\Big`,[{type:`textord`,text:`\\Vert`,mode:`math`}],[]);default:return{type:`textord`,text:` `,mode:`math`}}}function sJ(e){var t=[];for(e.gullet.beginGroup(),e.gullet.macros.set(`\\cr`,`\\\\\\relax`),e.gullet.beginGroup();;){t.push(e.parseExpression(!1,`\\\\`)),e.gullet.endGroup(),e.gullet.beginGroup();var n=e.fetch().text;if(n===`&`||n===`\\\\`)e.consume();else if(n===`\\end`){t[t.length-1].length===0&&t.pop();break}else throw new R(`Expected \\\\ or \\cr or \\end`,e.nextToken)}for(var r=[],i=[r],a=0;aAV`.includes(l))for(var d=0;d<2;d++){for(var f=!0,p=c+1;pAV=|." after @`,o[c])}var m={type:`styling`,body:[oJ(l,u,e)],mode:`math`,style:`display`,resetFont:!0};r.push(m),s=rJ()}a%2==0?r.push(s):r.shift(),r=[],i.push(r)}return e.gullet.endGroup(),e.gullet.endGroup(),{type:`array`,mode:`math`,body:i,arraystretch:1,addJot:!0,rowGaps:[null],cols:Array(i[0].length).fill({type:`align`,align:`c`,pregap:.25,postgap:.25}),colSeparationType:`CD`,hLinesBeforeRow:Array(i.length+1).fill([])}}Z({type:`cdlabel`,names:[`\\\\cdleft`,`\\\\cdright`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`cdlabel`,mode:n.mode,side:r.slice(4),label:t[0]}},htmlBuilder(e,t){var n=t.havingStyle(t.style.sup()),r=NK(cq(e.label,n,t),t);return r.classes.push(`cd-label-`+e.side),r.style.bottom=z(.8-r.depth),r.height=0,r.depth=0,r},mathmlBuilder(e,t){var n=new Q(`mrow`,[Cq(e.label,t)]);return n=new Q(`mpadded`,[n]),n.setAttribute(`width`,`0`),e.side===`left`&&n.setAttribute(`lspace`,`-1width`),n.setAttribute(`voffset`,`0.7em`),n=new Q(`mstyle`,[n]),n.setAttribute(`displaystyle`,`false`),n.setAttribute(`scriptlevel`,`1`),n}}),Z({type:`cdlabelparent`,names:[`\\\\cdparent`],numArgs:1,handler(e,t){return{type:`cdlabelparent`,mode:e.parser.mode,fragment:t[0]}},htmlBuilder(e,t){var n=NK(cq(e.fragment,t),t);return n.classes.push(`cd-vert-arrow`),n},mathmlBuilder(e,t){return new Q(`mrow`,[Cq(e.fragment,t)])}}),Z({type:`textord`,names:[`\\@char`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=qq(Wq(t[0],`ordgroup`),`\\@char has non-numeric argument`),i=parseInt(r),a;if(isNaN(i))throw new R(`\\@char has non-numeric argument `+r);if(i<0||i>1114111)throw new R(`\\@char with invalid code point `+r);return i<=65535?a=String.fromCharCode(i):(i-=65536,a=String.fromCharCode((i>>10)+55296,(i&1023)+56320)),{type:`textord`,mode:n.mode,text:a}}}),Z({type:`color`,names:[`\\textcolor`],numArgs:2,allowedInText:!0,argTypes:[`color`,`original`],handler(e,t){var n=e.parser,r=Wq(t[0],`color-token`).color,i=t[1];return{type:`color`,mode:n.mode,color:r,body:ZK(i)}},htmlBuilder:(e,t)=>MK(nq(e.body,t.withColor(e.color),!1)),mathmlBuilder:(e,t)=>{var n=new Q(`mstyle`,xq(e.body,t.withColor(e.color)));return n.setAttribute(`mathcolor`,e.color),n}}),Z({type:`color`,names:[`\\color`],numArgs:1,allowedInText:!0,argTypes:[`color`],handler(e,t){var n=e.parser,r=e.breakOnTokenText,i=Wq(t[0],`color-token`).color;n.gullet.macros.set(`\\current@color`,i);var a=n.parseExpression(!0,r);return{type:`color`,mode:n.mode,color:i,body:a}}}),Z({type:`cr`,names:[`\\\\`],numArgs:0,numOptionalArgs:0,allowedInText:!0,handler(e,t,n){var r=e.parser,i=r.gullet.future().text===`[`?r.parseSizeGroup(!0):null,a=!r.settings.displayMode||!r.settings.useStrictBehavior(`newLineInDisplayMode`,`In LaTeX, \\\\ or \\newline does nothing in display mode`);return{type:`cr`,mode:r.mode,newLine:a,size:i&&Wq(i,`size`).value}},htmlBuilder(e,t){var n=X([`mspace`],[],t);return e.newLine&&(n.classes.push(`katex-newline`),e.size&&(n.style.marginTop=z(uG(e.size,t)))),n},mathmlBuilder(e,t){var n=new Q(`mspace`);return e.newLine&&(n.setAttribute(`linebreak`,`newline`),e.size&&n.setAttribute(`height`,z(uG(e.size,t)))),n}});var cJ={"\\global":`\\global`,"\\long":`\\\\globallong`,"\\\\globallong":`\\\\globallong`,"\\def":`\\gdef`,"\\gdef":`\\gdef`,"\\edef":`\\xdef`,"\\xdef":`\\xdef`,"\\let":`\\\\globallet`,"\\futurelet":`\\\\globalfuture`},lJ=e=>{var t=e.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(t))throw new R(`Expected a control sequence`,e);return t},uJ=e=>{var t=e.gullet.popToken();return t.text===`=`&&(t=e.gullet.popToken(),t.text===` `&&(t=e.gullet.popToken())),t},dJ=(e,t,n,r)=>{var i=e.gullet.macros.get(n.text);i??=(n.noexpand=!0,{tokens:[n],numArgs:0,unexpandable:!e.gullet.isExpandable(n.text)}),e.gullet.macros.set(t,i,r)};Z({type:`internal`,names:[`\\global`,`\\long`,`\\\\globallong`],numArgs:0,allowedInText:!0,handler(e){var t=e.parser,n=e.funcName;t.consumeSpaces();var r=t.fetch();if(cJ[r.text])return(n===`\\global`||n===`\\\\globallong`)&&(r.text=cJ[r.text]),Wq(t.parseFunction(),`internal`);throw new R(`Invalid token after macro prefix`,r)}}),Z({type:`internal`,names:[`\\def`,`\\gdef`,`\\edef`,`\\xdef`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=t.gullet.popToken(),i=r.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(i))throw new R(`Expected a control sequence`,r);for(var a=0,o,s=[[]];t.gullet.future().text!==`{`;)if(r=t.gullet.popToken(),r.text===`#`){if(t.gullet.future().text===`{`){o=t.gullet.future(),s[a].push(`{`);break}if(r=t.gullet.popToken(),!/^[1-9]$/.test(r.text))throw new R(`Invalid argument number "`+r.text+`"`);if(parseInt(r.text)!==a+1)throw new R(`Argument number "`+r.text+`" out of order`);a++,s.push([])}else if(r.text===`EOF`)throw new R(`Expected a macro definition`);else s[a].push(r.text);var c=t.gullet.consumeArg().tokens;return o&&c.unshift(o),(n===`\\edef`||n===`\\xdef`)&&(c=t.gullet.expandTokens(c),c.reverse()),t.gullet.macros.set(i,{tokens:c,numArgs:a,delimiters:s},n===cJ[n]),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\let`,`\\\\globallet`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=lJ(t.gullet.popToken());return t.gullet.consumeSpaces(),dJ(t,r,uJ(t),n===`\\\\globallet`),{type:`internal`,mode:t.mode}}}),Z({type:`internal`,names:[`\\futurelet`,`\\\\globalfuture`],numArgs:0,allowedInText:!0,primitive:!0,handler(e){var t=e.parser,n=e.funcName,r=lJ(t.gullet.popToken()),i=t.gullet.popToken(),a=t.gullet.popToken();return dJ(t,r,a,n===`\\\\globalfuture`),t.gullet.pushToken(a),t.gullet.pushToken(i),{type:`internal`,mode:t.mode}}});var fJ=function(e,t,n){var r=MG(FG.math[e]&&FG.math[e].replace||e,t,n);if(!r)throw Error(`Unsupported symbol `+e+` and font size `+t+`.`);return r},pJ=function(e,t,n,r){var i=n.havingBaseStyle(t),a=X(r.concat(i.sizingClasses(n)),[e],n),o=i.sizeMultiplier/n.sizeMultiplier;return a.height*=o,a.depth*=o,a.maxFontSize=i.sizeMultiplier,a},mJ=function(e,t,n){var r=t.havingBaseStyle(n),i=(1-t.sizeMultiplier/r.sizeMultiplier)*t.fontMetrics().axisHeight;e.classes.push(`delimcenter`),e.style.top=z(i),e.height-=i,e.depth+=i},hJ=function(e,t,n,r,i,a){var o=pJ(SK(e,`Main-Regular`,i,r),t,r,a);return n&&mJ(o,r,t),o},gJ=function(e,t,n,r){return SK(e,`Size`+t+`-Regular`,n,r)},_J=function(e,t,n,r,i,a){var o=gJ(e,t,i,r),s=pJ(X([`delimsizing`,`size`+t],[o],r),VW.TEXT,r,a);return n&&mJ(s,r,VW.TEXT),s},vJ=function(e,t,n){return{type:`elem`,elem:X([`delimsizinginner`,t===`Size1-Regular`?`delim-size1`:`delim-size4`],[X([],[SK(e,t,n)])])}},yJ=function(e,t,n){var r=OG[`Size4-Regular`][e.charCodeAt(0)]?OG[`Size4-Regular`][e.charCodeAt(0)][4]:OG[`Size1-Regular`][e.charCodeAt(0)][4],i=kK([],[new SG([new CG(`inner`,nG(e,Math.round(1e3*t)))],{width:z(r),height:z(t),style:`width:`+z(r),viewBox:`0 0 `+1e3*r+` `+Math.round(1e3*t),preserveAspectRatio:`xMinYMin`})],n);return i.height=t,i.style.height=z(t),i.style.width=z(r),{type:`elem`,elem:i}},bJ=.008,xJ={type:`kern`,size:-1*bJ},SJ=new Set([`|`,`\\lvert`,`\\rvert`,`\\vert`]),CJ=new Set([`\\|`,`\\lVert`,`\\rVert`,`\\Vert`]),wJ=function(e,t,n,r,i,a){var o,s,c,l,u=``,d=0;o=c=l=e,s=null;var f=`Size1-Regular`;e===`\\uparrow`?c=l=`⏐`:e===`\\Uparrow`?c=l=`‖`:e===`\\downarrow`?o=c=`⏐`:e===`\\Downarrow`?o=c=`‖`:e===`\\updownarrow`?(o=`\\uparrow`,c=`⏐`,l=`\\downarrow`):e===`\\Updownarrow`?(o=`\\Uparrow`,c=`‖`,l=`\\Downarrow`):SJ.has(e)?(c=`∣`,u=`vert`,d=333):CJ.has(e)?(c=`∥`,u=`doublevert`,d=556):e===`[`||e===`\\lbrack`?(o=`⎡`,c=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lbrack`,d=667):e===`]`||e===`\\rbrack`?(o=`⎤`,c=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rbrack`,d=667):e===`\\lfloor`||e===`⌊`?(c=o=`⎢`,l=`⎣`,f=`Size4-Regular`,u=`lfloor`,d=667):e===`\\lceil`||e===`⌈`?(o=`⎡`,c=l=`⎢`,f=`Size4-Regular`,u=`lceil`,d=667):e===`\\rfloor`||e===`⌋`?(c=o=`⎥`,l=`⎦`,f=`Size4-Regular`,u=`rfloor`,d=667):e===`\\rceil`||e===`⌉`?(o=`⎤`,c=l=`⎥`,f=`Size4-Regular`,u=`rceil`,d=667):e===`(`||e===`\\lparen`?(o=`⎛`,c=`⎜`,l=`⎝`,f=`Size4-Regular`,u=`lparen`,d=875):e===`)`||e===`\\rparen`?(o=`⎞`,c=`⎟`,l=`⎠`,f=`Size4-Regular`,u=`rparen`,d=875):e===`\\{`||e===`\\lbrace`?(o=`⎧`,s=`⎨`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\}`||e===`\\rbrace`?(o=`⎫`,s=`⎬`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lgroup`||e===`⟮`?(o=`⎧`,l=`⎩`,c=`⎪`,f=`Size4-Regular`):e===`\\rgroup`||e===`⟯`?(o=`⎫`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):e===`\\lmoustache`||e===`⎰`?(o=`⎧`,l=`⎭`,c=`⎪`,f=`Size4-Regular`):(e===`\\rmoustache`||e===`⎱`)&&(o=`⎫`,l=`⎩`,c=`⎪`,f=`Size4-Regular`);var p=fJ(o,f,i),m=p.height+p.depth,h=fJ(c,f,i),g=h.height+h.depth,_=fJ(l,f,i),v=_.height+_.depth,y=0,b=1;if(s!==null){var x=fJ(s,f,i);y=x.height+x.depth,b=2}var S=m+v+y,C=S+Math.max(0,Math.ceil((t-S)/(b*g)))*b*g,ee=r.fontMetrics().axisHeight;n&&(ee*=r.sizeMultiplier);var te=C/2-ee,ne=[];if(u.length>0){var re=C-m-v,ie=Math.round(C*1e3),ae=iG(u,Math.round(re*1e3)),oe=new CG(u,ae),se=z(d/1e3),ce=z(ie/1e3),le=kK([],[new SG([oe],{width:se,height:ce,viewBox:`0 0 `+d+` `+ie})],r);le.height=ie/1e3,le.style.width=se,le.style.height=ce,ne.push({type:`elem`,elem:le})}else{if(ne.push(vJ(l,f,i)),ne.push(xJ),s===null){var ue=C-m-v+2*bJ;ne.push(yJ(c,ue,r))}else{var de=(C-m-v-y)/2+2*bJ;ne.push(yJ(c,de,r)),ne.push(xJ),ne.push(vJ(s,f,i)),ne.push(xJ),ne.push(yJ(c,de,r))}ne.push(xJ),ne.push(vJ(o,f,i))}var fe=r.havingBaseStyle(VW.TEXT);return pJ(X([`delimsizing`,`mult`],[FK({positionType:`bottom`,positionData:te,children:ne})],fe),VW.TEXT,r,a)},TJ=80,EJ=.08,DJ=function(e,t,n,r,i){return kK([`hide-tail`],[new SG([new CG(e,tG(e,r,n))],{width:`400em`,height:z(t),viewBox:`0 0 400000 `+n,preserveAspectRatio:`xMinYMin slice`})],i)},OJ=function(e,t){var n=t.havingBaseSizing(),r=RJ(`\\surd`,e*n.sizeMultiplier,IJ,n),i=n.sizeMultiplier,a=Math.max(0,t.minRuleThickness-t.fontMetrics().sqrtRuleThickness),o,s,c,l,u;return r.type===`small`?(l=1e3+1e3*a+TJ,e<1?i=1:e<1.4&&(i=.7),s=(1+a+EJ)/i,c=(1+a)/i,o=DJ(`sqrtMain`,s,l,a,t),o.style.minWidth=`0.853em`,u=.833/i):r.type===`large`?(l=(1e3+TJ)*MJ[r.size],c=(MJ[r.size]+a)/i,s=(MJ[r.size]+a+EJ)/i,o=DJ(`sqrtSize`+r.size,s,l,a,t),o.style.minWidth=`1.02em`,u=1/i):(s=e+a+EJ,c=e+a,l=Math.floor(1e3*e+a)+TJ,o=DJ(`sqrtTall`,s,l,a,t),o.style.minWidth=`0.742em`,u=1.056),o.height=c,o.style.height=z(s),{span:o,advanceWidth:u,ruleWidth:(t.fontMetrics().sqrtRuleThickness+a)*i}},kJ=new Set([`(`,`\\lparen`,`)`,`\\rparen`,`[`,`\\lbrack`,`]`,`\\rbrack`,`\\{`,`\\lbrace`,`\\}`,`\\rbrace`,`\\lfloor`,`\\rfloor`,`⌊`,`⌋`,`\\lceil`,`\\rceil`,`⌈`,`⌉`,`\\surd`]),AJ=new Set([`\\uparrow`,`\\downarrow`,`\\updownarrow`,`\\Uparrow`,`\\Downarrow`,`\\Updownarrow`,`|`,`\\|`,`\\vert`,`\\Vert`,`\\lvert`,`\\rvert`,`\\lVert`,`\\rVert`,`\\lgroup`,`\\rgroup`,`⟮`,`⟯`,`\\lmoustache`,`\\rmoustache`,`⎰`,`⎱`]),jJ=new Set([`<`,`>`,`\\langle`,`\\rangle`,`/`,`\\backslash`,`\\lt`,`\\gt`]),MJ=[0,1.2,1.8,2.4,3],NJ=function(e,t,n,r,i){if(e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`),kJ.has(e)||jJ.has(e))return _J(e,t,!1,n,r,i);if(AJ.has(e))return wJ(e,MJ[t],!1,n,r,i);throw new R(`Illegal delimiter: '`+e+`'`)},PJ=[{type:`small`,style:VW.SCRIPTSCRIPT},{type:`small`,style:VW.SCRIPT},{type:`small`,style:VW.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4}],FJ=[{type:`small`,style:VW.SCRIPTSCRIPT},{type:`small`,style:VW.SCRIPT},{type:`small`,style:VW.TEXT},{type:`stack`}],IJ=[{type:`small`,style:VW.SCRIPTSCRIPT},{type:`small`,style:VW.SCRIPT},{type:`small`,style:VW.TEXT},{type:`large`,size:1},{type:`large`,size:2},{type:`large`,size:3},{type:`large`,size:4},{type:`stack`}],LJ=function(e){if(e.type===`small`)return`Main-Regular`;if(e.type===`large`)return`Size`+e.size+`-Regular`;if(e.type===`stack`)return`Size4-Regular`;var t=e.type;throw Error(`Add support for delim type '`+t+`' here.`)},RJ=function(e,t,n,r){for(var i=Math.min(2,3-r.style.size);it)return a}return n[n.length-1]},zJ=function(e,t,n,r,i,a){e===`<`||e===`\\lt`||e===`⟨`?e=`\\langle`:(e===`>`||e===`\\gt`||e===`⟩`)&&(e=`\\rangle`);var o=jJ.has(e)?PJ:kJ.has(e)?IJ:FJ,s=RJ(e,t,o,r);return s.type===`small`?hJ(e,s.style,n,r,i,a):s.type===`large`?_J(e,s.size,n,r,i,a):wJ(e,t,n,r,i,a)},BJ=function(e,t,n,r,i,a){var o=r.fontMetrics().axisHeight*r.sizeMultiplier,s=901,c=5/r.fontMetrics().ptPerEm,l=Math.max(t-o,n+o);return zJ(e,Math.max(l/500*s,2*l-c),!0,r,i,a)},VJ={"\\bigl":{mclass:`mopen`,size:1},"\\Bigl":{mclass:`mopen`,size:2},"\\biggl":{mclass:`mopen`,size:3},"\\Biggl":{mclass:`mopen`,size:4},"\\bigr":{mclass:`mclose`,size:1},"\\Bigr":{mclass:`mclose`,size:2},"\\biggr":{mclass:`mclose`,size:3},"\\Biggr":{mclass:`mclose`,size:4},"\\bigm":{mclass:`mrel`,size:1},"\\Bigm":{mclass:`mrel`,size:2},"\\biggm":{mclass:`mrel`,size:3},"\\Biggm":{mclass:`mrel`,size:4},"\\big":{mclass:`mord`,size:1},"\\Big":{mclass:`mord`,size:2},"\\bigg":{mclass:`mord`,size:3},"\\Bigg":{mclass:`mord`,size:4}},HJ=new Set(`(,\\lparen,),\\rparen,[,\\lbrack,],\\rbrack,\\{,\\lbrace,\\},\\rbrace,\\lfloor,\\rfloor,⌊,⌋,\\lceil,\\rceil,⌈,⌉,<,>,\\langle,⟨,\\rangle,⟩,\\lt,\\gt,\\lvert,\\rvert,\\lVert,\\rVert,\\lgroup,\\rgroup,⟮,⟯,\\lmoustache,\\rmoustache,⎰,⎱,/,\\backslash,|,\\vert,\\|,\\Vert,\\uparrow,\\Uparrow,\\downarrow,\\Downarrow,\\updownarrow,\\Updownarrow,.`.split(`,`));function UJ(e){return`isMiddle`in e}function WJ(e,t){var n=Kq(e);if(n&&HJ.has(n.text))return n;throw n?new R(`Invalid delimiter '`+n.text+`' after '`+t.funcName+`'`,e):new R(`Invalid delimiter type '`+e.type+`'`,e)}Z({type:`delimsizing`,names:[`\\bigl`,`\\Bigl`,`\\biggl`,`\\Biggl`,`\\bigr`,`\\Bigr`,`\\biggr`,`\\Biggr`,`\\bigm`,`\\Bigm`,`\\biggm`,`\\Biggm`,`\\big`,`\\Big`,`\\bigg`,`\\Bigg`],numArgs:1,argTypes:[`primitive`],handler:(e,t)=>{var n=WJ(XK(t[0]),e);return{type:`delimsizing`,mode:e.parser.mode,size:VJ[e.funcName].size,mclass:VJ[e.funcName].mclass,delim:n.text}},htmlBuilder:(e,t)=>e.delim===`.`?X([e.mclass]):NJ(e.delim,e.size,t,e.mode,[e.mclass]),mathmlBuilder:e=>{var t=[];e.delim!==`.`&&t.push(gq(e.delim,e.mode));var n=new Q(`mo`,t);e.mclass===`mopen`||e.mclass===`mclose`?n.setAttribute(`fence`,`true`):n.setAttribute(`fence`,`false`),n.setAttribute(`stretchy`,`true`);var r=z(MJ[e.size]);return n.setAttribute(`minsize`,r),n.setAttribute(`maxsize`,r),n}});function GJ(e){if(!e.body)throw Error(`Bug: The leftright ParseNode wasn't fully parsed.`)}Z({type:`leftright-right`,names:[`\\right`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser.gullet.macros.get(`\\current@color`);if(n&&typeof n!=`string`)throw new R(`\\current@color set to non-string in \\right`);return{type:`leftright-right`,mode:e.parser.mode,delim:WJ(t[0],e).text,color:n}}}),Z({type:`leftright`,names:[`\\left`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=WJ(t[0],e),r=e.parser;++r.leftrightDepth;var i=r.parseExpression(!1);--r.leftrightDepth,r.expect(`\\right`,!1);var a=Wq(r.parseFunction(),`leftright-right`);return{type:`leftright`,mode:r.mode,body:i,left:n.text,right:a.delim,rightColor:a.color}},htmlBuilder:(e,t)=>{GJ(e);for(var n=nq(e.body,t,!0,[`mopen`,`mclose`]),r=0,i=0,a=!1,o=0;o{GJ(e);var n=xq(e.body,t);if(e.left!==`.`){var r=new Q(`mo`,[gq(e.left,e.mode)]);r.setAttribute(`fence`,`true`),n.unshift(r)}if(e.right!==`.`){var i=new Q(`mo`,[gq(e.right,e.mode)]);i.setAttribute(`fence`,`true`),e.rightColor&&i.setAttribute(`mathcolor`,e.rightColor),n.push(i)}return _q(n)}}),Z({type:`middle`,names:[`\\middle`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=WJ(t[0],e);if(!e.parser.leftrightDepth)throw new R(`\\middle without preceding \\left`,n);return{type:`middle`,mode:e.parser.mode,delim:n.text}},htmlBuilder:(e,t)=>{var n;return e.delim===`.`?n=sq(t,[]):(n=NJ(e.delim,1,t,e.mode,[]),n.isMiddle={delim:e.delim,options:t}),n},mathmlBuilder:(e,t)=>{var n=new Q(`mo`,[e.delim===`\\vert`||e.delim===`|`?gq(`|`,`text`):gq(e.delim,e.mode)]);return n.setAttribute(`fence`,`true`),n.setAttribute(`lspace`,`0.05em`),n.setAttribute(`rspace`,`0.05em`),n}}),Z({type:`enclose`,names:[`\\colorbox`],numArgs:2,allowedInText:!0,argTypes:[`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=Wq(t[0],`color-token`).color,o=t[1];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:a,body:o}},htmlBuilder:(e,t)=>{var n=NK(cq(e.body,t),t),r=e.label.slice(1),i=t.sizeMultiplier,a,o,s=vW(e.body);if(r===`sout`)a=X([`katex-stretchy`,`katex-sout`]),a.height=t.fontMetrics().defaultRuleThickness/i,o=-.5*t.fontMetrics().xHeight;else if(r===`phase`){var c=uG({number:.6,unit:`pt`},t),l=uG({number:.35,unit:`ex`},t),u=t.havingBaseSizing();i/=u.sizeMultiplier;var d=n.height+n.depth+c+l;n.style.paddingLeft=z(d/2+c);var f=Math.floor(1e3*d*i);a=kK([`hide-tail`],[new SG([new CG(`phase`,$W(f))],{width:`400em`,height:z(f/1e3),viewBox:`0 0 400000 `+f,preserveAspectRatio:`xMinYMin slice`})],t),a.style.height=z(d),o=n.depth+c+l}else{/cancel/.test(r)?s||n.classes.push(`cancel-pad`):r===`angl`?n.classes.push(`anglpad`):n.classes.push(`boxpad`);var p,m,h=0;/box/.test(r)?(h=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness),p=t.fontMetrics().fboxsep+(r===`colorbox`?0:h),m=p):r===`angl`?(h=Math.max(t.fontMetrics().defaultRuleThickness,t.minRuleThickness),p=4*h,m=Math.max(0,.25-n.depth)):(p=s?.2:0,m=p),a=Rq(n,r,p,m,t),/fbox|boxed|fcolorbox/.test(r)?(a.style.borderStyle=`solid`,a.style.borderWidth=z(h)):r===`angl`&&h!==.049&&(a.style.borderTopWidth=z(h),a.style.borderRightWidth=z(h)),o=n.depth+m,e.backgroundColor&&(a.style.backgroundColor=e.backgroundColor,e.borderColor&&(a.style.borderColor=e.borderColor))}var g;if(e.backgroundColor)g=FK({positionType:`individualShift`,children:[{type:`elem`,elem:a,shift:o},{type:`elem`,elem:n,shift:0}]});else{var _=/cancel|phase/.test(r)?[`svg-align`]:[];g=FK({positionType:`individualShift`,children:[{type:`elem`,elem:n,shift:0},{type:`elem`,elem:a,shift:o,wrapperClasses:_}]})}return/cancel/.test(r)&&(g.height=n.height,g.depth=n.depth),/cancel/.test(r)&&!s?X([`mord`,`cancel-lap`],[g],t):X([`mord`],[g],t)},mathmlBuilder:(e,t)=>{var n,r=new Q(e.label.includes(`colorbox`)?`mpadded`:`menclose`,[Cq(e.body,t)]);switch(e.label){case`\\cancel`:r.setAttribute(`notation`,`updiagonalstrike`);break;case`\\bcancel`:r.setAttribute(`notation`,`downdiagonalstrike`);break;case`\\phase`:r.setAttribute(`notation`,`phasorangle`);break;case`\\sout`:r.setAttribute(`notation`,`horizontalstrike`);break;case`\\fbox`:r.setAttribute(`notation`,`box`);break;case`\\angl`:r.setAttribute(`notation`,`actuarial`);break;case`\\fcolorbox`:case`\\colorbox`:if(n=t.fontMetrics().fboxsep*t.fontMetrics().ptPerEm,r.setAttribute(`width`,`+`+2*n+`pt`),r.setAttribute(`height`,`+`+2*n+`pt`),r.setAttribute(`lspace`,n+`pt`),r.setAttribute(`voffset`,n+`pt`),e.label===`\\fcolorbox`){var i=Math.max(t.fontMetrics().fboxrule,t.minRuleThickness);r.setAttribute(`style`,`border: `+z(i)+` solid `+e.borderColor)}break;case`\\xcancel`:r.setAttribute(`notation`,`updiagonalstrike downdiagonalstrike`)}return e.backgroundColor&&r.setAttribute(`mathbackground`,e.backgroundColor),r}}),Z({type:`enclose`,names:[`\\fcolorbox`],numArgs:3,allowedInText:!0,argTypes:[`color`,`color`,`hbox`],handler(e,t,n){var r=e.parser,i=e.funcName,a=Wq(t[0],`color-token`).color,o=Wq(t[1],`color-token`).color,s=t[2];return{type:`enclose`,mode:r.mode,label:i,backgroundColor:o,borderColor:a,body:s}}}),Z({type:`enclose`,names:[`\\fbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\fbox`,body:t[0]}}}),Z({type:`enclose`,names:[`\\cancel`,`\\bcancel`,`\\xcancel`,`\\phase`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\sout`],numArgs:1,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName;n.mode===`math`&&n.settings.reportNonstrict(`mathVsSout`,`LaTeX's \\sout works only in text mode`);var i=t[0];return{type:`enclose`,mode:n.mode,label:r,body:i}}}),Z({type:`enclose`,names:[`\\angl`],numArgs:1,argTypes:[`hbox`],allowedInText:!1,handler(e,t){return{type:`enclose`,mode:e.parser.mode,label:`\\angl`,body:t[0]}}});var KJ={};function qJ(e){for(var t=e.type,n=e.names,r=e.props,i=e.handler,a=e.htmlBuilder,o=e.mathmlBuilder,s={type:t,numArgs:r.numArgs||0,allowedInText:!1,numOptionalArgs:0,handler:i},c=0;c{if(!e.parser.settings.displayMode)throw new R(`{`+e.envName+`} can be used only in display mode.`)},$J=new Set([`gather`,`gather*`]);function eY(e){if(!e.includes(`ed`))return!e.includes(`*`)}function tY(e,t,n){var r=t.hskipBeforeAndAfter,i=t.addJot,a=t.cols,o=t.arraystretch,s=t.colSeparationType,c=t.autoTag,l=t.singleRow,u=t.emptySingleRow,d=t.maxNumCols,f=t.leqno;if(e.gullet.beginGroup(),l||e.gullet.macros.set(`\\cr`,`\\\\\\relax`),!o){var p=e.gullet.expandMacroAsText(`\\arraystretch`);if(p==null)o=1;else if(o=parseFloat(p),!o||o<0)throw new R(`Invalid \\arraystretch: `+p)}e.gullet.beginGroup();var m=[],h=[m],g=[],_=[],v=c==null?void 0:[];function y(){c&&e.gullet.macros.set(`\\@eqnsw`,`1`,!0)}function b(){v&&(e.gullet.macros.get(`\\df@tag`)?(v.push(e.subparse([new XJ(`\\df@tag`)])),e.gullet.macros.set(`\\df@tag`,void 0,!0)):v.push(!!c&&e.gullet.macros.get(`\\@eqnsw`)===`1`))}for(y(),_.push(ZJ(e));;){var x=e.parseExpression(!1,l?`\\end`:`\\\\`);e.gullet.endGroup(),e.gullet.beginGroup();var S={type:`ordgroup`,mode:e.mode,body:x};n&&(S={type:`styling`,mode:e.mode,style:n,resetFont:!0,body:[S]}),m.push(S);var C=e.fetch().text;if(C===`&`){if(d&&m.length===d){if(l||s)throw new R(`Too many tab characters: &`,e.nextToken);e.settings.reportNonstrict(`textEnv`,`Too few columns specified in the {array} column argument.`)}e.consume()}else if(C===`\\end`){b(),m.length===1&&S.type===`styling`&&S.body.length===1&&S.body[0].type===`ordgroup`&&S.body[0].body.length===0&&(h.length>1||!u)&&!Array.isArray(v?.[v.length-1])&&!(c&&v?.[v.length-1]===!0)&&h.pop(),_.length0&&(_+=.25),c.push({pos:_,isDashed:e[t]})}for(v(a[0]),n=0;n0&&(te+=g,xe))for(n=0;n=o)){var ve=void 0;(r>0||e.hskipBeforeAndAfter)&&(ve=fe?.pregap??d,ve!==0&&(ae=X([`arraycolsep`],[]),ae.style.width=z(ve),ie.push(ae)));var ye=[];for(n=0;n0){for(var Ee=AK(`katex-hline`,t,l),De=AK(`katex-hdashline`,t,l),Oe=[{type:`elem`,elem:Te,shift:0}];c.length>0;){var ke=c.pop(),Ae=ke.pos-ne;ke.isDashed?Oe.push({type:`elem`,elem:De,shift:Ae}):Oe.push({type:`elem`,elem:Ee,shift:Ae})}Te=FK({positionType:`individualShift`,children:Oe})}if(se.length===0)return X([`mord`],[Te],t);var je=X([`katex-tag`],[FK({positionType:`individualShift`,children:se})],t);return MK([Te,je])},iY={c:`center `,l:`left `,r:`right `},aY=function(e,t){for(var n=[],r=new Q(`mtd`,[],[`mtr-glue`]),i=new Q(`mtd`,[],[`mml-eqn-num`]),a=0;a0){var p=e.cols,m=``,h=!1,g=0,_=p.length;p[0].type===`separator`&&(d+=`top `,g=1),p[p.length-1].type===`separator`&&(d+=`bottom `,--_);for(var v=g;v<_;v++){var y=p[v];y.type===`align`?(f+=iY[y.align],h&&(m+=`none `),h=!0):y.type===`separator`&&(h&&=(m+=y.separator===`|`?`solid `:`dashed `,!1))}l.setAttribute(`columnalign`,f.trim()),/[sd]/.test(m)&&l.setAttribute(`columnlines`,m.trim())}if(e.colSeparationType===`align`){for(var b=e.cols||[],x=``,S=1;S0?`left `:``,d+=ee[ee.length-1].length>0?`right `:``;for(var te=1;te0&&u&&(p=1),n[d]={type:`align`,align:f,pregap:p,postgap:0}}return i.colSeparationType=u?`align`:`alignat`,i};qJ({type:`array`,names:[`array`,`darray`],props:{numArgs:1},handler(e,t){var n=(Kq(t[0])?[t[0]]:Wq(t[0],`ordgroup`).body).map(function(e){var t=Gq(e).text;if(`lcr`.includes(t))return{type:`align`,align:t};if(t===`|`)return{type:`separator`,separator:`|`};if(t===`:`)return{type:`separator`,separator:`:`};throw new R(`Unknown column alignment: `+t,e)}),r={cols:n,hskipBeforeAndAfter:!0,maxNumCols:n.length};return tY(e.parser,r,nY(e.envName))},htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`matrix`,`pmatrix`,`bmatrix`,`Bmatrix`,`vmatrix`,`Vmatrix`,`matrix*`,`pmatrix*`,`bmatrix*`,`Bmatrix*`,`vmatrix*`,`Vmatrix*`],props:{numArgs:0},handler(e){var t={matrix:null,pmatrix:[`(`,`)`],bmatrix:[`[`,`]`],Bmatrix:[`\\{`,`\\}`],vmatrix:[`|`,`|`],Vmatrix:[`\\Vert`,`\\Vert`]}[e.envName.replace(`*`,``)],n=`c`,r={hskipBeforeAndAfter:!1,cols:[{type:`align`,align:n}]};if(e.envName.charAt(e.envName.length-1)===`*`){var i=e.parser;if(i.consumeSpaces(),i.fetch().text===`[`){if(i.consume(),i.consumeSpaces(),n=i.fetch().text,!`lcr`.includes(n))throw new R(`Expected l or c or r`,i.nextToken);i.consume(),i.consumeSpaces(),i.expect(`]`),i.consume(),r.cols=[{type:`align`,align:n}]}}var a=tY(e.parser,r,nY(e.envName)),o=Math.max(0,...a.body.map(e=>e.length));return a.cols=Array(o).fill({type:`align`,align:n}),t?{type:`leftright`,mode:e.mode,body:[a],left:t[0],right:t[1],rightColor:void 0}:a},htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`smallmatrix`],props:{numArgs:0},handler(e){var t=tY(e.parser,{arraystretch:.5},`script`);return t.colSeparationType=`small`,t},htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`subarray`],props:{numArgs:1},handler(e,t){var n=(Kq(t[0])?[t[0]]:Wq(t[0],`ordgroup`).body).map(function(e){var t=Gq(e).text;if(`lc`.includes(t))return{type:`align`,align:t};throw new R(`Unknown column alignment: `+t,e)});if(n.length>1)throw new R(`{subarray} can contain only one column`);var r={cols:n,hskipBeforeAndAfter:!1,arraystretch:.5},i=tY(e.parser,r,`script`);if(i.body.length>0&&i.body[0].length>1)throw new R(`{subarray} can contain only one column`);return i},htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`cases`,`dcases`,`rcases`,`drcases`],props:{numArgs:0},handler(e){var t=tY(e.parser,{arraystretch:1.2,cols:[{type:`align`,align:`l`,pregap:0,postgap:1},{type:`align`,align:`l`,pregap:0,postgap:0}]},nY(e.envName));return{type:`leftright`,mode:e.mode,body:[t],left:e.envName.includes(`r`)?`.`:`\\{`,right:e.envName.includes(`r`)?`\\}`:`.`,rightColor:void 0}},htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`align`,`align*`,`aligned`,`split`],props:{numArgs:0},handler:oY,htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`gathered`,`gather`,`gather*`],props:{numArgs:0},handler(e){$J.has(e.envName)&&QJ(e);var t={cols:[{type:`align`,align:`c`}],addJot:!0,colSeparationType:`gather`,autoTag:eY(e.envName),emptySingleRow:!0,leqno:e.parser.settings.leqno};return tY(e.parser,t,`display`)},htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`alignat`,`alignat*`,`alignedat`],props:{numArgs:1},handler:oY,htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`equation`,`equation*`],props:{numArgs:0},handler(e){QJ(e);var t={autoTag:eY(e.envName),emptySingleRow:!0,singleRow:!0,maxNumCols:1,leqno:e.parser.settings.leqno};return tY(e.parser,t,`display`)},htmlBuilder:rY,mathmlBuilder:aY}),qJ({type:`array`,names:[`CD`],props:{numArgs:0},handler(e){return QJ(e),sJ(e.parser)},htmlBuilder:rY,mathmlBuilder:aY}),$(`\\nonumber`,`\\gdef\\@eqnsw{0}`),$(`\\notag`,`\\nonumber`),Z({type:`text`,names:[`\\hline`,`\\hdashline`],numArgs:0,allowedInText:!0,allowedInMath:!0,handler(e,t){throw new R(e.funcName+` valid only within array environment`)}});var sY=KJ;Z({type:`environment`,names:[`\\begin`,`\\end`],numArgs:1,argTypes:[`text`],handler(e,t){var n=e.parser,r=e.funcName,i=t[0];if(i.type!==`ordgroup`)throw new R(`Invalid environment name`,i);var a=qq(i,`Environment name should contain only text characters and spaces`,!0);if(r===`\\begin`){if(!Object.prototype.hasOwnProperty.call(sY,a))throw new R(`No such environment: `+a,i);var o=sY[a],s=n.parseArguments(`\\begin{`+a+`}`,o),c=s.args,l=s.optArgs,u={mode:n.mode,envName:a,parser:n},d=o.handler(u,c,l);n.expect(`\\end`,!1);var f=n.nextToken,p=Wq(n.parseFunction(),`environment`);if(p.name!==a)throw new R(`Mismatch: \\begin{`+a+`} matched by \\end{`+p.name+`}`,f);return d}return{type:`environment`,mode:n.mode,name:a,nameGroup:i}}});var cY=(e,t)=>{var n=e.font,r=t.withFont(n);return cq(e.body,r)},lY=(e,t)=>{var n=e.font,r=t.withFont(n);return Cq(e.body,r)},uY={"\\Bbb":`\\mathbb`,"\\bold":`\\mathbf`,"\\frak":`\\mathfrak`};Z({type:`font`,names:[`\\mathrm`,`\\mathit`,`\\mathbf`,`\\mathnormal`,`\\mathsfit`,`\\mathbb`,`\\mathcal`,`\\mathfrak`,`\\mathscr`,`\\mathsf`,`\\mathtt`,`\\Bbb`,`\\bold`,`\\frak`],numArgs:1,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=XK(t[0]),a=r in uY?uY[r]:r;return{type:`font`,mode:n.mode,font:a.slice(1),body:i}},htmlBuilder:cY,mathmlBuilder:lY}),Z({type:`mclass`,names:[`\\boldsymbol`,`\\bm`],numArgs:1,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`mclass`,mode:n.mode,mclass:tJ(r),body:[{type:`font`,mode:n.mode,font:`boldsymbol`,body:r}],isCharacterBox:vW(r)}}}),Z({type:`font`,names:[`\\rm`,`\\sf`,`\\tt`,`\\bf`,`\\it`,`\\cal`],numArgs:0,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=e.breakOnTokenText,a=n.mode,o=n.parseExpression(!0,i);return{type:`font`,mode:a,font:`math`+r.slice(1),body:{type:`ordgroup`,mode:n.mode,body:o}}}});var dY=(e,t)=>{var n=t.style,r=n.fracNum(),i=n.fracDen(),a=t.havingStyle(r),o=cq(e.numer,a,t);if(e.continued){var s=8.5/t.fontMetrics().ptPerEm,c=3.5/t.fontMetrics().ptPerEm;o.height=o.height0?3*f:7*f,h=t.fontMetrics().denom1):(d>0?(p=t.fontMetrics().num2,m=f):(p=t.fontMetrics().num3,m=3*f),h=t.fontMetrics().denom2);var g;if(u){var _=t.fontMetrics().axisHeight;p-o.depth-(_+.5*d){var n=new Q(`mfrac`,[Cq(e.numer,t),Cq(e.denom,t)]);if(!e.hasBarLine)n.setAttribute(`linethickness`,`0px`);else if(e.barSize){var r=uG(e.barSize,t);n.setAttribute(`linethickness`,z(r))}if(e.leftDelim!=null||e.rightDelim!=null){var i=[];if(e.leftDelim!=null){var a=new Q(`mo`,[new fq(e.leftDelim.replace(`\\`,``))]);a.setAttribute(`fence`,`true`),i.push(a)}if(i.push(n),e.rightDelim!=null){var o=new Q(`mo`,[new fq(e.rightDelim.replace(`\\`,``))]);o.setAttribute(`fence`,`true`),i.push(o)}return _q(i)}return n},pY=(e,t)=>t?{type:`styling`,mode:e.mode,style:t,body:[e]}:e;Z({type:`genfrac`,names:[`\\cfrac`,`\\dfrac`,`\\frac`,`\\tfrac`,`\\dbinom`,`\\binom`,`\\tbinom`,`\\\\atopfrac`,`\\\\bracefrac`,`\\\\brackfrac`],numArgs:2,allowedInArgument:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0],a=t[1],o,s=null,c=null;switch(r){case`\\cfrac`:case`\\dfrac`:case`\\frac`:case`\\tfrac`:o=!0;break;case`\\\\atopfrac`:o=!1;break;case`\\dbinom`:case`\\binom`:case`\\tbinom`:o=!1,s=`(`,c=`)`;break;case`\\\\bracefrac`:o=!1,s=`\\{`,c=`\\}`;break;case`\\\\brackfrac`:o=!1,s=`[`,c=`]`;break;default:throw Error(`Unrecognized genfrac command`)}var l=r===`\\cfrac`,u=null;return l||r.startsWith(`\\d`)?u=`display`:r.startsWith(`\\t`)&&(u=`text`),pY({type:`genfrac`,mode:n.mode,numer:i,denom:a,continued:l,hasBarLine:o,leftDelim:s,rightDelim:c,barSize:null},u)},htmlBuilder:dY,mathmlBuilder:fY}),Z({type:`infix`,names:[`\\over`,`\\choose`,`\\atop`,`\\brace`,`\\brack`],numArgs:0,infix:!0,handler(e){var t=e.parser,n=e.funcName,r=e.token,i;switch(n){case`\\over`:i=`\\frac`;break;case`\\choose`:i=`\\binom`;break;case`\\atop`:i=`\\\\atopfrac`;break;case`\\brace`:i=`\\\\bracefrac`;break;case`\\brack`:i=`\\\\brackfrac`;break;default:throw Error(`Unrecognized infix genfrac command`)}return{type:`infix`,mode:t.mode,replaceWith:i,token:r}}});var mY=[`display`,`text`,`script`,`scriptscript`],hY=function(e){var t=null;return e.length>0&&(t=e,t=t===`.`?null:t),t};Z({type:`genfrac`,names:[`\\genfrac`],numArgs:6,allowedInArgument:!0,argTypes:[`math`,`math`,`size`,`text`,`math`,`math`],handler(e,t){var n=e.parser,r=t[4],i=t[5],a=XK(t[0]),o=a.type===`atom`&&a.family===`open`?hY(a.text):null,s=XK(t[1]),c=s.type===`atom`&&s.family===`close`?hY(s.text):null,l=Wq(t[2],`size`),u,d=null;l.isBlank?u=!0:(d=l.value,u=d.number>0);var f=null,p=t[3];if(p.type===`ordgroup`){if(p.body.length>0){var m=Wq(p.body[0],`textord`);f=mY[Number(m.text)]}}else p=Wq(p,`textord`),f=mY[Number(p.text)];return pY({type:`genfrac`,mode:n.mode,numer:r,denom:i,continued:!1,hasBarLine:u,barSize:d,leftDelim:o,rightDelim:c},f)}}),Z({type:`infix`,names:[`\\above`],numArgs:1,argTypes:[`size`],infix:!0,handler(e,t){var n=e.parser;e.funcName;var r=e.token;return{type:`infix`,mode:n.mode,replaceWith:`\\\\abovefrac`,size:Wq(t[0],`size`).value,token:r}}}),Z({type:`genfrac`,names:[`\\\\abovefrac`],numArgs:3,argTypes:[`math`,`size`,`math`],handler:(e,t)=>{var n=e.parser;e.funcName;var r=t[0],i=Wq(t[1],`infix`).size;if(!i)throw Error(`\\\\abovefrac expected size, but got `+String(i));var a=t[2],o=i.number>0;return{type:`genfrac`,mode:n.mode,numer:r,denom:a,continued:!1,hasBarLine:o,barSize:i,leftDelim:null,rightDelim:null}}});var gY=(e,t)=>{var n=t.style,r,i;e.type===`supsub`?(r=e.sup?cq(e.sup,t.havingStyle(n.sup()),t):cq(e.sub,t.havingStyle(n.sub()),t),i=Wq(e.base,`horizBrace`)):i=Wq(e,`horizBrace`);var a=cq(i.base,t.havingBaseStyle(VW.DISPLAY)),o=Lq(i,t),s=i.isOver?FK({positionType:`firstBaseline`,children:[{type:`elem`,elem:a},{type:`kern`,size:.1},{type:`elem`,elem:o,wrapperClasses:[`svg-align`]}]}):FK({positionType:`bottom`,positionData:a.depth+.1+o.height,children:[{type:`elem`,elem:o,wrapperClasses:[`svg-align`]},{type:`kern`,size:.1},{type:`elem`,elem:a}]});if(r){var c=X([`minner`,i.isOver?`mover`:`munder`],[s],t);s=i.isOver?FK({positionType:`firstBaseline`,children:[{type:`elem`,elem:c},{type:`kern`,size:.2},{type:`elem`,elem:r}]}):FK({positionType:`bottom`,positionData:c.depth+.2+r.height+r.depth,children:[{type:`elem`,elem:r},{type:`kern`,size:.2},{type:`elem`,elem:c}]})}return X([`minner`,i.isOver?`mover`:`munder`],[s],t)};Z({type:`horizBrace`,names:[`\\overbrace`,`\\underbrace`,`\\overbracket`,`\\underbracket`],numArgs:1,handler(e,t){var n=e.parser,r=e.funcName;return{type:`horizBrace`,mode:n.mode,label:r,isOver:r.includes(`\\over`),base:t[0]}},htmlBuilder:gY,mathmlBuilder:(e,t)=>{var n=Pq(e.label);return new Q(e.isOver?`mover`:`munder`,[Cq(e.base,t),n])}}),Z({type:`href`,names:[`\\href`],numArgs:2,argTypes:[`url`,`original`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[1],i=Wq(t[0],`url`).url;return n.settings.isTrusted({command:`\\href`,url:i})?{type:`href`,mode:n.mode,href:i,body:ZK(r)}:n.formatUnsupportedCmd(`\\href`)},htmlBuilder:(e,t)=>{var n=nq(e.body,t,!1);return jK(e.href,[],n,t)},mathmlBuilder:(e,t)=>{var n=Sq(e.body,t);return n instanceof Q||(n=new Q(`mrow`,[n])),n.setAttribute(`href`,e.href),n}}),Z({type:`href`,names:[`\\url`],numArgs:1,argTypes:[`url`],allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=Wq(t[0],`url`).url;if(!n.settings.isTrusted({command:`\\url`,url:r}))return n.formatUnsupportedCmd(`\\url`);for(var i=[],a=0;a{var n=e.parser,r=e.funcName;e.token;var i=Wq(t[0],`raw`).string,a=t[1];n.settings.strict&&n.settings.reportNonstrict(`htmlExtension`,`HTML extension is disabled on strict mode`);var o,s={};switch(r){case`\\htmlClass`:s.class=i,o={command:`\\htmlClass`,class:i};break;case`\\htmlId`:s.id=i,o={command:`\\htmlId`,id:i};break;case`\\htmlStyle`:s.style=i,o={command:`\\htmlStyle`,style:i};break;case`\\htmlData`:for(var c=`{,}`,l=[],u=``,d=0;d{var n=nq(e.body,t,!1),r=[`enclosing`];e.attributes.class&&r.push(...e.attributes.class.trim().split(/\s+/));var i=X(r,n,t);for(var a of Object.entries(e.attributes)){var o=a[0],s=a[1];o!==`class`&&i.setAttribute(o,s)}return i},mathmlBuilder:(e,t)=>Sq(e.body,t)}),Z({type:`htmlmathml`,names:[`\\html@mathml`],numArgs:2,allowedInArgument:!0,allowedInText:!0,handler:(e,t)=>({type:`htmlmathml`,mode:e.parser.mode,html:ZK(t[0]),mathml:ZK(t[1])}),htmlBuilder:(e,t)=>MK(nq(e.html,t,!1)),mathmlBuilder:(e,t)=>Sq(e.mathml,t)});var _Y=function(e){if(/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(e))return{number:+e,unit:`bp`};var t=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(e);if(!t)throw new R(`Invalid size: '`+e+`' in \\includegraphics`);var n={number:+(t[1]+t[2]),unit:t[3]};if(!lG(n))throw new R(`Invalid unit: '`+n.unit+`' in \\includegraphics.`);return n};Z({type:`includegraphics`,names:[`\\includegraphics`],numArgs:1,numOptionalArgs:1,argTypes:[`raw`,`url`],allowedInText:!1,handler:(e,t,n)=>{var r=e.parser,i={number:0,unit:`em`},a={number:.9,unit:`em`},o={number:0,unit:`em`},s=``;if(n[0])for(var c=Wq(n[0],`raw`).string.split(`,`),l=0;l{var n=uG(e.height,t),r=0;e.totalheight.number>0&&(r=uG(e.totalheight,t)-n);var i=0;e.width.number>0&&(i=uG(e.width,t));var a={height:z(n+r)};i>0&&(a.width=z(i)),r>0&&(a.verticalAlign=z(-r));var o=new yG(e.src,e.alt,a);return o.height=n,o.depth=r,o},mathmlBuilder:(e,t)=>{var n=new Q(`mglyph`,[]);n.setAttribute(`alt`,e.alt);var r=uG(e.height,t),i=0;if(e.totalheight.number>0&&(i=uG(e.totalheight,t)-r,n.setAttribute(`valign`,z(-i))),n.setAttribute(`height`,z(r+i)),e.width.number>0){var a=uG(e.width,t);n.setAttribute(`width`,z(a))}return n.setAttribute(`src`,e.src),n}}),Z({type:`kern`,names:[`\\kern`,`\\mkern`,`\\hskip`,`\\mskip`],numArgs:1,argTypes:[`size`],primitive:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=Wq(t[0],`size`);if(n.settings.strict){var a=r[1]===`m`,o=i.value.unit===`mu`;a?(o||n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` supports only mu units, `+(`not `+i.value.unit+` units`)),n.mode!==`math`&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` works only in math mode`)):o&&n.settings.reportNonstrict(`mathVsTextUnits`,`LaTeX's `+r+` doesn't support mu units`)}return{type:`kern`,mode:n.mode,dimension:i.value}},htmlBuilder(e,t){return IK(e.dimension,t)},mathmlBuilder(e,t){return new pq(uG(e.dimension,t))}}),Z({type:`lap`,names:[`\\mathllap`,`\\mathrlap`,`\\mathclap`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=e.funcName,i=t[0];return{type:`lap`,mode:n.mode,alignment:r.slice(5),body:i}},htmlBuilder:(e,t)=>{var n;e.alignment===`clap`?(n=X([],[cq(e.body,t)]),n=X([`katex-inner`],[n],t)):n=X([`katex-inner`],[cq(e.body,t)]);var r=X([`katex-fix`],[]),i=X([e.alignment],[n,r],t),a=X([`katex-strut`]);return a.style.height=z(i.height+i.depth),i.depth&&(a.style.verticalAlign=z(-i.depth)),i.children.unshift(a),i=X([`katex-thinbox`],[i],t),X([`mord`,`katex-vbox`],[i],t)},mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[Cq(e.body,t)]);if(e.alignment!==`rlap`){var r=e.alignment===`llap`?`-1`:`-0.5`;n.setAttribute(`lspace`,r+`width`)}return n.setAttribute(`width`,`0px`),n}}),Z({type:`styling`,names:[`\\(`,`$`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){var n=e.funcName,r=e.parser,i=r.mode;r.switchMode(`math`);var a=n===`\\(`?`\\)`:`$`,o=r.parseExpression(!1,a);return r.expect(a),r.switchMode(i),{type:`styling`,mode:r.mode,style:`text`,resetFont:!0,body:o}}}),Z({type:`text`,names:[`\\)`,`\\]`],numArgs:0,allowedInText:!0,allowedInMath:!1,handler(e,t){throw new R(`Mismatched `+e.funcName)}});var vY=(e,t)=>{switch(t.style.size){case VW.DISPLAY.size:return e.display;case VW.TEXT.size:return e.text;case VW.SCRIPT.size:return e.script;case VW.SCRIPTSCRIPT.size:return e.scriptscript;default:return e.text}};Z({type:`mathchoice`,names:[`\\mathchoice`],numArgs:4,primitive:!0,handler:(e,t)=>({type:`mathchoice`,mode:e.parser.mode,display:ZK(t[0]),text:ZK(t[1]),script:ZK(t[2]),scriptscript:ZK(t[3])}),htmlBuilder:(e,t)=>MK(nq(vY(e,t),t,!1)),mathmlBuilder:(e,t)=>Sq(vY(e,t),t)});var yY=(e,t,n,r,i,a,o)=>{e=X([],[e]);var s=n&&vW(n),c,l;if(t){var u=cq(t,r.havingStyle(i.sup()),r);l={elem:u,kern:Math.max(r.fontMetrics().bigOpSpacing1,r.fontMetrics().bigOpSpacing3-u.depth)}}if(n){var d=cq(n,r.havingStyle(i.sub()),r);c={elem:d,kern:Math.max(r.fontMetrics().bigOpSpacing2,r.fontMetrics().bigOpSpacing4-d.height)}}var f;if(l&&c)f=FK({positionType:`bottom`,positionData:r.fontMetrics().bigOpSpacing5+c.elem.height+c.elem.depth+c.kern+e.depth+o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else if(c)f=FK({positionType:`top`,positionData:e.height-o,children:[{type:`kern`,size:r.fontMetrics().bigOpSpacing5},{type:`elem`,elem:c.elem,marginLeft:z(-a)},{type:`kern`,size:c.kern},{type:`elem`,elem:e}]});else if(l)f=FK({positionType:`bottom`,positionData:e.depth+o,children:[{type:`elem`,elem:e},{type:`kern`,size:l.kern},{type:`elem`,elem:l.elem,marginLeft:z(a)},{type:`kern`,size:r.fontMetrics().bigOpSpacing5}]});else return e;var p=[f];if(c&&a!==0&&!s){var m=X([`mspace`],[],r);m.style.marginRight=z(a),p.unshift(m)}return X([`mop`,`op-limits`],p,r)},bY=new Set([`\\smallint`]),xY=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=Wq(e.base,`op`),i=!0):a=Wq(e,`op`);var o=t.style,s=!1;o.size===VW.DISPLAY.size&&a.symbol&&!bY.has(a.name)&&(s=!0);var c,l;if(a.symbol){var u=s?`Size2-Regular`:`Size1-Regular`,d=``;if((a.name===`\\oiint`||a.name===`\\oiiint`)&&(d=a.name.slice(1),a.name=d===`oiint`?`\\iint`:`\\iiint`),c=SK(a.name,u,`math`,t,[`mop`,`op-symbol`,s?`large-op`:`small-op`]),l=c.italic,d.length>0){var f=BK(d+`Size`+(s?`2`:`1`),t);c=FK({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:0},{type:`elem`,elem:f,shift:s?.08:0}]}),a.name=`\\`+d,c.classes.unshift(`mop`),c.italic=l}}else if(a.body){var p=nq(a.body,t,!0);p.length===1&&p[0]instanceof xG?(c=p[0],c.classes[0]=`mop`):c=X([`mop`],p,t)}else{for(var m=[],h=1;h{var n;if(e.symbol)n=new Q(`mo`,[gq(e.name,e.mode)]),bY.has(e.name)&&n.setAttribute(`largeop`,`false`);else if(e.body)n=new Q(`mo`,xq(e.body,t));else{n=new Q(`mi`,[new fq(e.name.slice(1))]);var r=new Q(`mo`,[gq(`⁡`,`text`)]);n=e.parentIsSupSub?new Q(`mrow`,[n,r]):dq([n,r])}return n},CY={"∏":`\\prod`,"∐":`\\coprod`,"∑":`\\sum`,"⋀":`\\bigwedge`,"⋁":`\\bigvee`,"⋂":`\\bigcap`,"⋃":`\\bigcup`,"⨀":`\\bigodot`,"⨁":`\\bigoplus`,"⨂":`\\bigotimes`,"⨄":`\\biguplus`,"⨆":`\\bigsqcup`};Z({type:`op`,names:`\\coprod.\\bigvee.\\bigwedge.\\biguplus.\\bigcap.\\bigcup.\\intop.\\prod.\\sum.\\bigotimes.\\bigoplus.\\bigodot.\\bigsqcup.\\smallint.∏.∐.∑.⋀.⋁.⋂.⋃.⨀.⨁.⨂.⨄.⨆`.split(`.`),numArgs:0,handler:(e,t)=>{var n=e.parser,r=e.funcName;return r.length===1&&(r=CY[r]),{type:`op`,mode:n.mode,limits:!0,parentIsSupSub:!1,symbol:!0,name:r}},htmlBuilder:xY,mathmlBuilder:SY}),Z({type:`op`,names:[`\\mathop`],numArgs:1,primitive:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`op`,mode:n.mode,limits:!1,parentIsSupSub:!1,symbol:!1,body:ZK(r)}}});var wY={"∫":`\\int`,"∬":`\\iint`,"∭":`\\iiint`,"∮":`\\oint`,"∯":`\\oiint`,"∰":`\\oiiint`};Z({type:`op`,names:`\\arcsin.\\arccos.\\arctan.\\arctg.\\arcctg.\\arg.\\ch.\\cos.\\cosec.\\cosh.\\cot.\\cotg.\\coth.\\csc.\\ctg.\\cth.\\deg.\\dim.\\exp.\\hom.\\ker.\\lg.\\ln.\\log.\\sec.\\sin.\\sinh.\\sh.\\tan.\\tanh.\\tg.\\th`.split(`.`),numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\det`,`\\gcd`,`\\inf`,`\\lim`,`\\max`,`\\min`,`\\Pr`,`\\sup`],numArgs:0,handler(e){var t=e.parser,n=e.funcName;return{type:`op`,mode:t.mode,limits:!0,parentIsSupSub:!1,symbol:!1,name:n}}}),Z({type:`op`,names:[`\\int`,`\\iint`,`\\iiint`,`\\oint`,`\\oiint`,`\\oiiint`,`∫`,`∬`,`∭`,`∮`,`∯`,`∰`],numArgs:0,allowedInArgument:!0,handler(e){var t=e.parser,n=e.funcName;return n.length===1&&(n=wY[n]),{type:`op`,mode:t.mode,limits:!1,parentIsSupSub:!1,symbol:!0,name:n}}});var TY=(e,t)=>{var n,r,i=!1,a;e.type===`supsub`?(n=e.sup,r=e.sub,a=Wq(e.base,`operatorname`),i=!0):a=Wq(e,`operatorname`);var o;if(a.body.length>0){for(var s=nq(a.body.map(e=>{var t=`text`in e?e.text:void 0;return typeof t==`string`?{type:`textord`,mode:e.mode,text:t}:e}),t.withFont(`mathrm`),!0),c=0;c{var n=e.parser,r=e.funcName,i=t[0];return{type:`operatorname`,mode:n.mode,body:ZK(i),alwaysHandleSupSub:r===`\\operatornamewithlimits`,limits:!1,parentIsSupSub:!1}},htmlBuilder:TY,mathmlBuilder:(e,t)=>{for(var n=xq(e.body,t.withFont(`mathrm`)),r=!0,i=0;ie.toText()).join(``))]);var s=new Q(`mi`,n);s.setAttribute(`mathvariant`,`normal`);var c=new Q(`mo`,[gq(`⁡`,`text`)]);return e.parentIsSupSub?new Q(`mrow`,[s,c]):dq([s,c])}}),$(`\\operatorname`,`\\@ifstar\\operatornamewithlimits\\operatorname@`),YK({type:`ordgroup`,htmlBuilder(e,t){return e.semisimple?MK(nq(e.body,t,!1)):X([`mord`],nq(e.body,t,!0),t)},mathmlBuilder(e,t){return Sq(e.body,t,!0)}}),Z({type:`overline`,names:[`\\overline`],numArgs:1,handler(e,t){var n=e.parser,r=t[0];return{type:`overline`,mode:n.mode,body:r}},htmlBuilder(e,t){var n=cq(e.body,t.havingCrampedStyle()),r=AK(`overline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-overline`],[FK({positionType:`firstBaseline`,children:[{type:`elem`,elem:n},{type:`kern`,size:3*i},{type:`elem`,elem:r},{type:`kern`,size:i}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new fq(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`mover`,[Cq(e.body,t),n]);return r.setAttribute(`accent`,`true`),r}}),Z({type:`phantom`,names:[`\\phantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`phantom`,mode:n.mode,body:ZK(r)}},htmlBuilder:(e,t)=>MK(nq(e.body,t.withPhantom(),!1)),mathmlBuilder:(e,t)=>new Q(`mphantom`,xq(e.body,t))}),$(`\\hphantom`,`\\smash{\\phantom{#1}}`),Z({type:`vphantom`,names:[`\\vphantom`],numArgs:1,allowedInText:!0,handler:(e,t)=>{var n=e.parser,r=t[0];return{type:`vphantom`,mode:n.mode,body:r}},htmlBuilder:(e,t)=>X([`mord`,`rlap`],[X([`katex-inner`],[cq(e.body,t.withPhantom())]),X([`katex-fix`],[])],t),mathmlBuilder:(e,t)=>{var n=new Q(`mpadded`,[new Q(`mphantom`,xq(ZK(e.body),t))]);return n.setAttribute(`width`,`0px`),n}}),Z({type:`raisebox`,names:[`\\raisebox`],numArgs:2,argTypes:[`size`,`hbox`],allowedInText:!0,handler(e,t){var n=e.parser,r=Wq(t[0],`size`).value,i=t[1];return{type:`raisebox`,mode:n.mode,dy:r,body:i}},htmlBuilder(e,t){var n=cq(e.body,t);return FK({positionType:`shift`,positionData:-uG(e.dy,t),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){var n=new Q(`mpadded`,[Cq(e.body,t)]),r=e.dy.number+e.dy.unit;return n.setAttribute(`voffset`,r),n}});var EY=(e,t)=>({type:`reflectbox`,mode:e.parser.mode,body:t[0]});Z({type:`reflectbox`,names:[`\\reflectbox`],numArgs:1,argTypes:[`hbox`],allowedInText:!0,handler:EY,htmlBuilder(e,t){return X([`mord`,`reflectbox`],[cq(e.body,t)],t)},mathmlBuilder(e,t){return Cq(e.body,t)}}),Z({type:`reflectbox`,names:[`\\mathreflectbox`],numArgs:1,argTypes:[`math`],handler:EY}),Z({type:`internal`,names:[`\\relax`],numArgs:0,allowedInText:!0,allowedInArgument:!0,handler(e){return{type:`internal`,mode:e.parser.mode}}}),Z({type:`rule`,names:[`\\rule`],numArgs:2,numOptionalArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:[`size`,`size`,`size`],handler(e,t,n){var r=e.parser,i=n[0],a=Wq(t[0],`size`),o=Wq(t[1],`size`);return{type:`rule`,mode:r.mode,shift:i&&Wq(i,`size`).value,width:a.value,height:o.value}},htmlBuilder(e,t){var n=X([`mord`,`katex-rule`],[],t),r=uG(e.width,t),i=uG(e.height,t),a=e.shift?uG(e.shift,t):0;return n.style.borderRightWidth=z(r),n.style.borderTopWidth=z(i),n.style.bottom=z(a),n.width=r,n.height=i+a,n.depth=-a,n.maxFontSize=i*1.125*t.sizeMultiplier,n},mathmlBuilder(e,t){var n=uG(e.width,t),r=uG(e.height,t),i=e.shift?uG(e.shift,t):0,a=t.color&&t.getColor()||`black`,o=new Q(`mspace`);o.setAttribute(`mathbackground`,a),o.setAttribute(`width`,z(n)),o.setAttribute(`height`,z(r));var s=new Q(`mpadded`,[o]);return i>=0?s.setAttribute(`height`,z(i)):(s.setAttribute(`height`,z(i)),s.setAttribute(`depth`,z(-i))),s.setAttribute(`voffset`,z(i)),s}});function DY(e,t,n){for(var r=nq(e,t,!1),i=t.sizeMultiplier/n.sizeMultiplier,a=0;a{var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!1,n);return{type:`sizing`,mode:i.mode,size:OY.indexOf(r)+1,body:a}},htmlBuilder:(e,t)=>{var n=t.havingSize(e.size);return DY(e.body,n,t)},mathmlBuilder:(e,t)=>{var n=t.havingSize(e.size),r=new Q(`mstyle`,xq(e.body,n));return r.setAttribute(`mathsize`,z(n.sizeMultiplier)),r}}),Z({type:`smash`,names:[`\\smash`],numArgs:1,numOptionalArgs:1,allowedInText:!0,handler:(e,t,n)=>{var r=e.parser,i=!1,a=!1,o=n[0]&&Wq(n[0],`ordgroup`);if(o)for(var s,c=0;c{var n=X([],[cq(e.body,t)]);if(!e.smashHeight&&!e.smashDepth)return n;if(e.smashHeight&&(n.height=0),e.smashDepth&&(n.depth=0),e.smashHeight&&e.smashDepth)return X([`mord`,`katex-smash`],[n],t);if(n.children)for(var r=0;r{var n=new Q(`mpadded`,[Cq(e.body,t)]);return e.smashHeight&&n.setAttribute(`height`,`0px`),e.smashDepth&&n.setAttribute(`depth`,`0px`),n}}),Z({type:`sqrt`,names:[`\\sqrt`],numArgs:1,numOptionalArgs:1,handler(e,t,n){var r=e.parser,i=n[0],a=t[0];return{type:`sqrt`,mode:r.mode,body:a,index:i}},htmlBuilder(e,t){var n=cq(e.body,t.havingCrampedStyle());n.height===0&&(n.height=t.fontMetrics().xHeight),n=NK(n,t);var r=t.fontMetrics().defaultRuleThickness,i=r;t.style.idn.height+n.depth+a&&(a=(a+u-n.height-n.depth)/2);var d=s.height-n.height-a-c;n.style.paddingLeft=z(l);var f=FK({positionType:`firstBaseline`,children:[{type:`elem`,elem:n,wrapperClasses:[`svg-align`]},{type:`kern`,size:-(n.height+d)},{type:`elem`,elem:s},{type:`kern`,size:c}]});if(e.index){var p=t.havingStyle(VW.SCRIPTSCRIPT),m=cq(e.index,p,t);return X([`mord`,`sqrt`],[X([`katex-root`],[FK({positionType:`shift`,positionData:-(.6*(f.height-f.depth)),children:[{type:`elem`,elem:m}]})]),f],t)}return X([`mord`,`sqrt`],[f],t)},mathmlBuilder(e,t){var n=e.body,r=e.index;return r?new Q(`mroot`,[Cq(n,t),Cq(r,t)]):new Q(`msqrt`,[Cq(n,t)])}});var kY={display:VW.DISPLAY,text:VW.TEXT,script:VW.SCRIPT,scriptscript:VW.SCRIPTSCRIPT};function AY(e){return e in kY}Z({type:`styling`,names:[`\\displaystyle`,`\\textstyle`,`\\scriptstyle`,`\\scriptscriptstyle`],numArgs:0,allowedInText:!0,primitive:!0,handler(e,t){var n=e.breakOnTokenText,r=e.funcName,i=e.parser,a=i.parseExpression(!0,n),o=r.slice(1,r.length-5);if(!AY(o))throw Error(`Unknown style: `+o);return{type:`styling`,mode:i.mode,style:o,body:a}},htmlBuilder(e,t){var n=kY[e.style],r=t.havingStyle(n);return e.resetFont&&(r=r.withFont(``)),DY(e.body,r,t)},mathmlBuilder(e,t){var n=kY[e.style],r=t.havingStyle(n);e.resetFont&&(r=r.withFont(``));var i=new Q(`mstyle`,xq(e.body,r)),a={display:[`0`,`true`],text:[`0`,`false`],script:[`1`,`false`],scriptscript:[`2`,`false`]}[e.style];return i.setAttribute(`scriptlevel`,a[0]),i.setAttribute(`displaystyle`,a[1]),i}});var jY=function(e,t){var n=e.base;return n?n.type===`op`?n.limits&&(t.style.size===VW.DISPLAY.size||n.alwaysHandleSupSub)?xY:null:n.type===`operatorname`?n.alwaysHandleSupSub&&(t.style.size===VW.DISPLAY.size||n.limits)?TY:null:n.type===`accent`?vW(n.base)?Yq:null:n.type===`horizBrace`&&!e.sub===n.isOver?gY:null:null};YK({type:`supsub`,htmlBuilder(e,t){var n=jY(e,t);if(n)return n(e,t);var r=e.base,i=e.sup,a=e.sub,o=cq(r,t),s,c,l=t.fontMetrics(),u=0,d=0,f=r&&vW(r);if(i){var p=t.havingStyle(t.style.sup());s=cq(i,p,t),f||(u=o.height-p.fontMetrics().supDrop*p.sizeMultiplier/t.sizeMultiplier)}if(a){var m=t.havingStyle(t.style.sub());c=cq(a,m,t),f||(d=o.depth+m.fontMetrics().subDrop*m.sizeMultiplier/t.sizeMultiplier)}var h=t.style===VW.DISPLAY?l.sup1:t.style.cramped?l.sup3:l.sup2,g=t.sizeMultiplier,_=z(.5/l.ptPerEm/g),v=null;if(c){var y=e.base&&e.base.type===`op`&&e.base.name&&(e.base.name===`\\oiint`||e.base.name===`\\oiiint`);(o instanceof xG||y)&&(v=z(-(o.italic??0)))}var b;if(s&&c){u=Math.max(u,h,s.depth+.25*l.xHeight),d=Math.max(d,l.sub2);var x=4*l.defaultRuleThickness;if(u-s.depth-(c.height-d)0&&(u+=S,d-=S)}b=FK({positionType:`individualShift`,children:[{type:`elem`,elem:c,shift:d,marginRight:_,marginLeft:v},{type:`elem`,elem:s,shift:-u,marginRight:_}]})}else if(c)d=Math.max(d,l.sub1,c.height-.8*l.xHeight),b=FK({positionType:`shift`,positionData:d,children:[{type:`elem`,elem:c,marginLeft:v,marginRight:_}]});else if(s)u=Math.max(u,h,s.depth+.25*l.xHeight),b=FK({positionType:`shift`,positionData:-u,children:[{type:`elem`,elem:s,marginRight:_}]});else throw Error(`supsub must have either sup or sub.`);return X([oq(o,`right`)||`mord`],[o,X([`msupsub`],[b])],t)},mathmlBuilder(e,t){var n=!1,r,i;e.base&&e.base.type===`horizBrace`&&(i=!!e.sup,i===e.base.isOver&&(n=!0,r=e.base.isOver)),e.base&&(e.base.type===`op`||e.base.type===`operatorname`)&&(e.base.parentIsSupSub=!0);var a=[Cq(e.base,t)];e.sub&&a.push(Cq(e.sub,t)),e.sup&&a.push(Cq(e.sup,t));var o;if(n)o=r?`mover`:`munder`;else if(!e.sub){var s=e.base;o=s&&s.type===`op`&&s.limits&&(t.style===VW.DISPLAY||s.alwaysHandleSupSub)||s&&s.type===`operatorname`&&s.alwaysHandleSupSub&&(s.limits||t.style===VW.DISPLAY)?`mover`:`msup`}else if(e.sup){var c=e.base;o=c&&c.type===`op`&&c.limits&&t.style===VW.DISPLAY||c&&c.type===`operatorname`&&c.alwaysHandleSupSub&&(t.style===VW.DISPLAY||c.limits)?`munderover`:`msubsup`}else{var l=e.base;o=l&&l.type===`op`&&l.limits&&(t.style===VW.DISPLAY||l.alwaysHandleSupSub)||l&&l.type===`operatorname`&&l.alwaysHandleSupSub&&(l.limits||t.style===VW.DISPLAY)?`munder`:`msub`}return new Q(o,a)}}),YK({type:`atom`,htmlBuilder(e,t){return CK(e.text,e.mode,t,[`m`+e.family])},mathmlBuilder(e,t){var n=new Q(`mo`,[gq(e.text,e.mode)]);if(e.family===`bin`){var r=yq(e,t);r===`bold-italic`&&n.setAttribute(`mathvariant`,r)}else e.family===`punct`?n.setAttribute(`separator`,`true`):(e.family===`open`||e.family===`close`)&&n.setAttribute(`stretchy`,`false`);return n}});var MY={mi:`italic`,mn:`normal`,mtext:`normal`};YK({type:`mathord`,htmlBuilder(e,t){return TK(e,t)},mathmlBuilder(e,t){var n=new Q(`mi`,[gq(e.text,e.mode,t)]),r=yq(e,t)||`italic`;return r!==MY[n.type]&&n.setAttribute(`mathvariant`,r),n}}),YK({type:`textord`,htmlBuilder(e,t){return TK(e,t)},mathmlBuilder(e,t){var n=gq(e.text,e.mode,t),r=yq(e,t)||`normal`,i=e.mode===`text`?new Q(`mtext`,[n]):/[0-9]/.test(e.text)?new Q(`mn`,[n]):e.text===`\\prime`?new Q(`mo`,[n]):new Q(`mi`,[n]);return r!==MY[i.type]&&i.setAttribute(`mathvariant`,r),i}});var NY=new Map([[`\\nobreak`,`nobreak`],[`\\allowbreak`,`allowbreak`]]),PY=new Map([[` `,{}],[`\\ `,{}],[`~`,{className:`nobreak`}],[`\\space`,{}],[`\\nobreakspace`,{className:`nobreak`}]]);YK({type:`spacing`,htmlBuilder(e,t){var n=PY.get(e.text),r=NY.get(e.text);if(n){var i=n.className||``;if(e.mode===`text`){var a=TK(e,t);return a.classes.push(i),a}return X([`mspace`,i],[CK(e.text,e.mode,t)],t)}if(r)return X([`mspace`,r],[],t);throw new R(`Unknown type of space "`+e.text+`"`)},mathmlBuilder(e,t){var n;if(PY.has(e.text))n=new Q(`mtext`,[new fq(`\xA0`)]);else if(NY.has(e.text))return new Q(`mspace`);else throw new R(`Unknown type of space "`+e.text+`"`);return n}});var FY=()=>{var e=new Q(`mtd`,[]);return e.setAttribute(`width`,`50%`),e};YK({type:`tag`,mathmlBuilder(e,t){var n=new Q(`mtable`,[new Q(`mtr`,[FY(),new Q(`mtd`,[Sq(e.body,t)]),FY(),new Q(`mtd`,[Sq(e.tag,t)])])]);return n.setAttribute(`width`,`100%`),n}});var IY={"\\text":void 0,"\\textrm":`textrm`,"\\textsf":`textsf`,"\\texttt":`texttt`,"\\textnormal":`textrm`},LY={"\\textbf":`textbf`,"\\textmd":`textmd`},RY={"\\textit":`textit`,"\\textup":`textup`},zY=(e,t)=>{var n=e.font;return n?IY[n]?t.withTextFontFamily(IY[n]):LY[n]?t.withTextFontWeight(LY[n]):n===`\\emph`?t.fontShape===`textit`?t.withTextFontShape(`textup`):t.withTextFontShape(`textit`):t.withTextFontShape(RY[n]):t};Z({type:`text`,names:[`\\text`,`\\textrm`,`\\textsf`,`\\texttt`,`\\textnormal`,`\\textbf`,`\\textmd`,`\\textit`,`\\textup`,`\\emph`],numArgs:1,argTypes:[`text`],allowedInArgument:!0,allowedInText:!0,handler(e,t){var n=e.parser,r=e.funcName,i=t[0];return{type:`text`,mode:n.mode,body:ZK(i),font:r}},htmlBuilder(e,t){var n=zY(e,t);return X([`mord`,`text`],nq(e.body,n,!0),n)},mathmlBuilder(e,t){var n=zY(e,t);return Sq(e.body,n)}}),Z({type:`underline`,names:[`\\underline`],numArgs:1,allowedInText:!0,handler(e,t){return{type:`underline`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=cq(e.body,t),r=AK(`underline-line`,t),i=t.fontMetrics().defaultRuleThickness;return X([`mord`,`katex-underline`],[FK({positionType:`top`,positionData:n.height,children:[{type:`kern`,size:i},{type:`elem`,elem:r},{type:`kern`,size:3*i},{type:`elem`,elem:n}]})],t)},mathmlBuilder(e,t){var n=new Q(`mo`,[new fq(`‾`)]);n.setAttribute(`stretchy`,`true`);var r=new Q(`munder`,[Cq(e.body,t),n]);return r.setAttribute(`accentunder`,`true`),r}}),Z({type:`vcenter`,names:[`\\vcenter`],numArgs:1,argTypes:[`original`],allowedInText:!1,handler(e,t){return{type:`vcenter`,mode:e.parser.mode,body:t[0]}},htmlBuilder(e,t){var n=cq(e.body,t),r=t.fontMetrics().axisHeight;return FK({positionType:`shift`,positionData:.5*(n.height-r-(n.depth+r)),children:[{type:`elem`,elem:n}]})},mathmlBuilder(e,t){return new Q(`mrow`,[new Q(`mpadded`,[Cq(e.body,t)],[`vcenter`])])}}),Z({type:`verb`,names:[`\\verb`],numArgs:0,allowedInText:!0,handler(e,t,n){throw new R(`\\verb ended by end of line instead of matching delimiter`)},htmlBuilder(e,t){for(var n=BY(e),r=[],i=t.havingStyle(t.style.text()),a=0;ae.body.replace(/ /g,e.star?`␣`:`\xA0`),VY=KK,HY=`[ \r + ]`,UY=`\\\\[a-zA-Z@]+`,WY=`\\\\[^\ud800-\udfff]`,GY=`(`+UY+`)`+HY+`*`,KY=`\\\\( |[ \r ]+ -?)[ \r ]*`,gJ=`[̀-ͯ]`,_J=RegExp(gJ+`+$`),vJ=`(`+dJ+`+)|`+(hJ+`|`)+`([!-\\[\\]-‧‪-퟿豈-￿]`+(gJ+`*`)+`|[\ud800-\udbff][\udc00-\udfff]`+(gJ+`*`)+`|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5`+(`|`+mJ)+(`|`+pJ+`)`),yJ=class{constructor(e,t){this.input=void 0,this.settings=void 0,this.tokenRegex=void 0,this.catcodes=void 0,this.input=e,this.settings=t,this.tokenRegex=new RegExp(vJ,`g`),this.catcodes={"%":14,"~":13}}setCatcode(e,t){this.catcodes[e]=t}lex(){var e=this.input,t=this.tokenRegex.lastIndex;if(t===e.length)return new yq(`EOF`,new vq(this,t,t));var n=this.tokenRegex.exec(e);if(n===null||n.index!==t)throw new L(`Unexpected character: '`+e[t]+`'`,new yq(e[t],new vq(this,t,t+1)));var r=n[6]||n[3]||(n[2]?`\\ `:` `);if(this.catcodes[r]===14){var i=e.indexOf(` -`,this.tokenRegex.lastIndex);return i===-1?(this.tokenRegex.lastIndex=e.length,this.settings.reportNonstrict(`commentAtEnd`,`% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode (e.g. $)`)):this.tokenRegex.lastIndex=i+1,this.lex()}return new yq(r,new vq(this,t,this.tokenRegex.lastIndex))}},bJ=class{constructor(e,t){e===void 0&&(e={}),t===void 0&&(t={}),this.current=void 0,this.builtins=void 0,this.undefStack=void 0,this.current=t,this.builtins=e,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(this.undefStack.length===0)throw new L(`Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug`);var e=this.undefStack.pop();for(var t of Object.keys(e))e[t]===void 0?delete this.current[t]:this.current[t]=e[t]}endGroups(){for(;this.undefStack.length>0;)this.endGroup()}has(e){return Object.prototype.hasOwnProperty.call(this.current,e)||Object.prototype.hasOwnProperty.call(this.builtins,e)}get(e){if(Object.prototype.hasOwnProperty.call(this.current,e))return this.current[e];if(Object.prototype.hasOwnProperty.call(this.builtins,e))return this.builtins[e]}set(e,t,n){if(n===void 0&&(n=!1),n){for(var r=0;r0&&(this.undefStack[this.undefStack.length-1][e]=t)}else{var i=this.undefStack[this.undefStack.length-1];i&&!Object.prototype.hasOwnProperty.call(i,e)&&(i[e]=Object.prototype.hasOwnProperty.call(this.current,e)?this.current[e]:void 0)}t==null?delete this.current[e]:this.current[e]=t}},xJ=_q;$(`\\noexpand`,function(e){var t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}}),$(`\\expandafter`,function(e){var t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}}),$(`\\@firstoftwo`,function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}}),$(`\\@secondoftwo`,function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}}),$(`\\@ifnextchar`,function(e){var t=e.consumeArgs(3);e.consumeSpaces();var n=e.future();return t[0].length===1&&t[0][0].text===n.text?{tokens:t[1],numArgs:0}:{tokens:t[2],numArgs:0}}),$(`\\@ifstar`,`\\@ifnextchar *{\\@firstoftwo{#1}}`),$(`\\TextOrMath`,function(e){var t=e.consumeArgs(2);return e.mode===`text`?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}});var SJ={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};$(`\\char`,function(e){var t=e.popToken(),n,r=0;if(t.text===`'`)n=8,t=e.popToken();else if(t.text===`"`)n=16,t=e.popToken();else if(t.text==="`"){if(t=e.popToken(),t.text[0]===`\\`)r=t.text.charCodeAt(1);else if(t.text===`EOF`)throw new L("\\char` missing argument");else r=t.text.charCodeAt(0)}else n=10;if(n){if(r=SJ[t.text],r==null||r>=n)throw new L(`Invalid base-`+n+` digit `+t.text);for(var i;(i=SJ[e.future().text])!=null&&i{var i=e.consumeArg().tokens;if(i.length!==1)throw new L(`\\newcommand's first argument must be a macro name`);var a=i[0].text,o=e.isDefined(a);if(o&&!t)throw new L(`\\newcommand{`+a+`} attempting to redefine `+(a+`; use \\renewcommand`));if(!o&&!n)throw new L(`\\renewcommand{`+a+`} when command `+a+` does not yet exist; use \\newcommand`);var s=0;if(i=e.consumeArg().tokens,i.length===1&&i[0].text===`[`){for(var c=``,l=e.expandNextToken();l.text!==`]`&&l.text!==`EOF`;)c+=l.text,l=e.expandNextToken();if(!c.match(/^\s*[0-9]+\s*$/))throw new L(`Invalid number of arguments: `+c);s=parseInt(c),i=e.consumeArg().tokens}return o&&r||e.macros.set(a,{tokens:i,numArgs:s}),``};$(`\\newcommand`,e=>CJ(e,!1,!0,!1)),$(`\\renewcommand`,e=>CJ(e,!0,!1,!1)),$(`\\providecommand`,e=>CJ(e,!0,!0,!0)),$(`\\message`,e=>{var t=e.consumeArgs(1)[0];return console.log(t.reverse().map(e=>e.text).join(``)),``}),$(`\\errmessage`,e=>{var t=e.consumeArgs(1)[0];return console.error(t.reverse().map(e=>e.text).join(``)),``}),$(`\\show`,e=>{var t=e.popToken(),n=t.text;return console.log(t,e.macros.get(n),uJ[n],iW.math[n],iW.text[n]),``}),$(`\\bgroup`,`{`),$(`\\egroup`,`}`),$(`~`,`\\nobreakspace`),$(`\\lq`,"`"),$(`\\rq`,`'`),$(`\\aa`,`\\r a`),$(`\\AA`,`\\r A`),$(`\\textcopyright`,"\\html@mathml{\\textcircled{c}}{\\char`©}"),$(`\\copyright`,`\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}`),$(`\\textregistered`,"\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"),$(`ℬ`,`\\mathscr{B}`),$(`ℰ`,`\\mathscr{E}`),$(`ℱ`,`\\mathscr{F}`),$(`ℋ`,`\\mathscr{H}`),$(`ℐ`,`\\mathscr{I}`),$(`ℒ`,`\\mathscr{L}`),$(`ℳ`,`\\mathscr{M}`),$(`ℛ`,`\\mathscr{R}`),$(`ℭ`,`\\mathfrak{C}`),$(`ℌ`,`\\mathfrak{H}`),$(`ℨ`,`\\mathfrak{Z}`),$(`\\Bbbk`,`\\Bbb{k}`),$(`\\llap`,`\\mathllap{\\textrm{#1}}`),$(`\\rlap`,`\\mathrlap{\\textrm{#1}}`),$(`\\clap`,`\\mathclap{\\textrm{#1}}`),$(`\\mathstrut`,`\\vphantom{(}`),$(`\\underbar`,`\\underline{\\text{#1}}`),$(`\\not`,`\\html@mathml{\\mathrel{\\mathrlap\\@not}\\nobreak}{\\char"338}`),$(`\\neq`,"\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}"),$(`\\ne`,`\\neq`),$(`≠`,`\\neq`),$(`\\notin`,"\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}{\\mathrel{\\char`∉}}"),$(`∉`,`\\notin`),$(`≘`,"\\html@mathml{\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}}{\\mathrel{\\char`≘}}"),$(`≙`,"\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`≘}}"),$(`≚`,"\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`≚}}"),$(`≛`,"\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}{\\mathrel{\\char`≛}}"),$(`≝`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}{\\mathrel{\\char`≝}}"),$(`≞`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}{\\mathrel{\\char`≞}}"),$(`≟`,"\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`≟}}"),$(`⟂`,`\\perp`),$(`‼`,`\\mathclose{!\\mkern-0.8mu!}`),$(`∌`,`\\notni`),$(`⌜`,`\\ulcorner`),$(`⌝`,`\\urcorner`),$(`⌞`,`\\llcorner`),$(`⌟`,`\\lrcorner`),$(`©`,`\\copyright`),$(`®`,`\\textregistered`),$(`\\ulcorner`,`\\html@mathml{\\@ulcorner}{\\mathop{\\char"231c}}`),$(`\\urcorner`,`\\html@mathml{\\@urcorner}{\\mathop{\\char"231d}}`),$(`\\llcorner`,`\\html@mathml{\\@llcorner}{\\mathop{\\char"231e}}`),$(`\\lrcorner`,`\\html@mathml{\\@lrcorner}{\\mathop{\\char"231f}}`),$(`\\vdots`,`{\\varvdots\\rule{0pt}{15pt}}`),$(`⋮`,`\\vdots`),$(`\\varGamma`,`\\mathit{\\Gamma}`),$(`\\varDelta`,`\\mathit{\\Delta}`),$(`\\varTheta`,`\\mathit{\\Theta}`),$(`\\varLambda`,`\\mathit{\\Lambda}`),$(`\\varXi`,`\\mathit{\\Xi}`),$(`\\varPi`,`\\mathit{\\Pi}`),$(`\\varSigma`,`\\mathit{\\Sigma}`),$(`\\varUpsilon`,`\\mathit{\\Upsilon}`),$(`\\varPhi`,`\\mathit{\\Phi}`),$(`\\varPsi`,`\\mathit{\\Psi}`),$(`\\varOmega`,`\\mathit{\\Omega}`),$(`\\substack`,`\\begin{subarray}{c}#1\\end{subarray}`),$(`\\colon`,`\\nobreak\\mskip2mu\\mathpunct{}\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax`),$(`\\boxed`,`\\fbox{$\\displaystyle{#1}$}`),$(`\\iff`,`\\DOTSB\\;\\Longleftrightarrow\\;`),$(`\\implies`,`\\DOTSB\\;\\Longrightarrow\\;`),$(`\\impliedby`,`\\DOTSB\\;\\Longleftarrow\\;`),$(`\\dddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ...}}{#1}}`),$(`\\ddddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ....}}{#1}}`);var wJ={",":`\\dotsc`,"\\not":`\\dotsb`,"+":`\\dotsb`,"=":`\\dotsb`,"<":`\\dotsb`,">":`\\dotsb`,"-":`\\dotsb`,"*":`\\dotsb`,":":`\\dotsb`,"\\DOTSB":`\\dotsb`,"\\coprod":`\\dotsb`,"\\bigvee":`\\dotsb`,"\\bigwedge":`\\dotsb`,"\\biguplus":`\\dotsb`,"\\bigcap":`\\dotsb`,"\\bigcup":`\\dotsb`,"\\prod":`\\dotsb`,"\\sum":`\\dotsb`,"\\bigotimes":`\\dotsb`,"\\bigoplus":`\\dotsb`,"\\bigodot":`\\dotsb`,"\\bigsqcup":`\\dotsb`,"\\And":`\\dotsb`,"\\longrightarrow":`\\dotsb`,"\\Longrightarrow":`\\dotsb`,"\\longleftarrow":`\\dotsb`,"\\Longleftarrow":`\\dotsb`,"\\longleftrightarrow":`\\dotsb`,"\\Longleftrightarrow":`\\dotsb`,"\\mapsto":`\\dotsb`,"\\longmapsto":`\\dotsb`,"\\hookrightarrow":`\\dotsb`,"\\doteq":`\\dotsb`,"\\mathbin":`\\dotsb`,"\\mathrel":`\\dotsb`,"\\relbar":`\\dotsb`,"\\Relbar":`\\dotsb`,"\\xrightarrow":`\\dotsb`,"\\xleftarrow":`\\dotsb`,"\\DOTSI":`\\dotsi`,"\\int":`\\dotsi`,"\\oint":`\\dotsi`,"\\iint":`\\dotsi`,"\\iiint":`\\dotsi`,"\\iiiint":`\\dotsi`,"\\idotsint":`\\dotsi`,"\\DOTSX":`\\dotsx`},TJ=new Set([`bin`,`rel`]);$(`\\dots`,function(e){var t=`\\dotso`,n=e.expandAfterFuture().text;return n in wJ?t=wJ[n]:(n.slice(0,4)===`\\not`||n in iW.math&&TJ.has(iW.math[n].group))&&(t=`\\dotsb`),t});var EJ={")":!0,"]":!0,"\\rbrack":!0,"\\}":!0,"\\rbrace":!0,"\\rangle":!0,"\\rceil":!0,"\\rfloor":!0,"\\rgroup":!0,"\\rmoustache":!0,"\\right":!0,"\\bigr":!0,"\\biggr":!0,"\\Bigr":!0,"\\Biggr":!0,$:!0,";":!0,".":!0,",":!0};$(`\\dotso`,function(e){return e.future().text in EJ?`\\ldots\\,`:`\\ldots`}),$(`\\dotsc`,function(e){var t=e.future().text;return t in EJ&&t!==`,`?`\\ldots\\,`:`\\ldots`}),$(`\\cdots`,function(e){return e.future().text in EJ?`\\@cdots\\,`:`\\@cdots`}),$(`\\dotsb`,`\\cdots`),$(`\\dotsm`,`\\cdots`),$(`\\dotsi`,`\\!\\cdots`),$(`\\dotsx`,`\\ldots\\,`),$(`\\DOTSI`,`\\relax`),$(`\\DOTSB`,`\\relax`),$(`\\DOTSX`,`\\relax`),$(`\\tmspace`,`\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax`),$(`\\,`,`\\tmspace+{3mu}{.1667em}`),$(`\\thinspace`,`\\,`),$(`\\>`,`\\mskip{4mu}`),$(`\\:`,`\\tmspace+{4mu}{.2222em}`),$(`\\medspace`,`\\:`),$(`\\;`,`\\tmspace+{5mu}{.2777em}`),$(`\\thickspace`,`\\;`),$(`\\!`,`\\tmspace-{3mu}{.1667em}`),$(`\\negthinspace`,`\\!`),$(`\\negmedspace`,`\\tmspace-{4mu}{.2222em}`),$(`\\negthickspace`,`\\tmspace-{5mu}{.277em}`),$(`\\enspace`,`\\kern.5em `),$(`\\enskip`,`\\hskip.5em\\relax`),$(`\\quad`,`\\hskip1em\\relax`),$(`\\qquad`,`\\hskip2em\\relax`),$(`\\tag`,`\\@ifstar\\tag@literal\\tag@paren`),$(`\\tag@paren`,`\\tag@literal{({#1})}`),$(`\\tag@literal`,e=>{if(e.macros.get(`\\df@tag`))throw new L(`Multiple \\tag`);return`\\gdef\\df@tag{\\text{#1}}`}),$(`\\bmod`,`\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}\\mathbin{\\rm mod}\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}`),$(`\\pod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)`),$(`\\pmod`,`\\pod{{\\rm mod}\\mkern6mu#1}`),$(`\\mod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1`),$(`\\newline`,`\\\\\\relax`),$(`\\TeX`,`\\textrm{\\html@mathml{T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX}{TeX}}`);var DJ=z(ZU[`Main-Regular`][84][1]-.7*ZU[`Main-Regular`][65][1]);$(`\\LaTeX`,`\\textrm{\\html@mathml{`+(`L\\kern-.36em\\raisebox{`+DJ+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{LaTeX}}`),$(`\\KaTeX`,`\\textrm{\\html@mathml{`+(`K\\kern-.17em\\raisebox{`+DJ+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{KaTeX}}`),$(`\\hspace`,`\\@ifstar\\@hspacer\\@hspace`),$(`\\@hspace`,`\\hskip #1\\relax`),$(`\\@hspacer`,`\\rule{0pt}{0pt}\\hskip #1\\relax`),$(`\\ordinarycolon`,`:`),$(`\\vcentcolon`,`\\mathrel{\\mathop\\ordinarycolon}`),$(`\\dblcolon`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}{\\mathop{\\char"2237}}`),$(`\\coloneqq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2254}}`),$(`\\Coloneqq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2237\\char"3d}}`),$(`\\coloneq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"3a\\char"2212}}`),$(`\\Coloneq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"2237\\char"2212}}`),$(`\\eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2255}}`),$(`\\Eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"3d\\char"2237}}`),$(`\\eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2239}}`),$(`\\Eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"2212\\char"2237}}`),$(`\\colonapprox`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"3a\\char"2248}}`),$(`\\Colonapprox`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"2237\\char"2248}}`),$(`\\colonsim`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"3a\\char"223c}}`),$(`\\Colonsim`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"2237\\char"223c}}`),$(`∷`,`\\dblcolon`),$(`∹`,`\\eqcolon`),$(`≔`,`\\coloneqq`),$(`≕`,`\\eqqcolon`),$(`⩴`,`\\Coloneqq`),$(`\\ratio`,`\\vcentcolon`),$(`\\coloncolon`,`\\dblcolon`),$(`\\colonequals`,`\\coloneqq`),$(`\\coloncolonequals`,`\\Coloneqq`),$(`\\equalscolon`,`\\eqqcolon`),$(`\\equalscoloncolon`,`\\Eqqcolon`),$(`\\colonminus`,`\\coloneq`),$(`\\coloncolonminus`,`\\Coloneq`),$(`\\minuscolon`,`\\eqcolon`),$(`\\minuscoloncolon`,`\\Eqcolon`),$(`\\coloncolonapprox`,`\\Colonapprox`),$(`\\coloncolonsim`,`\\Colonsim`),$(`\\simcolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\simcoloncolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\approxcolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\approxcoloncolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\notni`,"\\html@mathml{\\not\\ni}{\\mathrel{\\char`∌}}"),$(`\\limsup`,`\\DOTSB\\operatorname*{lim\\,sup}`),$(`\\liminf`,`\\DOTSB\\operatorname*{lim\\,inf}`),$(`\\injlim`,`\\DOTSB\\operatorname*{inj\\,lim}`),$(`\\projlim`,`\\DOTSB\\operatorname*{proj\\,lim}`),$(`\\varlimsup`,`\\DOTSB\\operatorname*{\\overline{lim}}`),$(`\\varliminf`,`\\DOTSB\\operatorname*{\\underline{lim}}`),$(`\\varinjlim`,`\\DOTSB\\operatorname*{\\underrightarrow{lim}}`),$(`\\varprojlim`,`\\DOTSB\\operatorname*{\\underleftarrow{lim}}`),$(`\\gvertneqq`,`\\html@mathml{\\@gvertneqq}{≩}`),$(`\\lvertneqq`,`\\html@mathml{\\@lvertneqq}{≨}`),$(`\\ngeqq`,`\\html@mathml{\\@ngeqq}{≱}`),$(`\\ngeqslant`,`\\html@mathml{\\@ngeqslant}{≱}`),$(`\\nleqq`,`\\html@mathml{\\@nleqq}{≰}`),$(`\\nleqslant`,`\\html@mathml{\\@nleqslant}{≰}`),$(`\\nshortmid`,`\\html@mathml{\\@nshortmid}{∤}`),$(`\\nshortparallel`,`\\html@mathml{\\@nshortparallel}{∦}`),$(`\\nsubseteqq`,`\\html@mathml{\\@nsubseteqq}{⊈}`),$(`\\nsupseteqq`,`\\html@mathml{\\@nsupseteqq}{⊉}`),$(`\\varsubsetneq`,`\\html@mathml{\\@varsubsetneq}{⊊}`),$(`\\varsubsetneqq`,`\\html@mathml{\\@varsubsetneqq}{⫋}`),$(`\\varsupsetneq`,`\\html@mathml{\\@varsupsetneq}{⊋}`),$(`\\varsupsetneqq`,`\\html@mathml{\\@varsupsetneqq}{⫌}`),$(`\\imath`,`\\html@mathml{\\@imath}{ı}`),$(`\\jmath`,`\\html@mathml{\\@jmath}{ȷ}`),$(`\\llbracket`,"\\html@mathml{\\mathopen{[\\mkern-3.2mu[}}{\\mathopen{\\char`⟦}}"),$(`\\rrbracket`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu]}}{\\mathclose{\\char`⟧}}"),$(`⟦`,`\\llbracket`),$(`⟧`,`\\rrbracket`),$(`\\lBrace`,"\\html@mathml{\\mathopen{\\{\\mkern-3.2mu[}}{\\mathopen{\\char`⦃}}"),$(`\\rBrace`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu\\}}}{\\mathclose{\\char`⦄}}"),$(`↤`,`\\mapsfrom`),$(`\\mapsfrom`,"\\html@mathml{\\mathrel{\\mathreflectbox{\\mapsto}}}{\\mathrel{\\char`↤}}"),$(`⦃`,`\\lBrace`),$(`⦄`,`\\rBrace`),$(`\\minuso`,"\\mathbin{\\html@mathml{{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}{\\char`⦵}}"),$(`⦵`,`\\minuso`),$(`\\darr`,`\\downarrow`),$(`\\dArr`,`\\Downarrow`),$(`\\Darr`,`\\Downarrow`),$(`\\lang`,`\\langle`),$(`\\rang`,`\\rangle`),$(`\\uarr`,`\\uparrow`),$(`\\uArr`,`\\Uparrow`),$(`\\Uarr`,`\\Uparrow`),$(`\\N`,`\\mathbb{N}`),$(`\\R`,`\\mathbb{R}`),$(`\\Z`,`\\mathbb{Z}`),$(`\\alef`,`\\aleph`),$(`\\alefsym`,`\\aleph`),$(`\\Alpha`,`\\mathrm{A}`),$(`\\Beta`,`\\mathrm{B}`),$(`\\bull`,`\\bullet`),$(`\\Chi`,`\\mathrm{X}`),$(`\\clubs`,`\\clubsuit`),$(`\\cnums`,`\\mathbb{C}`),$(`\\Complex`,`\\mathbb{C}`),$(`\\Dagger`,`\\ddagger`),$(`\\diamonds`,`\\diamondsuit`),$(`\\empty`,`\\emptyset`),$(`\\Epsilon`,`\\mathrm{E}`),$(`\\Eta`,`\\mathrm{H}`),$(`\\exist`,`\\exists`),$(`\\harr`,`\\leftrightarrow`),$(`\\hArr`,`\\Leftrightarrow`),$(`\\Harr`,`\\Leftrightarrow`),$(`\\hearts`,`\\heartsuit`),$(`\\image`,`\\Im`),$(`\\infin`,`\\infty`),$(`\\Iota`,`\\mathrm{I}`),$(`\\isin`,`\\in`),$(`\\Kappa`,`\\mathrm{K}`),$(`\\larr`,`\\leftarrow`),$(`\\lArr`,`\\Leftarrow`),$(`\\Larr`,`\\Leftarrow`),$(`\\lrarr`,`\\leftrightarrow`),$(`\\lrArr`,`\\Leftrightarrow`),$(`\\Lrarr`,`\\Leftrightarrow`),$(`\\Mu`,`\\mathrm{M}`),$(`\\natnums`,`\\mathbb{N}`),$(`\\Nu`,`\\mathrm{N}`),$(`\\Omicron`,`\\mathrm{O}`),$(`\\plusmn`,`\\pm`),$(`\\rarr`,`\\rightarrow`),$(`\\rArr`,`\\Rightarrow`),$(`\\Rarr`,`\\Rightarrow`),$(`\\real`,`\\Re`),$(`\\reals`,`\\mathbb{R}`),$(`\\Reals`,`\\mathbb{R}`),$(`\\Rho`,`\\mathrm{P}`),$(`\\sdot`,`\\cdot`),$(`\\sect`,`\\S`),$(`\\spades`,`\\spadesuit`),$(`\\sub`,`\\subset`),$(`\\sube`,`\\subseteq`),$(`\\supe`,`\\supseteq`),$(`\\Tau`,`\\mathrm{T}`),$(`\\thetasym`,`\\vartheta`),$(`\\weierp`,`\\wp`),$(`\\Zeta`,`\\mathrm{Z}`),$(`\\argmin`,`\\DOTSB\\operatorname*{arg\\,min}`),$(`\\argmax`,`\\DOTSB\\operatorname*{arg\\,max}`),$(`\\plim`,`\\DOTSB\\mathop{\\operatorname{plim}}\\limits`),$(`\\bra`,`\\mathinner{\\langle{#1}|}`),$(`\\ket`,`\\mathinner{|{#1}\\rangle}`),$(`\\braket`,`\\mathinner{\\langle{#1}\\rangle}`),$(`\\Bra`,`\\left\\langle#1\\right|`),$(`\\Ket`,`\\left|#1\\right\\rangle`);var OJ=e=>t=>{var n=t.consumeArg().tokens,r=t.consumeArg().tokens,i=t.consumeArg().tokens,a=t.consumeArg().tokens,o=t.macros.get(`|`),s=t.macros.get(`\\|`);t.macros.beginGroup();var c=t=>n=>{e&&(n.macros.set(`|`,o),i.length&&n.macros.set(`\\|`,s));var a=t;return!t&&i.length&&n.future().text===`|`&&(n.popToken(),a=!0),{tokens:a?i:r,numArgs:0}};t.macros.set(`|`,c(!1)),i.length&&t.macros.set(`\\|`,c(!0));var l=t.consumeArg().tokens,u=t.expandTokens([...a,...l,...n]);return t.macros.endGroup(),{tokens:u.reverse(),numArgs:0}};$(`\\bra@ket`,OJ(!1)),$(`\\bra@set`,OJ(!0)),$(`\\Braket`,`\\bra@ket{\\left\\langle}{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}`),$(`\\Set`,`\\bra@set{\\left\\{\\:}{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}`),$(`\\set`,`\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}`),$(`\\angln`,`{\\angl n}`),$(`\\blue`,`\\textcolor{##6495ed}{#1}`),$(`\\orange`,`\\textcolor{##ffa500}{#1}`),$(`\\pink`,`\\textcolor{##ff00af}{#1}`),$(`\\red`,`\\textcolor{##df0030}{#1}`),$(`\\green`,`\\textcolor{##28ae7b}{#1}`),$(`\\gray`,`\\textcolor{gray}{#1}`),$(`\\purple`,`\\textcolor{##9d38bd}{#1}`),$(`\\blueA`,`\\textcolor{##ccfaff}{#1}`),$(`\\blueB`,`\\textcolor{##80f6ff}{#1}`),$(`\\blueC`,`\\textcolor{##63d9ea}{#1}`),$(`\\blueD`,`\\textcolor{##11accd}{#1}`),$(`\\blueE`,`\\textcolor{##0c7f99}{#1}`),$(`\\tealA`,`\\textcolor{##94fff5}{#1}`),$(`\\tealB`,`\\textcolor{##26edd5}{#1}`),$(`\\tealC`,`\\textcolor{##01d1c1}{#1}`),$(`\\tealD`,`\\textcolor{##01a995}{#1}`),$(`\\tealE`,`\\textcolor{##208170}{#1}`),$(`\\greenA`,`\\textcolor{##b6ffb0}{#1}`),$(`\\greenB`,`\\textcolor{##8af281}{#1}`),$(`\\greenC`,`\\textcolor{##74cf70}{#1}`),$(`\\greenD`,`\\textcolor{##1fab54}{#1}`),$(`\\greenE`,`\\textcolor{##0d923f}{#1}`),$(`\\goldA`,`\\textcolor{##ffd0a9}{#1}`),$(`\\goldB`,`\\textcolor{##ffbb71}{#1}`),$(`\\goldC`,`\\textcolor{##ff9c39}{#1}`),$(`\\goldD`,`\\textcolor{##e07d10}{#1}`),$(`\\goldE`,`\\textcolor{##a75a05}{#1}`),$(`\\redA`,`\\textcolor{##fca9a9}{#1}`),$(`\\redB`,`\\textcolor{##ff8482}{#1}`),$(`\\redC`,`\\textcolor{##f9685d}{#1}`),$(`\\redD`,`\\textcolor{##e84d39}{#1}`),$(`\\redE`,`\\textcolor{##bc2612}{#1}`),$(`\\maroonA`,`\\textcolor{##ffbde0}{#1}`),$(`\\maroonB`,`\\textcolor{##ff92c6}{#1}`),$(`\\maroonC`,`\\textcolor{##ed5fa6}{#1}`),$(`\\maroonD`,`\\textcolor{##ca337c}{#1}`),$(`\\maroonE`,`\\textcolor{##9e034e}{#1}`),$(`\\purpleA`,`\\textcolor{##ddd7ff}{#1}`),$(`\\purpleB`,`\\textcolor{##c6b9fc}{#1}`),$(`\\purpleC`,`\\textcolor{##aa87ff}{#1}`),$(`\\purpleD`,`\\textcolor{##7854ab}{#1}`),$(`\\purpleE`,`\\textcolor{##543b78}{#1}`),$(`\\mintA`,`\\textcolor{##f5f9e8}{#1}`),$(`\\mintB`,`\\textcolor{##edf2df}{#1}`),$(`\\mintC`,`\\textcolor{##e0e5cc}{#1}`),$(`\\grayA`,`\\textcolor{##f6f7f7}{#1}`),$(`\\grayB`,`\\textcolor{##f0f1f2}{#1}`),$(`\\grayC`,`\\textcolor{##e3e5e6}{#1}`),$(`\\grayD`,`\\textcolor{##d6d8da}{#1}`),$(`\\grayE`,`\\textcolor{##babec2}{#1}`),$(`\\grayF`,`\\textcolor{##888d93}{#1}`),$(`\\grayG`,`\\textcolor{##626569}{#1}`),$(`\\grayH`,`\\textcolor{##3b3e40}{#1}`),$(`\\grayI`,`\\textcolor{##21242c}{#1}`),$(`\\kaBlue`,`\\textcolor{##314453}{#1}`),$(`\\kaGreen`,`\\textcolor{##71B307}{#1}`);var kJ={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0},AJ=class{constructor(e,t,n){this.settings=void 0,this.expansionCount=void 0,this.lexer=void 0,this.macros=void 0,this.stack=void 0,this.mode=void 0,this.settings=t,this.expansionCount=0,this.feed(e),this.macros=new bJ(xJ,t.macros),this.mode=n,this.stack=[]}feed(e){this.lexer=new yJ(e,this.settings)}switchMode(e){this.mode=e}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}endGroups(){this.macros.endGroups()}future(){return this.stack.length===0&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(e){this.stack.push(e)}pushTokens(e){this.stack.push(...e)}scanArgument(e){var t,n,r;if(e){if(this.consumeSpaces(),this.future().text!==`[`)return null;t=this.popToken();var i=this.consumeArg([`]`]);r=i.tokens,n=i.end}else{var a=this.consumeArg();r=a.tokens,t=a.start,n=a.end}return this.pushToken(new yq(`EOF`,n.loc)),this.pushTokens(r),new yq(``,vq.range(t,n))}consumeSpaces(){for(;this.future().text===` `;)this.stack.pop()}consumeArg(e){var t=[],n=e&&e.length>0;n||this.consumeSpaces();var r=this.future(),i,a=0,o=0;do{if(i=this.popToken(),t.push(i),i.text===`{`)++a;else if(i.text===`}`){if(--a,a===-1)throw new L(`Extra }`,i)}else if(i.text===`EOF`)throw new L(`Unexpected end of input in a macro argument, expected '`+(e&&n?e[o]:`}`)+`'`,i);if(e&&n){if((a===0||a===1&&e[o]===`{`)&&i.text===e[o]){if(++o,o===e.length){t.splice(-o,o);break}}else o=0}}while(a!==0||n);return r.text===`{`&&t[t.length-1].text===`}`&&(t.pop(),t.shift()),t.reverse(),{tokens:t,start:r,end:i}}consumeArgs(e,t){if(t){if(t.length!==e+1)throw new L(`The length of delimiters doesn't match the number of args!`);for(var n=t[0],r=0;rthis.settings.maxExpand)throw new L(`Too many expansions: infinite loop or need to increase maxExpand setting`)}expandOnce(e){var t=this.popToken(),n=t.text,r=t.noexpand?null:this._getExpansion(n);if(r==null||e&&r.unexpandable){if(e&&r==null&&n[0]===`\\`&&!this.isDefined(n))throw new L(`Undefined control sequence: `+n);return this.pushToken(t),!1}this.countExpansion(1);var i=r.tokens,a=this.consumeArgs(r.numArgs,r.delimiters);if(r.numArgs){i=i.slice();for(var o=i.length-1;o>=0;--o){var s=i[o];if(s.text===`#`){if(o===0)throw new L(`Incomplete placeholder at end of macro body`,s);if(s=i[--o],s.text===`#`)i.splice(o+1,1);else if(/^[1-9]$/.test(s.text))i.splice(o,2,...a[s.text-1]);else throw new L(`Not a valid argument number`,s)}}}return this.pushTokens(i),i.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(this.expandOnce()===!1){var e=this.stack.pop();return e.treatAsRelax&&(e.text=`\\relax`),e}}expandMacro(e){return this.macros.has(e)?this.expandTokens([new yq(e)]):void 0}expandTokens(e){var t=[],n=this.stack.length;for(this.pushTokens(e);this.stack.length>n;)if(this.expandOnce(!0)===!1){var r=this.stack.pop();r.treatAsRelax&&=(r.noexpand=!1,!1),t.push(r)}return this.countExpansion(t.length),t}expandMacroAsText(e){var t=this.expandMacro(e);return t&&t.map(e=>e.text).join(``)}_getExpansion(e){var t=this.macros.get(e);if(t==null)return t;if(e.length===1){var n=this.lexer.catcodes[e];if(n!=null&&n!==13)return}var r=typeof t==`function`?t(this):t;if(typeof r==`string`){var i=0;if(r.includes(`#`))for(var a=r.replace(/##/g,``);a.includes(`#`+(i+1));)++i;for(var o=new yJ(r,this.settings),s=[],c=o.lex();c.text!==`EOF`;)s.push(c),c=o.lex();return s.reverse(),{tokens:s,numArgs:i}}return r}isDefined(e){return this.macros.has(e)||Object.prototype.hasOwnProperty.call(uJ,e)||Object.prototype.hasOwnProperty.call(iW.math,e)||Object.prototype.hasOwnProperty.call(iW.text,e)||Object.prototype.hasOwnProperty.call(kJ,e)}isExpandable(e){var t=this.macros.get(e);return t==null?Object.prototype.hasOwnProperty.call(uJ,e)&&!uJ[e].primitive:typeof t==`string`||typeof t==`function`||!t.unexpandable}},jJ=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,MJ=Object.freeze({"₊":`+`,"₋":`-`,"₌":`=`,"₍":`(`,"₎":`)`,"₀":`0`,"₁":`1`,"₂":`2`,"₃":`3`,"₄":`4`,"₅":`5`,"₆":`6`,"₇":`7`,"₈":`8`,"₉":`9`,ₐ:`a`,ₑ:`e`,ₕ:`h`,ᵢ:`i`,ⱼ:`j`,ₖ:`k`,ₗ:`l`,ₘ:`m`,ₙ:`n`,ₒ:`o`,ₚ:`p`,ᵣ:`r`,ₛ:`s`,ₜ:`t`,ᵤ:`u`,ᵥ:`v`,ₓ:`x`,ᵦ:`β`,ᵧ:`γ`,ᵨ:`ρ`,ᵩ:`ϕ`,ᵪ:`χ`,"⁺":`+`,"⁻":`-`,"⁼":`=`,"⁽":`(`,"⁾":`)`,"⁰":`0`,"¹":`1`,"²":`2`,"³":`3`,"⁴":`4`,"⁵":`5`,"⁶":`6`,"⁷":`7`,"⁸":`8`,"⁹":`9`,ᴬ:`A`,ᴮ:`B`,ᴰ:`D`,ᴱ:`E`,ᴳ:`G`,ᴴ:`H`,ᴵ:`I`,ᴶ:`J`,ᴷ:`K`,ᴸ:`L`,ᴹ:`M`,ᴺ:`N`,ᴼ:`O`,ᴾ:`P`,ᴿ:`R`,ᵀ:`T`,ᵁ:`U`,ⱽ:`V`,ᵂ:`W`,ᵃ:`a`,ᵇ:`b`,ᶜ:`c`,ᵈ:`d`,ᵉ:`e`,ᶠ:`f`,ᵍ:`g`,ʰ:`h`,ⁱ:`i`,ʲ:`j`,ᵏ:`k`,ˡ:`l`,ᵐ:`m`,ⁿ:`n`,ᵒ:`o`,ᵖ:`p`,ʳ:`r`,ˢ:`s`,ᵗ:`t`,ᵘ:`u`,ᵛ:`v`,ʷ:`w`,ˣ:`x`,ʸ:`y`,ᶻ:`z`,ᵝ:`β`,ᵞ:`γ`,ᵟ:`δ`,ᵠ:`ϕ`,ᵡ:`χ`,ᶿ:`θ`}),NJ={"́":{text:`\\'`,math:`\\acute`},"̀":{text:"\\`",math:`\\grave`},"̈":{text:`\\"`,math:`\\ddot`},"̃":{text:`\\~`,math:`\\tilde`},"̄":{text:`\\=`,math:`\\bar`},"̆":{text:`\\u`,math:`\\breve`},"̌":{text:`\\v`,math:`\\check`},"̂":{text:`\\^`,math:`\\hat`},"̇":{text:`\\.`,math:`\\dot`},"̊":{text:`\\r`,math:`\\mathring`},"̋":{text:`\\H`},"̧":{text:`\\c`}},PJ={á:`á`,à:`à`,ä:`ä`,ǟ:`ǟ`,ã:`ã`,ā:`ā`,ă:`ă`,ắ:`ắ`,ằ:`ằ`,ẵ:`ẵ`,ǎ:`ǎ`,â:`â`,ấ:`ấ`,ầ:`ầ`,ẫ:`ẫ`,ȧ:`ȧ`,ǡ:`ǡ`,å:`å`,ǻ:`ǻ`,ḃ:`ḃ`,ć:`ć`,ḉ:`ḉ`,č:`č`,ĉ:`ĉ`,ċ:`ċ`,ç:`ç`,ď:`ď`,ḋ:`ḋ`,ḑ:`ḑ`,é:`é`,è:`è`,ë:`ë`,ẽ:`ẽ`,ē:`ē`,ḗ:`ḗ`,ḕ:`ḕ`,ĕ:`ĕ`,ḝ:`ḝ`,ě:`ě`,ê:`ê`,ế:`ế`,ề:`ề`,ễ:`ễ`,ė:`ė`,ȩ:`ȩ`,ḟ:`ḟ`,ǵ:`ǵ`,ḡ:`ḡ`,ğ:`ğ`,ǧ:`ǧ`,ĝ:`ĝ`,ġ:`ġ`,ģ:`ģ`,ḧ:`ḧ`,ȟ:`ȟ`,ĥ:`ĥ`,ḣ:`ḣ`,ḩ:`ḩ`,í:`í`,ì:`ì`,ï:`ï`,ḯ:`ḯ`,ĩ:`ĩ`,ī:`ī`,ĭ:`ĭ`,ǐ:`ǐ`,î:`î`,ǰ:`ǰ`,ĵ:`ĵ`,ḱ:`ḱ`,ǩ:`ǩ`,ķ:`ķ`,ĺ:`ĺ`,ľ:`ľ`,ļ:`ļ`,ḿ:`ḿ`,ṁ:`ṁ`,ń:`ń`,ǹ:`ǹ`,ñ:`ñ`,ň:`ň`,ṅ:`ṅ`,ņ:`ņ`,ó:`ó`,ò:`ò`,ö:`ö`,ȫ:`ȫ`,õ:`õ`,ṍ:`ṍ`,ṏ:`ṏ`,ȭ:`ȭ`,ō:`ō`,ṓ:`ṓ`,ṑ:`ṑ`,ŏ:`ŏ`,ǒ:`ǒ`,ô:`ô`,ố:`ố`,ồ:`ồ`,ỗ:`ỗ`,ȯ:`ȯ`,ȱ:`ȱ`,ő:`ő`,ṕ:`ṕ`,ṗ:`ṗ`,ŕ:`ŕ`,ř:`ř`,ṙ:`ṙ`,ŗ:`ŗ`,ś:`ś`,ṥ:`ṥ`,š:`š`,ṧ:`ṧ`,ŝ:`ŝ`,ṡ:`ṡ`,ş:`ş`,ẗ:`ẗ`,ť:`ť`,ṫ:`ṫ`,ţ:`ţ`,ú:`ú`,ù:`ù`,ü:`ü`,ǘ:`ǘ`,ǜ:`ǜ`,ǖ:`ǖ`,ǚ:`ǚ`,ũ:`ũ`,ṹ:`ṹ`,ū:`ū`,ṻ:`ṻ`,ŭ:`ŭ`,ǔ:`ǔ`,û:`û`,ů:`ů`,ű:`ű`,ṽ:`ṽ`,ẃ:`ẃ`,ẁ:`ẁ`,ẅ:`ẅ`,ŵ:`ŵ`,ẇ:`ẇ`,ẘ:`ẘ`,ẍ:`ẍ`,ẋ:`ẋ`,ý:`ý`,ỳ:`ỳ`,ÿ:`ÿ`,ỹ:`ỹ`,ȳ:`ȳ`,ŷ:`ŷ`,ẏ:`ẏ`,ẙ:`ẙ`,ź:`ź`,ž:`ž`,ẑ:`ẑ`,ż:`ż`,Á:`Á`,À:`À`,Ä:`Ä`,Ǟ:`Ǟ`,Ã:`Ã`,Ā:`Ā`,Ă:`Ă`,Ắ:`Ắ`,Ằ:`Ằ`,Ẵ:`Ẵ`,Ǎ:`Ǎ`,Â:`Â`,Ấ:`Ấ`,Ầ:`Ầ`,Ẫ:`Ẫ`,Ȧ:`Ȧ`,Ǡ:`Ǡ`,Å:`Å`,Ǻ:`Ǻ`,Ḃ:`Ḃ`,Ć:`Ć`,Ḉ:`Ḉ`,Č:`Č`,Ĉ:`Ĉ`,Ċ:`Ċ`,Ç:`Ç`,Ď:`Ď`,Ḋ:`Ḋ`,Ḑ:`Ḑ`,É:`É`,È:`È`,Ë:`Ë`,Ẽ:`Ẽ`,Ē:`Ē`,Ḗ:`Ḗ`,Ḕ:`Ḕ`,Ĕ:`Ĕ`,Ḝ:`Ḝ`,Ě:`Ě`,Ê:`Ê`,Ế:`Ế`,Ề:`Ề`,Ễ:`Ễ`,Ė:`Ė`,Ȩ:`Ȩ`,Ḟ:`Ḟ`,Ǵ:`Ǵ`,Ḡ:`Ḡ`,Ğ:`Ğ`,Ǧ:`Ǧ`,Ĝ:`Ĝ`,Ġ:`Ġ`,Ģ:`Ģ`,Ḧ:`Ḧ`,Ȟ:`Ȟ`,Ĥ:`Ĥ`,Ḣ:`Ḣ`,Ḩ:`Ḩ`,Í:`Í`,Ì:`Ì`,Ï:`Ï`,Ḯ:`Ḯ`,Ĩ:`Ĩ`,Ī:`Ī`,Ĭ:`Ĭ`,Ǐ:`Ǐ`,Î:`Î`,İ:`İ`,Ĵ:`Ĵ`,Ḱ:`Ḱ`,Ǩ:`Ǩ`,Ķ:`Ķ`,Ĺ:`Ĺ`,Ľ:`Ľ`,Ļ:`Ļ`,Ḿ:`Ḿ`,Ṁ:`Ṁ`,Ń:`Ń`,Ǹ:`Ǹ`,Ñ:`Ñ`,Ň:`Ň`,Ṅ:`Ṅ`,Ņ:`Ņ`,Ó:`Ó`,Ò:`Ò`,Ö:`Ö`,Ȫ:`Ȫ`,Õ:`Õ`,Ṍ:`Ṍ`,Ṏ:`Ṏ`,Ȭ:`Ȭ`,Ō:`Ō`,Ṓ:`Ṓ`,Ṑ:`Ṑ`,Ŏ:`Ŏ`,Ǒ:`Ǒ`,Ô:`Ô`,Ố:`Ố`,Ồ:`Ồ`,Ỗ:`Ỗ`,Ȯ:`Ȯ`,Ȱ:`Ȱ`,Ő:`Ő`,Ṕ:`Ṕ`,Ṗ:`Ṗ`,Ŕ:`Ŕ`,Ř:`Ř`,Ṙ:`Ṙ`,Ŗ:`Ŗ`,Ś:`Ś`,Ṥ:`Ṥ`,Š:`Š`,Ṧ:`Ṧ`,Ŝ:`Ŝ`,Ṡ:`Ṡ`,Ş:`Ş`,Ť:`Ť`,Ṫ:`Ṫ`,Ţ:`Ţ`,Ú:`Ú`,Ù:`Ù`,Ü:`Ü`,Ǘ:`Ǘ`,Ǜ:`Ǜ`,Ǖ:`Ǖ`,Ǚ:`Ǚ`,Ũ:`Ũ`,Ṹ:`Ṹ`,Ū:`Ū`,Ṻ:`Ṻ`,Ŭ:`Ŭ`,Ǔ:`Ǔ`,Û:`Û`,Ů:`Ů`,Ű:`Ű`,Ṽ:`Ṽ`,Ẃ:`Ẃ`,Ẁ:`Ẁ`,Ẅ:`Ẅ`,Ŵ:`Ŵ`,Ẇ:`Ẇ`,Ẍ:`Ẍ`,Ẋ:`Ẋ`,Ý:`Ý`,Ỳ:`Ỳ`,Ÿ:`Ÿ`,Ỹ:`Ỹ`,Ȳ:`Ȳ`,Ŷ:`Ŷ`,Ẏ:`Ẏ`,Ź:`Ź`,Ž:`Ž`,Ẑ:`Ẑ`,Ż:`Ż`,ά:`ά`,ὰ:`ὰ`,ᾱ:`ᾱ`,ᾰ:`ᾰ`,έ:`έ`,ὲ:`ὲ`,ή:`ή`,ὴ:`ὴ`,ί:`ί`,ὶ:`ὶ`,ϊ:`ϊ`,ΐ:`ΐ`,ῒ:`ῒ`,ῑ:`ῑ`,ῐ:`ῐ`,ό:`ό`,ὸ:`ὸ`,ύ:`ύ`,ὺ:`ὺ`,ϋ:`ϋ`,ΰ:`ΰ`,ῢ:`ῢ`,ῡ:`ῡ`,ῠ:`ῠ`,ώ:`ώ`,ὼ:`ὼ`,Ύ:`Ύ`,Ὺ:`Ὺ`,Ϋ:`Ϋ`,Ῡ:`Ῡ`,Ῠ:`Ῠ`,Ώ:`Ώ`,Ὼ:`Ὼ`},FJ=class e{constructor(e,t){this.mode=void 0,this.gullet=void 0,this.settings=void 0,this.leftrightDepth=void 0,this.nextToken=void 0,this.mode=`math`,this.gullet=new AJ(e,t,this.mode),this.settings=t,this.leftrightDepth=0,this.nextToken=null}expect(e,t){if(t===void 0&&(t=!0),this.fetch().text!==e)throw new L(`Expected '`+e+`', got '`+this.fetch().text+`'`,this.fetch());t&&this.consume()}consume(){this.nextToken=null}fetch(){return this.nextToken??=this.gullet.expandNextToken(),this.nextToken}switchMode(e){this.mode=e,this.gullet.switchMode(e)}parse(){this.settings.globalGroup||this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set(`\\color`,`\\textcolor`);try{var e=this.parseExpression(!1);return this.expect(`EOF`),this.settings.globalGroup||this.gullet.endGroup(),e}finally{this.gullet.endGroups()}}subparse(e){var t=this.nextToken;this.consume(),this.gullet.pushToken(new yq(`}`)),this.gullet.pushTokens(e);var n=this.parseExpression(!1);return this.expect(`}`),this.nextToken=t,n}parseExpression(t,n){for(var r=[];;){this.mode===`math`&&this.consumeSpaces();var i=this.fetch();if(e.endOfExpression.has(i.text)||n&&i.text===n||t&&uJ[i.text]&&uJ[i.text].infix)break;var a=this.parseAtom(n);if(!a)break;a.type!==`internal`&&r.push(a)}return this.mode===`text`&&this.formLigatures(r),this.handleInfixNodes(r)}handleInfixNodes(e){for(var t=-1,n,r=0;r=128)this.settings.strict&&(mU(t.charCodeAt(0))?this.mode===`math`&&this.settings.reportNonstrict(`unicodeTextInMathMode`,`Unicode text character "`+t[0]+`" used in math mode`,e):this.settings.reportNonstrict(`unknownSymbol`,`Unrecognized Unicode character "`+t[0]+`"`+(` (`+t.charCodeAt(0)+`)`),e)),a={type:`textord`,mode:`text`,loc:vq.range(e),text:t};else return null;if(this.consume(),i)for(var c=0;ce.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertBlockMath:e=>({commands:t,editor:n})=>{let{latex:r,pos:i}=e;return r?t.insertContentAt(i??n.state.selection.from,{type:this.name,attrs:{latex:r}}):!1},deleteBlockMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateBlockMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r??a.attrs.latex}),!0)}}},parseHTML(){return[{tag:`div[data-type="block-math"]`}]},renderHTML({HTMLAttributes:e}){return[`div`,A(e,{"data-type":`block-math`})]},parseMarkdown:e=>({type:`blockMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>[`$$`,e.attrs?.latex||``,`$$`].join(` -`),markdownTokenizer:{name:`blockMath`,level:`block`,start:e=>e.indexOf(`$$`),tokenize:e=>{let t=e.match(/^\$\$([^$]+)\$\$/);if(!t)return;let[n,r]=t;return{type:`blockMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new lp({find:/^\$\$\$([^$]+)\$\$\$$/,handler:({state:e,range:t,match:n})=>{let[,r]=n,{tr:i}=e,a=e.doc.resolve(t.from),o=this.type.create({latex:r}),s=a.depth>0&&a.parent.isTextblock&&t.from===a.start()&&t.to===a.end()&&a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),this.type)?{from:a.before(),to:a.after()}:t;i.replaceWith(s.from,s.to,o)}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`div`),i=document.createElement(`div`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),i.className=`block-math-inner`,r.dataset.type=`block-math`,r.setAttribute(`data-latex`,t.attrs.latex),r.appendChild(i);function a(){try{HJ.render(t.attrs.latex,i,e),r.classList.remove(`block-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`block-math-error`)}}let o=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,o),a(),{dom:r,destroy(){r.removeEventListener(`click`,o)}}}}}),WJ=e=>{let t=/\$\$([^$\n]+?)\$\$(?!\$)/g,n=t.exec(e);for(;n!==null;){if(n.index===0||e[n.index-1]!==`$`)return{index:n.index,text:n[0],data:{latex:n[1]}};t.lastIndex=n.index+1,n=t.exec(e)}return null},GJ=Jp.create({name:`inlineMath`,group:`inline`,inline:!0,atom:!0,addOptions(){return{onClick:void 0,katexOptions:void 0}},addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertInlineMath:e=>({editor:t,tr:n})=>{let r=e.latex,i=e?.pos??t.state.selection.from;return r?(n.replaceWith(i,i,this.type.create({latex:r})),!0):!1},deleteInlineMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateInlineMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r}),!0)}}},parseHTML(){return[{tag:`span[data-type="inline-math"]`}]},renderHTML({HTMLAttributes:e}){return[`span`,A(e,{"data-type":`inline-math`})]},parseMarkdown:e=>({type:`inlineMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>`$${e.attrs?.latex||``}$`,markdownTokenizer:{name:`inlineMath`,level:`inline`,start:e=>e.indexOf(`$`),tokenize:e=>{let t=e.match(/^\$([^$]+)\$(?!\$)/);if(!t)return;let[n,r]=t;return{type:`inlineMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new lp({find:WJ,handler:({state:e,range:t,match:n})=>{let r=n.data?.latex;if(typeof r!=`string`)return null;let{tr:i}=e,a=t.from,o=t.to;i.replaceWith(a,o,this.type.create({latex:r}))}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`span`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),r.dataset.type=`inline-math`,r.setAttribute(`data-latex`,t.attrs.latex);function i(){try{HJ.render(t.attrs.latex,r,e),r.classList.remove(`inline-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`inline-math-error`)}}let a=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,a),i(),{dom:r,destroy(){r.removeEventListener(`click`,a)}}}}}),KJ=Tp.create({name:`Mathematics`,addOptions(){return{inlineOptions:void 0,blockOptions:void 0,katexOptions:void 0}},addExtensions(){return[UJ.configure({...this.options.blockOptions,katexOptions:this.options.katexOptions}),GJ.configure({...this.options.inlineOptions,katexOptions:this.options.katexOptions})]}});function qJ(e,t){let n=n=>(r,i)=>{let a=t();if(!a?.isEditable)return;let o=a.view.nodeDOM(i);if(!(o instanceof HTMLElement))return;let s=e.blocks;cH({anchor:o,value:String(r.attrs.latex??``),label:s.latex,multiline:n===`block`,monospace:!0,labels:{done:s.done,cancel:s.cancel,remove:s.remove},onSave:e=>{let t=a.chain().setNodeSelection(i);e.trim()?(n===`inline`?t.updateInlineMath({latex:e,pos:i}):t.updateBlockMath({latex:e,pos:i})).focus().run():(n===`inline`?t.deleteInlineMath({pos:i}):t.deleteBlockMath({pos:i})).focus().run()},onRemove:()=>{let e=a.chain();(n===`inline`?e.deleteInlineMath({pos:i}):e.deleteBlockMath({pos:i})).focus().run()}})};return KJ.configure({katexOptions:{throwOnError:!1,strict:!1,trust:!1},inlineOptions:{onClick:n(`inline`)},blockOptions:{onClick:n(`block`)}})}function JJ({editor:e,overrideSuggestionOptions:t,extensionName:n,char:r=`@`}){return{editor:e,char:r,pluginKey:new Un,command:({editor:e,range:t,props:i})=>{var a,o;let s=e.view.state.selection.$to.nodeAfter;s!=null&&(a=s.text)!=null&&a.startsWith(` `)&&(t.to+=1),e.chain().focus().insertContentAt(t,[{type:n,attrs:{...i,mentionSuggestionChar:r}},{type:`text`,text:` `}]).run(),(o=e.view.dom.ownerDocument.defaultView)==null||(o=o.getSelection())==null||o.collapseToEnd()},allow:({state:e,range:t})=>{let r=e.doc.resolve(t.from),i=e.schema.nodes[n];return!!r.parent.type.contentMatch.matchType(i)},...t}}function YJ(e){return(e.options.suggestions.length?e.options.suggestions:[e.options.suggestion]).map(t=>JJ({editor:e.editor,overrideSuggestionOptions:t,extensionName:e.name,char:t.char}))}function XJ(e,t){let n=YJ(e);return n.find(e=>e.char===t)||(n.length?n[0]:null)}var ZJ=Jp.create({name:`mention`,priority:101,addOptions(){return{HTMLAttributes:{},renderText({node:e,suggestion:t}){return`${t?.char??`@`}${e.attrs.label??e.attrs.id}`},deleteTriggerWithBackspace:!1,renderHTML({options:e,node:t,suggestion:n}){return[`span`,A(this.HTMLAttributes,e.HTMLAttributes),`${n?.char??`@`}${t.attrs.label??t.attrs.id}`]},suggestions:[],suggestion:{}}},group:`inline`,inline:!0,selectable:!1,atom:!0,addAttributes(){return{id:{default:null,parseHTML:e=>e.getAttribute(`data-id`),renderHTML:e=>e.id?{"data-id":e.id}:{}},label:{default:null,parseHTML:e=>e.getAttribute(`data-label`),renderHTML:e=>e.label?{"data-label":e.label}:{}},mentionSuggestionChar:{default:`@`,parseHTML:e=>e.getAttribute(`data-mention-suggestion-char`),renderHTML:e=>({"data-mention-suggestion-char":e.mentionSuggestionChar})}}},parseHTML(){return[{tag:`span[data-type="${this.name}"]`}]},renderHTML({node:e,HTMLAttributes:t}){let n=XJ(this,e.attrs.mentionSuggestionChar);if(this.options.renderLabel!==void 0)return console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),[`span`,A({"data-type":this.name},this.options.HTMLAttributes,t),this.options.renderLabel({options:this.options,node:e,suggestion:n})];let r={...this.options};r.HTMLAttributes=A({"data-type":this.name},this.options.HTMLAttributes,t);let i=this.options.renderHTML({options:r,node:e,suggestion:n});return typeof i==`string`?[`span`,A({"data-type":this.name},this.options.HTMLAttributes,t),i]:i},...$f({nodeName:`mention`,name:`@`,selfClosing:!0,allowedAttributes:[`id`,`label`,{name:`mentionSuggestionChar`,skipIfDefault:`@`}],parseAttributes:e=>{let t={},n=/(?:^|\s)(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i===`char`?`mentionSuggestionChar`:i]=a??o,r=n.exec(e)}return t},serializeAttributes:e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e===`mentionSuggestionChar`?`char`:e}="${t}"`).join(` `)}),renderText({node:e}){let t={options:this.options,node:e,suggestion:XJ(this,e.attrs.mentionSuggestionChar)};return this.options.renderLabel===void 0?this.options.renderText(t):(console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),this.options.renderLabel(t))},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.command(({tr:e,state:t})=>{let n=!1,{selection:r}=t,{empty:i,anchor:a}=r;if(!i)return!1;let o=new ce,s=0;return t.doc.nodesBetween(a-1,a,(e,t)=>{if(e.type.name===this.name)return n=!0,o=e,s=t,!1}),n&&e.insertText(this.options.deleteTriggerWithBackspace?``:o.attrs.mentionSuggestionChar,s,s+o.nodeSize),n})}},addProseMirrorPlugins(){return YJ(this).map(BV)}});function QJ(e,t){return ZJ.configure({HTMLAttributes:{class:`dw-mention`},renderText:({node:e})=>`@${e.attrs.label??e.attrs.id}`,suggestion:{char:`@`,allow:()=>!!t,findSuggestionMatch:t=>{let n=EV({...t,allowSpaces:!0});return n&&xV(n.query,e)?n:EV({...t,allowSpaces:!1})},items:async({query:n})=>{if(!t)return[];let r=bV(n,e,!!t.me).map(e=>({date:e})),i=(await t.search(n).catch(()=>[])).map(e=>({person:e}));return n.trim()?[...r,...i].slice(0,8):[...i.slice(0,6),...r]},render:Uj({label:e.mentions,empty:e.noPeople,toItem:t=>`person`in t?{label:t.person.label,description:t.person.hint,icon:`at`}:{label:vV(t.date.date,e),description:t.date.remind?`${e.dates.remindMe} · ${yV(t.date.date,e)}`:yV(t.date.date,e),icon:t.date.remind?`bell`:`calendar`},pick:(e,n)=>{`person`in n?e.command({id:n.person.id,label:n.person.label}):wV(e.editor,e.range,n.date,t?.me)}})}})}var $J=`flowchart LR - Idea --> Draft --> Review --> Published`,eY=null;function tY(e){return eY??=e().then(e=>(e.initialize({startOnLoad:!1,securityLevel:`strict`,theme:document.documentElement.classList.contains(`dark`)?`dark`:`neutral`,fontFamily:`inherit`}),e)),eY}var nY=0;async function rY(e,t,n,r){if(e.classList.remove(`dw-mermaid__body--error`),!t.trim())e.textContent=``;else if(r)try{let{svg:n}=await(await tY(r)).render(`dw-mermaid-${++nY}`,t);e.innerHTML=n}catch(t){e.classList.add(`dw-mermaid__body--error`),e.textContent=`${n.blocks.mermaidError} ${t instanceof Error?t.message:String(t)}`}else{let n=document.createElement(`pre`);n.className=`dw-mermaid__source`,n.textContent=t,e.replaceChildren(n)}}var iY=Jp.create({name:`mermaid`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null,load:void 0}},addAttributes(){return{code:{default:``,parseHTML:e=>e.getAttribute(`data-code`)??e.textContent??``,renderHTML:e=>({"data-code":e.code})}}},parseHTML(){return[{tag:`div[data-type='mermaid']`},{tag:`pre.mermaid`}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,A(t,{"data-type":`mermaid`}),[`pre`,{},String(e.attrs.code)]]},addCommands(){return{insertMermaid:(e=$J)=>({commands:t})=>t.insertContent({type:this.name,attrs:{code:e}})}},addNodeView(){return({node:e,editor:t,getPos:n})=>{let r=this.options.labels,i=this.options.load,a=document.createElement(`div`);a.className=`dw-mermaid`,a.setAttribute(`data-type`,`mermaid`);let o=document.createElement(`div`);o.className=`dw-mermaid__body`,a.append(o);let s=String(e.attrs.code);return rY(o,s,r,i),a.addEventListener(`click`,()=>{if(!t.isEditable)return;let e=typeof n==`function`?n():void 0;if(e===void 0)return;let c=r.blocks;cH({anchor:a,value:s,label:c.mermaid,multiline:!0,monospace:!0,labels:{done:c.done,cancel:c.cancel,remove:c.remove},onInput:e=>void rY(o,e,r,i),onSave:n=>{t.chain().setNodeSelection(e).updateAttributes(`mermaid`,{code:n}).run(),rY(o,n,r,i)},onRemove:()=>t.chain().setNodeSelection(e).deleteSelection().focus().run(),onCancel:()=>void rY(o,s,r,i)})}),{dom:a,update:e=>e.type.name===`mermaid`&&(e.attrs.code!==s&&(s=String(e.attrs.code),rY(o,s,r,i)),!0),ignoreMutation:()=>!0,stopEvent:()=>!1}}}});function aY(e){return new Promise(t=>{let n=document.createElement(`input`);n.type=`file`,n.accept=e,n.multiple=!0,n.onchange=()=>t([...n.files??[]]),n.click()})}function oY(e,t,n,r,i=!1,a){let o=(t,n,r,i)=>({id:t,icon:n,keywords:r,label:e.slash[t]?.label??t,description:e.slash[t]?.description??``,run:i}),s=[o(`text`,`text`,[`paragraph`,`p`],(e,t)=>e.chain().focus().deleteRange(t).setParagraph().run()),o(`h1`,`heading`,[`heading`,`title`,`#`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:1}).run()),o(`h2`,`heading`,[`heading`,`subtitle`,`##`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:2}).run()),o(`h3`,`heading`,[`heading`,`###`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:3}).run()),{...o(`otherHeadings`,`heading`,[`other`,`more headings`,`smaller`],()=>{}),children:[4,5,6].map(e=>o(`h${e}`,`heading`,[`heading`,`#`.repeat(e)],(t,n)=>t.chain().focus().deleteRange(n).setHeading({level:e}).run()))},o(`bullet`,`list`,[`list`,`ul`,`-`],(e,t)=>e.chain().focus().deleteRange(t).toggleBulletList().run()),o(`ordered`,`list-ordered`,[`list`,`ol`,`1.`],(e,t)=>e.chain().focus().deleteRange(t).toggleOrderedList().run()),o(`todo`,`todo`,[`task`,`checkbox`,`checklist`,`[]`],(e,t)=>e.chain().focus().deleteRange(t).toggleTaskList().run()),o(`callout`,`callout`,[`note`,`info`,`tip`,`warning`,`aside`,`box`],(e,t)=>e.chain().focus().deleteRange(t).setCallout().run()),{...o(`columns`,`columns`,[`layout`,`side by side`,`split`,`grid`,`multi-column`],()=>{}),children:[2,3,4].map(e=>o(`columns${e}`,`columns`,[`columns`,`layout`,`side by side`,String(e)],(t,n)=>t.chain().focus().deleteRange(n).insertColumns(e).run()))},o(`table`,`table`,[`grid`,`rows`,`columns`,`spreadsheet`],(e,t)=>e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()),o(`database`,`database`,[`kanban`,`board`,`calendar`,`records`,`tracker`,`notion`],(e,t)=>e.chain().focus().deleteRange(t).insertDatabase().run()),o(`quote`,`quote`,[`blockquote`,`>`],(e,t)=>e.chain().focus().deleteRange(t).toggleBlockquote().run()),o(`code`,`code`,[`codeblock`,"```",`snippet`],(e,t)=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()),o(`toggle`,`chevron-right`,[`details`,`collapse`,`expand`,`fold`,`>`],(e,t)=>e.chain().focus().deleteRange(t).setDetails().run()),o(`divider`,`divider`,[`hr`,`rule`,`line`,`---`],(e,t)=>e.chain().focus().deleteRange(t).setHorizontalRule().run()),o(`toc`,`list`,[`contents`,`outline`,`headings`,`index`],(e,t)=>e.chain().focus().deleteRange(t).insertTableOfContents().run()),o(`math`,`sigma`,[`latex`,`formula`,`equation`,`katex`,`$$`],(e,t)=>e.chain().focus().deleteRange(t).insertBlockMath({latex:`E = mc^2`}).run()),o(`mathInline`,`sigma`,[`latex`,`formula`,`equation`,`$`],(e,t)=>e.chain().focus().deleteRange(t).insertInlineMath({latex:`x^2`}).run()),o(`mermaid`,`diagram`,[`diagram`,`flowchart`,`chart`,`sequence`,`graph`],(e,t)=>e.chain().focus().deleteRange(t).insertMermaid().run()),o(`embed`,`video`,[`video`,`youtube`,`vimeo`,`figma`,`loom`,`iframe`,`map`],(t,r)=>{t.chain().focus().deleteRange(r).run(),hH(t,e,a,n)}),o(`linkCard`,`link`,[`bookmark`,`preview`,`card`,`url`,`web`],(t,r)=>{t.chain().focus().deleteRange(r).run(),gH(t,e,a,n)})],c=e=>{let t=new Date;return mV(new Date(t.getFullYear(),t.getMonth(),t.getDate()+e))};if(s.push(o(`today`,`calendar`,[`date`,`day`],(e,t)=>wV(e,t,{date:c(0),remind:!1})),o(`tomorrow`,`calendar`,[`date`,`day`],(e,t)=>wV(e,t,{date:c(1),remind:!1})),o(`yesterday`,`calendar`,[`date`,`day`],(e,t)=>wV(e,t,{date:c(-1),remind:!1})),o(`now`,`clock`,[`time`,`date`,`timestamp`],(t,n)=>{wV(t,n,{date:c(0),remind:!1});let r=new Intl.DateTimeFormat(e.locale,{hour:`numeric`,minute:`2-digit`}).format(new Date);t.chain().focus().insertContent(`${r} `).run()})),r&&(s.push(o(`pageLink`,`link`,[`page`,`link`,`[[`,`wiki`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`[[`).run())),s.push(o(`syncedPage`,`copy`,[`embed`,`transclude`,`include`,`mirror`,`![[`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`![[`).run())),r.create&&s.push(o(`newPage`,`page-plus`,[`page`,`doc`,`subpage`,`create`],(e,t)=>{e.chain().focus().deleteRange(t).run(),KV(e,r,``).catch(n)}))),t?.upload){let e=e=>(r,i)=>{r.chain().focus().deleteRange(i).run(),aY(e).then(e=>CH(r,t,e).catch(n))};s.push(o(`image`,`image`,[`picture`,`photo`,`img`],e(`image/*`)),o(`file`,`paperclip`,[`attachment`,`upload`,`pdf`],e(``)),o(`drawio`,`diagram`,[`diagram`,`diagrams.net`,`draw`,`chart`,`uml`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`drawio`).run())),i&&s.push(o(`excalidraw`,`pencil`,[`drawing`,`sketch`,`whiteboard`,`draw`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`excalidraw`).run()))}return s}function sY(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e=>e.label.toLowerCase().includes(n)||e.id.startsWith(n)||e.keywords.some(e=>e.toLowerCase().startsWith(n));return e.flatMap(e=>{let t=e.children?.filter(r)??[];return t.length?t:r(e)?[e]:[]})}var cY=Tp.create({name:`slashMenu`,addOptions(){return{commands:[],labels:void 0}},addProseMirrorPlugins(){return[VV({editor:this.editor,pluginKey:new Un(`slashMenu`),char:`/`,allowSpaces:!1,startOfLine:!1,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:({query:e})=>sY(this.options.commands,e),render:Uj({label:this.options.labels.slashMenu,empty:this.options.labels.noMatches,showQuery:!0,toItem:e=>({label:e.label,description:e.description,icon:e.icon}),children:e=>e.children,pick:(e,t)=>t.run(e.editor,e.range)})})]}}),lY=`suggestInsert`,uY=`suggestDelete`,dY=`suggestionSkip`,fY=new Un(`suggestions`),pY=()=>Math.random().toString(36).slice(2,10);function mY(e,t){return _p.create({name:e,inclusive:!1,excludes:``,priority:1100,addAttributes(){return{id:{default:``,parseHTML:e=>e.getAttribute(`data-suggestion`)??``},author:{default:``,parseHTML:e=>e.getAttribute(`data-author`)??``},name:{default:``,parseHTML:e=>e.getAttribute(`data-name`)??``},at:{default:0,parseHTML:e=>Number(e.getAttribute(`data-at`))||0}}},parseHTML(){return[{tag:`${t}[data-suggestion]`}]},renderHTML({mark:e,HTMLAttributes:n}){let r=e.attrs;return[t,A({class:t===`ins`?`dw-suggest-ins`:`dw-suggest-del`},{"data-suggestion":r.id,"data-author":r.author,"data-name":r.name,"data-at":String(r.at),title:r.name},Object.fromEntries(Object.entries(n).filter(([e])=>e===`class`||e===`style`))),0]}})}var hY=mY(lY,`ins`),gY=mY(uY,`del`),_Y=(e,t)=>e.marks.find(e=>e.type===t);function vY(e,t){let n=new Map;return e.descendants((e,r)=>{if(!e.isInline)return!0;for(let i of e.marks){if(i.type.name!==lY&&i.type.name!==uY)continue;let a=String(i.attrs.id);if(t&&a!==t)continue;let o=n.get(a)??[],s=i.type.name===lY,c=o[o.length-1];c&&c.to===r&&c.insert===s?c.to=r+e.nodeSize:o.push({from:r,to:r+e.nodeSize,insert:s}),n.set(a,o)}return!1}),n}function yY(e,t,n){let r=vY(e.doc,n);if(!r.size)return!1;let i=e.doc.type.schema,a=[];for(let n of r.values())for(let r of n){let n=i.marks[r.insert?lY:uY];r.insert===t?e.removeMark(r.from,r.to,n):a.push(r)}a.sort((e,t)=>t.from-e.from);for(let t of a)e.delete(t.from,t.to);return e.setMeta(dY,!0),!0}function bY(e){let t=!1;return e.descendants(e=>(e.isInline&&(t=!0),!t)),t}function xY(e,t,n,r,i){let a=[];return e.forEach(e=>{if(e.isInline){let o=_Y(e,n);if(o&&o.attrs.author===i)return;a.push(_Y(e,t)?e:e.mark(t.create(r).addToSet(e.marks)))}else a.push(e.copy(xY(e.content,t,n,r,i)))}),s.from(a)}function SY(e,t,n,r){let i=e.resolve(Math.min(Math.max(t,0),e.content.size));for(let e of[i.nodeBefore,i.nodeAfter]){let t=e&&_Y(e,n);if(t&&t.attrs.author===r)return t.attrs}return null}function CY(e,t,n,r){if(!e.steps.length||!e.steps.every(e=>e instanceof Et))return null;let i=n.schema,a=i.marks[lY],o=i.marks[uY],s=n.tr,c=Date.now(),l=null,u=e.steps.length===1;if(e.steps.forEach((n,i)=>{let d=n,f=e.docs[i].slice(d.from,d.to),m=s.mapping.map(e.mapping.slice(i+1).map(d.from,-1),-1),h=d.slice.size;if(h>0&&bY(d.slice.content)){let e=m+h,t=SY(s.doc,m,a,r.id)??SY(s.doc,e,a,r.id)??{id:pY(),author:r.id,name:r.name,at:c};s.doc.nodesBetween(m,e,(n,r)=>{if(!n.isInline)return!0;let i=Math.max(r,m),c=Math.min(r+n.nodeSize,e);return _Y(n,o)&&s.removeMark(i,c,o),s.addMark(i,c,a.create(t)),!1})}let g=0;if(f.size>0&&bY(f.content)){let e=SY(s.doc,m,o,r.id)??SY(s.doc,m+1,o,r.id)??{id:pY(),author:r.id,name:r.name,at:c},t=xY(f.content,o,a,e,r.id);if(bY(t)){let e=new p(t,f.openStart,f.openEnd),n=s.doc.content.size;s.replace(m,m,e),g=s.doc.content.size-n}}if(u){let e=t.selection;l=h>0?m+g+h:e.empty&&e.head===d.to?m:m+g}}),!s.docChanged)return null;if(l!==null){let t=Math.min(Math.max(l,0),s.doc.content.size);s.setSelection(T.near(s.doc.resolve(t),wY(e)))}return s.setMeta(dY,!0),s}function wY(e){return e.steps[0].slice.size>0?1:-1}var TY=Tp.create({name:`suggestions`,addOptions(){return{onSelect:void 0}},addExtensions(){return[hY,gY]},addCommands(){return{setSuggesting:e=>({tr:t,dispatch:n})=>(n&&t.setMeta(fY,{author:e}).setMeta(dY,!0).setMeta(`addToHistory`,!1),!0),acceptSuggestion:e=>({tr:t})=>yY(t,!0,e),rejectSuggestion:e=>({tr:t})=>yY(t,!1,e),acceptAllSuggestions:()=>({tr:e})=>yY(e,!0),rejectAllSuggestions:()=>({tr:e})=>yY(e,!1)}},addProseMirrorPlugins(){let e=()=>this.options.onSelect;return[new D({key:fY,state:{init:()=>({author:null}),apply:(e,t)=>e.getMeta(fY)??t},appendTransaction(e,t,n){let r=fY.getState(n)?.author;if(!r||e.length!==1)return null;let i=e[0];return!i.docChanged||i.getMeta(dY)||i.getMeta(FS)?.isChangeOrigin||i.getMeta(`history$`)||i.getMeta(`isUndoRedo`)?null:CY(i,t,n,r)},props:{attributes:e=>fY.getState(e)?.author?{"data-suggesting":`true`}:{},handleClick(t,n,r){let i=r.target?.closest?.(`[data-suggestion]`),a=i?.getAttribute(`data-suggestion`);return!i||!a||e()?.(a,i),!1}}})]}});function EY(e,t){let n=!0,r=e.firstChild?.childCount??0;return e.forEach(e=>{t===`column`&&e.childCount!==r&&(n=!1),e.forEach(e=>{((t===`row`?e.attrs.rowspan:e.attrs.colspan)??1)>1&&(n=!1)})}),n}function DY(e,t,n){let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r}var OY=e=>{let t=[];return e.forEach(e=>t.push(e)),t};function kY(e,t,n,r,i,a=0){let o=e.doc.nodeAt(t);if(!o||o.type.name!==`table`||!EY(o,n))return null;let c=OY(o),l=n===`row`?c.length:c[0]?.childCount??0;if(r===i||r<0||i<0||r>=l||i>=l)return null;let u=n===`row`?DY(c,r,i):c.map(e=>e.copy(s.fromArray(DY(OY(e),r,i)))),d=e.tr.replaceWith(t,t+o.nodeSize,o.copy(s.fromArray(u))),[f,p]=n===`row`?[i,0]:[Math.min(a,u.length-1),i],m=t+1;for(let e=0;e0;e--)if(n.node(e).type.name===`table`)return{tablePos:n.before(e),row:n.index(e),column:e+1<=n.depth?n.index(e+1):0};return null}var jY=Tp.create({name:`tableMove`,addOptions(){return{labels:null}},addCommands(){let e=e=>t=>({state:n,dispatch:r})=>{let i=AY(n,n.selection.from);if(!i)return!1;let a=e===`row`?i.row:i.column,o=kY(n,i.tablePos,e,a,a+t,i.row);return o?(r?.(o),!0):!1};return{moveTableRow:e(`row`),moveTableColumn:e(`column`)}},addKeyboardShortcuts(){return{"Mod-Alt-ArrowUp":()=>this.editor.commands.moveTableRow(-1),"Mod-Alt-ArrowDown":()=>this.editor.commands.moveTableRow(1),"Mod-Alt-ArrowLeft":()=>this.editor.commands.moveTableColumn(-1),"Mod-Alt-ArrowRight":()=>this.editor.commands.moveTableColumn(1)}},addProseMirrorPlugins(){let e=this.options.labels?.table;return[new D({key:new Un(`tableMove`),view:t=>new MY(t,{row:e?.dragRow??`Drag to move the row`,column:e?.dragColumn??`Drag to move the column`})})]}}),MY=class{view;grips={row:document.createElement(`button`),column:document.createElement(`button`)};line=document.createElement(`div`);cell=null;drag=null;constructor(e,t){this.view=e;for(let e of[`row`,`column`]){let n=this.grips[e];n.type=`button`,n.className=`dw-table-grip dw-table-grip--${e}`,n.contentEditable=`false`,n.setAttribute(`aria-label`,t[e]),n.title=t[e],n.hidden=!0,n.tabIndex=-1,n.addEventListener(`pointerdown`,t=>this.start(t,e)),n.addEventListener(`mouseleave`,this.leave)}this.line.className=`dw-table-drop`,this.line.hidden=!0,e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave)}get host(){let e=this.view.dom.parentElement;return e&&this.line.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.grips.row,this.grips.column,this.line)),e}hide=()=>{this.drag||(this.grips.row.hidden=!0,this.grips.column.hidden=!0,this.cell=null)};leave=e=>{let t=e.relatedTarget;t&&(this.grips.row.contains(t)||this.grips.column.contains(t)||this.view.dom.contains(t))||this.hide()};move=e=>{if(this.drag)return;let t=e.target?.closest?.(`td, th`),n=this.host;if(!this.view.editable||!n||!(t instanceof HTMLTableCellElement)||!this.view.dom.contains(t))return this.hide();let r=this.locate(t),i=r&&this.view.state.doc.nodeAt(r.tablePos);if(!r||!i)return this.hide();this.cell=t;let a=n.getBoundingClientRect(),o=t.closest(`table`).getBoundingClientRect(),s=t.parentElement.getBoundingClientRect(),c=t.getBoundingClientRect(),l=i.childCount>1&&EY(i,`row`),u=(i.firstChild?.childCount??0)>1&&EY(i,`column`);Object.assign(this.grips.row.style,{top:`${s.top-a.top+s.height/2-11}px`,left:`${o.left-a.left-7}px`}),Object.assign(this.grips.column.style,{top:`${o.top-a.top-7}px`,left:`${c.left-a.left+c.width/2-11}px`}),this.grips.row.hidden=!l,this.grips.column.hidden=!u};locate(e){try{return AY(this.view.state,this.view.posAtDOM(e,0))}catch{return null}}start(e,t){let n=this.cell;if(!n||e.button!==0)return;let r=this.locate(n),i=n.parentElement?.parentElement;if(!r||!i)return;e.preventDefault();let a=this.grips[t];a.setPointerCapture(e.pointerId);let o=[...i.children].filter(e=>e instanceof HTMLTableRowElement),s=t===`row`?r.row:r.column,c=t===`row`?o:[...o[0]?.children??[]],l=t===`row`?[o[s]]:o.map(e=>e.children[s]).filter(Boolean);for(let e of l)e.classList.add(`dw-table-dragging`);this.drag={axis:t,tablePos:r.tablePos,from:s,slots:c,dimmed:l,to:s,cursorRow:r.row},a.addEventListener(`pointermove`,this.dragMove),a.addEventListener(`pointerup`,this.drop),a.addEventListener(`pointercancel`,this.cancel)}dragMove=e=>{let t=this.drag,n=this.host;if(!t||!n)return;let r=t.axis===`row`,i=r?e.clientY:e.clientX,a=t.slots.length;for(let[e,n]of t.slots.entries()){let t=n.getBoundingClientRect();if(i<(r?t.top+t.height/2:t.left+t.width/2)){a=e;break}}t.to=a>t.from?a-1:a;let o=n.getBoundingClientRect(),s=t.slots[0].closest(`table`).getBoundingClientRect(),c=t.slots.at(-1).getBoundingClientRect(),l=t.slots[a]?.getBoundingClientRect(),u=r?l?.top??c.bottom:l?.left??c.right;Object.assign(this.line.style,r?{top:`${u-o.top-1}px`,left:`${s.left-o.left}px`,width:`${s.width}px`,height:`2px`}:{top:`${s.top-o.top}px`,left:`${u-o.left-1}px`,width:`2px`,height:`${s.height}px`}),this.line.hidden=t.to===t.from};drop=()=>{let e=this.drag;if(this.cancel(),!e||e.to===e.from)return;let t=kY(this.view.state,e.tablePos,e.axis,e.from,e.to,e.cursorRow);t&&this.view.dispatch(t),this.view.focus()};cancel=()=>{let e=this.drag;for(let t of e?.dimmed??[])t.classList.remove(`dw-table-dragging`);this.drag=null,this.line.hidden=!0;for(let e of Object.values(this.grips))e.removeEventListener(`pointermove`,this.dragMove),e.removeEventListener(`pointerup`,this.drop),e.removeEventListener(`pointercancel`,this.cancel);this.hide()};update(){this.cell&&!this.cell.isConnected&&this.hide()}destroy(){this.cancel();for(let e of Object.values(this.grips))e.remove();this.line.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave)}};function NY(e){let t=[];return e.descendants((e,n)=>e.type.name!==`heading`||(t.push({level:Number(e.attrs.level)||1,text:e.textContent.trim(),pos:n}),!1)),t}function PY(e,t){let n=e.view.nodeDOM(t);n instanceof HTMLElement&&n.scrollIntoView({behavior:`smooth`,block:`start`}),e.isEditable&&e.commands.setTextSelection(t+1)}var FY=Jp.create({name:`tableOfContents`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`nav[data-type='toc']`}]},renderHTML(){return[`nav`,{"data-type":`toc`}]},addCommands(){return{insertTableOfContents:()=>({commands:e})=>e.insertContent({type:this.name})}},addNodeView(){return({editor:e})=>{let t=this.options.labels.blocks,n=document.createElement(`nav`);n.className=`dw-toc`,n.setAttribute(`data-type`,`toc`),n.setAttribute(`aria-label`,t.toc),n.contentEditable=`false`;let r=document.createElement(`p`);r.className=`dw-toc__title`,r.textContent=t.toc;let i=document.createElement(`ol`);i.className=`dw-toc__list`,n.append(r,i);let a=``,o=()=>{let n=NY(e.state.doc),r=JSON.stringify(n.map(e=>[e.level,e.text]));if(r===a){i.querySelectorAll(`a`).forEach((e,t)=>e.dataset.pos=String(n[t]?.pos??0));return}if(a=r,i.replaceChildren(),!n.length){let e=document.createElement(`li`);e.className=`dw-toc__empty`,e.textContent=t.tocEmpty,i.append(e);return}let o=Math.min(...n.map(e=>e.level));for(let t of n){let n=document.createElement(`li`);n.style.paddingLeft=`${(t.level-o)*1}rem`;let r=document.createElement(`a`);r.href=`#`,r.textContent=t.text||`…`,r.dataset.pos=String(t.pos),r.addEventListener(`click`,t=>{t.preventDefault(),PY(e,Number(r.dataset.pos))}),n.append(r),i.append(n)}};return o(),e.on(`update`,o),{dom:n,update:e=>e.type.name===`tableOfContents`,ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`),destroy:()=>e.off(`update`,o)}}}}),IY=(e,t)=>{let n=t.view.domAtPos(e).node,r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return r?r.offsetParent!==null:!1},LY=(e,t,n)=>{for(let r=e.depth;r>0;--r){let i=e.node(r),a=t(i),o=IY(e.start(r),n);if(a&&o)return{pos:r>0?e.before(r):0,start:e.start(r),depth:r,node:i}}},RY=(e,t)=>{let{state:n,view:r,extensionManager:i}=e,{schema:a,selection:o}=n,{empty:s,$anchor:c}=o,l=!!i.extensions.find(e=>e.name===`gapCursor`);if(!s||c.parent.type!==a.nodes.detailsSummary||!l||t===`right`&&c.parentOffset!==c.parent.nodeSize-2)return!1;let u=yu(e=>e.type===a.nodes.details)(o);if(!u)return!1;let d=gu(u.node,e=>e.type===a.nodes.detailsContent);if(!d.length||IY(u.start+d[0].pos+1,e))return!1;let f=n.doc.resolve(u.pos+u.node.nodeSize),p=zw.findFrom(f,1,!1);if(!p)return!1;let{tr:m}=n,h=new zw(p);return m.setSelection(h),m.scrollIntoView(),r.dispatch(m),!0},zY=Jp.create({name:`details`,content:`detailsSummary detailsContent`,group:`block`,defining:!0,isolating:!0,allowGapCursor:!1,addOptions(){return{persist:!1,openClassName:`is-open`,HTMLAttributes:{},renderToggleButton:({element:e,isOpen:t})=>{e.setAttribute(`aria-label`,t?`Collapse details content`:`Expand details content`)}}},addAttributes(){return this.options.persist?{open:{default:!1,parseHTML:e=>e.hasAttribute(`open`),renderHTML:({open:e})=>e?{open:``}:{}}}:[]},parseHTML(){return[{tag:`details`}]},renderHTML({HTMLAttributes:e}){return[`details`,A(this.options.HTMLAttributes,e),0]},...Xf({nodeName:`details`,content:`block`}),addNodeView(){return({editor:e,getPos:t,node:n,HTMLAttributes:r})=>{let i=document.createElement(`div`),a=A(this.options.HTMLAttributes,r,{"data-type":this.name});Object.entries(a).forEach(([e,t])=>i.setAttribute(e,t));let o=document.createElement(`button`);o.type=`button`;let s=e=>{this.options.renderToggleButton({element:o,...e})};i.append(o);let c=document.createElement(`div`);i.append(c);let l=e=>{let{setToValue:t,node:r=n}=e||{};if(t!==void 0){if(t){if(i.classList.contains(this.options.openClassName))return;i.classList.add(this.options.openClassName)}else{if(!i.classList.contains(this.options.openClassName))return;i.classList.remove(this.options.openClassName)}}else i.classList.toggle(this.options.openClassName);let a=i.classList.contains(this.options.openClassName);s({isOpen:a,node:r});let o=new Event(`toggleDetailsContent`);c.querySelector(`:scope > div[data-type="detailsContent"]`)?.dispatchEvent(o)};return s({isOpen:!!n.attrs.open,node:n}),n.attrs.open&&setTimeout(()=>l()),o.addEventListener(`click`,()=>{if(l(),!this.options.persist)e.commands.focus(void 0,{scrollIntoView:!1});else if(e.isEditable&&typeof t==`function`){let{from:n,to:r}=e.state.selection;e.chain().command(({tr:e})=>{let n=t();if(typeof n!=`number`)return!1;let r=e.doc.nodeAt(n);return r?.type===this.type&&(e.setNodeMarkup(n,void 0,{open:!r.attrs.open}),!0)}).setTextSelection({from:n,to:r}).focus(void 0,{scrollIntoView:!1}).run()}}),{dom:i,contentDOM:c,ignoreMutation(e){if(e.type===`selection`)return!1;let t=e.target,n=i.contains(t);return o.contains(t)||!n||i===t},update:e=>e.type===this.type&&(e.attrs.open===void 0?s({isOpen:i.classList.contains(this.options.openClassName),node:e}):l({setToValue:e.attrs.open,node:e}),!0)}}},addCommands(){return{setDetails:()=>({state:e,chain:t})=>{let{schema:n,selection:r}=e,{$from:i,$to:a}=r,o=i.blockRange(a);if(!o)return!1;let s=e.doc.slice(o.start,o.end);if(!n.nodes.detailsContent.contentMatch.matchFragment(s.content))return!1;let c=s.toJSON()?.content||[];return t().insertContentAt({from:o.start,to:o.end},{type:this.name,content:[{type:`detailsSummary`},{type:`detailsContent`,content:c}]}).setTextSelection(o.start+2).run()},unsetDetails:()=>({state:e,chain:t})=>{let{selection:n,schema:r}=e,i=yu(e=>e.type===this.type)(n);if(!i)return!1;let a=gu(i.node,e=>e.type===r.nodes.detailsSummary),o=gu(i.node,e=>e.type===r.nodes.detailsContent);if(!a.length||!o.length)return!1;let s=a[0],c=o[0],l=i.pos,u=e.doc.resolve(l),d={from:l,to:l+i.node.nodeSize},f=c.node.content.toJSON()||[],p=[u.parent.type.contentMatch.defaultType?.create(null,s.node.content).toJSON(),...f];return t().insertContentAt(d,p).setTextSelection(l+1).run()}}},addKeyboardShortcuts(){return{Backspace:()=>{let{schema:e,selection:t}=this.editor.state,{empty:n,$anchor:r}=t;return!n||r.parent.type!==e.nodes.detailsSummary?!1:r.parentOffset===0?this.editor.commands.unsetDetails():this.editor.commands.command(({tr:e})=>{let t=r.pos-1,n=r.pos;return e.delete(t,n),!0})},Enter:({editor:e})=>{let{state:t,view:n}=e,{schema:r,selection:i}=t,{$head:a}=i;if(a.parent.type!==r.nodes.detailsSummary)return!1;let o=IY(a.after()+1,e),s=o?t.doc.nodeAt(a.after()):a.node(-2);if(!s)return!1;let c=o?0:a.indexAfter(-1),l=Ll(s.contentMatchAt(c));if(!l||!s.canReplaceWith(c,c,l))return!1;let u=l.createAndFill();if(!u)return!1;let d=o?a.after()+1:a.after(-1),f=t.tr.replaceWith(d,d,u),p=f.doc.resolve(d),m=w.near(p,1);return f.setSelection(m),f.scrollIntoView(),n.dispatch(f),!0},ArrowRight:({editor:e})=>RY(e,`right`),ArrowDown:({editor:e})=>RY(e,`down`)}},addProseMirrorPlugins(){return[new D({key:new Un(`detailsSelection`),appendTransaction:(e,t,n)=>{let{editor:r,type:i}=this;if(r.view.composing||!e.some(e=>e.selectionSet)||!t.selection.empty||!n.selection.empty||!sd(n,i.name))return;let{$from:a}=n.selection;if(IY(a.pos,r))return;let o=LY(a,e=>e.type===i,r);if(!o)return;let s=gu(o.node,e=>e.type===n.schema.nodes.detailsSummary);if(!s.length)return;let c=s[0],l=(t.selection.from{let t=document.createElement(`div`),n=A(this.options.HTMLAttributes,e,{"data-type":this.name,hidden:`hidden`});return Object.entries(n).forEach(([e,n])=>t.setAttribute(e,n)),t.addEventListener(`toggleDetailsContent`,()=>{t.toggleAttribute(`hidden`)}),{dom:t,contentDOM:t,ignoreMutation(e){return e.type===`selection`?!1:!t.contains(e.target)||t===e.target},update:e=>e.type===this.type}}},addKeyboardShortcuts(){return{Enter:({editor:e})=>{let{state:t,view:n}=e,{selection:r}=t,{$from:i,empty:a}=r,o=yu(e=>e.type===this.type)(r);if(!a||!o||!o.node.childCount)return!1;let s=i.index(o.depth),{childCount:c}=o.node;if(c!==s+1)return!1;let l=o.node.type.contentMatch.defaultType?.createAndFill();if(!l)return!1;let u=t.doc.resolve(o.pos+1),d=c-1,f=o.node.child(d),p=u.posAtIndex(d,o.depth);if(!f.eq(l))return!1;let m=i.node(-3);if(!m)return!1;let h=i.indexAfter(-3),g=Ll(m.contentMatchAt(h));if(!g||!m.canReplaceWith(h,h,g))return!1;let _=g.createAndFill();if(!_)return!1;let{tr:v}=t,y=i.after(-2);v.replaceWith(y,y,_);let b=v.doc.resolve(y),x=w.near(b,1);v.setSelection(x);let S=p,C=p+f.nodeSize;return v.delete(S,C),v.scrollIntoView(),n.dispatch(v),!0}}},...Xf({nodeName:`detailsContent`})}),VY=Jp.create({name:`detailsSummary`,content:`text*`,defining:!0,selectable:!1,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`summary`}]},renderHTML({HTMLAttributes:e}){return[`summary`,A(this.options.HTMLAttributes,e),0]},...Xf({nodeName:`detailsSummary`,content:`inline`})});function HY(e){return[zY.configure({persist:!1,HTMLAttributes:{class:`dw-toggle`},renderToggleButton:({element:t,isOpen:n})=>{t.setAttribute(`aria-label`,n?e.blocks.collapse:e.blocks.expand),t.setAttribute(`aria-expanded`,String(n))}}),VY,BY]}function UY(e={}){let t=e.labels??BR,n=null,r=Tp.create({name:`editorRef`,onCreate(){n=this.editor}}),i={host:e.files,labels:t,drawioUrl:e.drawioUrl,loadExcalidraw:e.loadExcalidraw,onError:e.onError},a=[r,Yk.configure({heading:{levels:[1,2,3,4,5,6]},codeBlock:!1,link:{openOnClick:!1,autolink:!0},undoRedo:e.collab||e.syncedDoc||e.rowBody||e.rowFragmentReadOnly?!1:void 0}),hT.configure({placeholder:e.placeholder??`Type '/' for commands…`}),wH.configure({host:e.files}),EH.configure({host:e.files,loadPdf:e.loadPdf,labels:t}),Lj.configure({lineNumbers:e.codeLineNumbers??!1}),jP,AP,LP,RP,...OP(),...kP(),jY.configure({labels:t}),VP.configure({labels:t}),JP.configure({labels:t}),YP.configure({labels:t}),DH.configure({host:e.files,onError:e.onError}),QJ(t,e.mentions),SV.configure({labels:t,me:()=>e.mentions?.me,onOpen:e.onOpenDate}),cY.configure({commands:oY(t,e.files,e.onError,e.pages,!!e.loadExcalidraw,e.links),labels:t}),fV.configure({onSelect:e.onCommentSelect}),TY.configure({onSelect:e.onSuggestionSelect}),qJ(t,()=>n),iY.configure({labels:t,load:e.loadMermaid}),FY.configure({labels:t}),aH.configure(i),oH.configure(i),qV.configure({host:e.pages,labels:t,onNavigate:e.onNavigate}),YV.configure({host:e.syncedPages,pages:e.pages,labels:t,onNavigate:e.onNavigate,nested:t=>UY({syncedDoc:t,files:e.files,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:``})}),...HY(t),vH.configure({labels:t}),yH.configure({labels:t}),nM.configure({labels:t,link:e.blockLink,onCopied:e.onBlockLinkCopied}),PH,rV.configure({labels:t,doc:e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc,readOnlyDoc:!!e.syncedDoc,undoScope:!e.rowBody,files:e.files,people:e.mentions,recordLink:e.blockLink,linkedPages:e.syncedPages,pages:e.pages,onNavigate:e.onNavigate,recordPage:e.recordPage,onLinkCopied:e.onBlockLinkCopied,me:()=>{let t=e.mentions?.me;return t?{id:t,name:e.collab?.user.name??``}:null},rowExtensions:n=>{let r=e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc;return UY({rowBody:n&&r&&!e.syncedDoc?{doc:r,fragment:n}:void 0,files:e.files,mentions:e.mentions,pages:e.pages,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadExcalidraw:e.loadExcalidraw,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:t.database.bodyPlaceholder,rowFragmentReadOnly:n&&e.syncedDoc?n:void 0})}})],o={trackedOrigins:[rB]};return e.rowBody?a.push(jw.configure({document:e.rowBody.doc,fragment:e.rowBody.fragment,yUndoOptions:o})):e.rowFragmentReadOnly?a.push(jw.configure({fragment:e.rowFragmentReadOnly})):e.syncedDoc?a.push(jw.configure({document:e.syncedDoc})):e.collab&&a.push(jw.configure({document:e.collab.provider.doc,yUndoOptions:o}),Iw.configure({provider:e.collab.provider,user:e.collab.user,render:WY})),a}function WY(e){let t=typeof e.color==`string`&&/^#[0-9a-f]{3,8}$/i.test(e.color)?e.color:`#888`,n=document.createElement(`span`);n.classList.add(`collaboration-carets__caret`),n.style.borderColor=t;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.setAttribute(`aria-hidden`,`true`),r.style.backgroundColor=t,r.textContent=typeof e.name==`string`?e.name:``,n.append(r),n}function GY(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var KY=GY();function qY(e){KY=e}var JY={exec:()=>null};function YY(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(ZY.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var XY=(()=>{try{return!0}catch{return!1}})(),ZY={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},QY=/^(?:[ \t]*(?:\n|$))+/,$Y=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,eX=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,tX=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,nX=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,rX=/(?:[*+-]|\d{1,9}[.)])/,iX=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,aX=YY(iX).replace(/bull/g,rX).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),oX=YY(iX).replace(/bull/g,rX).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),sX=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,cX=/^[^\n]+/,lX=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,uX=YY(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,lX).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),dX=YY(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,rX).getRegex(),fX=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,pX=/\x3C!--(?:-?>|[\s\S]*?(?:-->|$))/,mX=YY(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,pX).replace(`tag`,fX).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),hX=YY(sX).replace(`hr`,tX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fX).getRegex(),gX={blockquote:YY(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,hX).getRegex(),code:$Y,def:uX,fences:eX,heading:nX,hr:tX,html:mX,lheading:aX,list:dX,newline:QY,paragraph:hX,table:JY,text:cX},_X=YY(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,tX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fX).getRegex(),vX={...gX,lheading:oX,table:_X,paragraph:YY(sX).replace(`hr`,tX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,_X).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,fX).getRegex()},yX={...gX,html:YY(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,pX).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:JY,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:YY(sX).replace(`hr`,tX).replace(`heading`,` *#{1,6} *[^ -]`).replace(`lheading`,aX).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},bX=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,xX=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,SX=/^( {2,}|\\)\n(?!\s*$)/,CX=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\`+)[^`]+\k(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,XY?"(?`+)[^`]+\k(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),MX=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,NX=YY(MX,`u`).replace(/punct/g,wX).getRegex(),PX=YY(MX,`u`).replace(/punct/g,OX).getRegex(),FX=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,IX=YY(FX,`gu`).replace(/notPunctSpace/g,EX).replace(/punctSpace/g,TX).replace(/punct/g,wX).getRegex(),LX=YY(FX,`gu`).replace(/notPunctSpace/g,AX).replace(/punctSpace/g,kX).replace(/punct/g,OX).getRegex(),RX=YY(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,EX).replace(/punctSpace/g,TX).replace(/punct/g,wX).getRegex(),zX=YY(/\\(punct)/,`gu`).replace(/punct/g,wX).getRegex(),BX=YY(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),VX=YY(pX).replace(`(?:-->|$)`,`-->`).getRegex(),HX=YY(`^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^`).replace(`comment`,VX).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),UX=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,WX=YY(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace(`label`,UX).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),GX=YY(/^!?\[(label)\]\[(ref)\]/).replace(`label`,UX).replace(`ref`,lX).getRegex(),KX=YY(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,lX).getRegex(),qX=YY(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,GX).replace(`nolink`,KX).getRegex(),JX=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,YX={_backpedal:JY,anyPunctuation:zX,autolink:BX,blockSkip:jX,br:SX,code:xX,del:JY,emStrongLDelim:NX,emStrongRDelimAst:IX,emStrongRDelimUnd:RX,escape:bX,link:WX,nolink:KX,punctuation:DX,reflink:GX,reflinkSearch:qX,tag:HX,text:CX,url:JY},XX={...YX,link:YY(/^!?\[(label)\]\((.*?)\)/).replace(`label`,UX).getRegex(),reflink:YY(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,UX).getRegex()},ZX={...YX,emStrongRDelimAst:LX,emStrongLDelim:PX,url:YY(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,JX).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:YY(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\":`>`,'"':`"`,"'":`'`},nZ=e=>tZ[e];function rZ(e,t){if(t){if(ZY.escapeTest.test(e))return e.replace(ZY.escapeReplace,nZ)}else if(ZY.escapeTestNoEncode.test(e))return e.replace(ZY.escapeReplaceNoEncode,nZ);return e}function iZ(e){try{e=encodeURI(e).replace(ZY.percentDecode,`%`)}catch{return null}return e}function aZ(e,t){let n=e.replace(ZY.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(ZY.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length0?-2:-1}function cZ(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function lZ(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(` +?)[ \r ]*`,qY=`[̀-ͯ]`,JY=RegExp(qY+`+$`),YY=`(`+HY+`+)|`+(KY+`|`)+`([!-\\[\\]-‧‪-퟿豈-￿]`+(qY+`*`)+`|[\ud800-\udbff][\udc00-\udfff]`+(qY+`*`)+`|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5`+(`|`+GY)+(`|`+WY+`)`),XY=class{constructor(e,t){this.input=void 0,this.settings=void 0,this.tokenRegex=void 0,this.catcodes=void 0,this.input=e,this.settings=t,this.tokenRegex=new RegExp(YY,`g`),this.catcodes={"%":14,"~":13}}setCatcode(e,t){this.catcodes[e]=t}lex(){var e=this.input,t=this.tokenRegex.lastIndex;if(t===e.length)return new XJ(`EOF`,new YJ(this,t,t));var n=this.tokenRegex.exec(e);if(n===null||n.index!==t)throw new R(`Unexpected character: '`+e[t]+`'`,new XJ(e[t],new YJ(this,t,t+1)));var r=n[6]||n[3]||(n[2]?`\\ `:` `);if(this.catcodes[r]===14){var i=e.indexOf(` +`,this.tokenRegex.lastIndex);return i===-1?(this.tokenRegex.lastIndex=e.length,this.settings.reportNonstrict(`commentAtEnd`,`% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode (e.g. $)`)):this.tokenRegex.lastIndex=i+1,this.lex()}return new XJ(r,new YJ(this,t,this.tokenRegex.lastIndex))}},ZY=class{constructor(e,t){e===void 0&&(e={}),t===void 0&&(t={}),this.current=void 0,this.builtins=void 0,this.undefStack=void 0,this.current=t,this.builtins=e,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(this.undefStack.length===0)throw new R(`Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug`);var e=this.undefStack.pop();for(var t of Object.keys(e))e[t]===void 0?delete this.current[t]:this.current[t]=e[t]}endGroups(){for(;this.undefStack.length>0;)this.endGroup()}has(e){return Object.prototype.hasOwnProperty.call(this.current,e)||Object.prototype.hasOwnProperty.call(this.builtins,e)}get(e){if(Object.prototype.hasOwnProperty.call(this.current,e))return this.current[e];if(Object.prototype.hasOwnProperty.call(this.builtins,e))return this.builtins[e]}set(e,t,n){if(n===void 0&&(n=!1),n){for(var r=0;r0&&(this.undefStack[this.undefStack.length-1][e]=t)}else{var i=this.undefStack[this.undefStack.length-1];i&&!Object.prototype.hasOwnProperty.call(i,e)&&(i[e]=Object.prototype.hasOwnProperty.call(this.current,e)?this.current[e]:void 0)}t==null?delete this.current[e]:this.current[e]=t}},QY=JJ;$(`\\noexpand`,function(e){var t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}}),$(`\\expandafter`,function(e){var t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}}),$(`\\@firstoftwo`,function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}}),$(`\\@secondoftwo`,function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}}),$(`\\@ifnextchar`,function(e){var t=e.consumeArgs(3);e.consumeSpaces();var n=e.future();return t[0].length===1&&t[0][0].text===n.text?{tokens:t[1],numArgs:0}:{tokens:t[2],numArgs:0}}),$(`\\@ifstar`,`\\@ifnextchar *{\\@firstoftwo{#1}}`),$(`\\TextOrMath`,function(e){var t=e.consumeArgs(2);return e.mode===`text`?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}});var $Y={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15};$(`\\char`,function(e){var t=e.popToken(),n,r=0;if(t.text===`'`)n=8,t=e.popToken();else if(t.text===`"`)n=16,t=e.popToken();else if(t.text==="`"){if(t=e.popToken(),t.text[0]===`\\`)r=t.text.charCodeAt(1);else if(t.text===`EOF`)throw new R("\\char` missing argument");else r=t.text.charCodeAt(0)}else n=10;if(n){if(r=$Y[t.text],r==null||r>=n)throw new R(`Invalid base-`+n+` digit `+t.text);for(var i;(i=$Y[e.future().text])!=null&&i{var i=e.consumeArg().tokens;if(i.length!==1)throw new R(`\\newcommand's first argument must be a macro name`);var a=i[0].text,o=e.isDefined(a);if(o&&!t)throw new R(`\\newcommand{`+a+`} attempting to redefine `+(a+`; use \\renewcommand`));if(!o&&!n)throw new R(`\\renewcommand{`+a+`} when command `+a+` does not yet exist; use \\newcommand`);var s=0;if(i=e.consumeArg().tokens,i.length===1&&i[0].text===`[`){for(var c=``,l=e.expandNextToken();l.text!==`]`&&l.text!==`EOF`;)c+=l.text,l=e.expandNextToken();if(!c.match(/^\s*[0-9]+\s*$/))throw new R(`Invalid number of arguments: `+c);s=parseInt(c),i=e.consumeArg().tokens}return o&&r||e.macros.set(a,{tokens:i,numArgs:s}),``};$(`\\newcommand`,e=>eX(e,!1,!0,!1)),$(`\\renewcommand`,e=>eX(e,!0,!1,!1)),$(`\\providecommand`,e=>eX(e,!0,!0,!0)),$(`\\message`,e=>{var t=e.consumeArgs(1)[0];return console.log(t.reverse().map(e=>e.text).join(``)),``}),$(`\\errmessage`,e=>{var t=e.consumeArgs(1)[0];return console.error(t.reverse().map(e=>e.text).join(``)),``}),$(`\\show`,e=>{var t=e.popToken(),n=t.text;return console.log(t,e.macros.get(n),VY[n],FG.math[n],FG.text[n]),``}),$(`\\bgroup`,`{`),$(`\\egroup`,`}`),$(`~`,`\\nobreakspace`),$(`\\lq`,"`"),$(`\\rq`,`'`),$(`\\aa`,`\\r a`),$(`\\AA`,`\\r A`),$(`\\textcopyright`,"\\html@mathml{\\textcircled{c}}{\\char`©}"),$(`\\copyright`,`\\TextOrMath{\\textcopyright}{\\text{\\textcopyright}}`),$(`\\textregistered`,"\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}"),$(`ℬ`,`\\mathscr{B}`),$(`ℰ`,`\\mathscr{E}`),$(`ℱ`,`\\mathscr{F}`),$(`ℋ`,`\\mathscr{H}`),$(`ℐ`,`\\mathscr{I}`),$(`ℒ`,`\\mathscr{L}`),$(`ℳ`,`\\mathscr{M}`),$(`ℛ`,`\\mathscr{R}`),$(`ℭ`,`\\mathfrak{C}`),$(`ℌ`,`\\mathfrak{H}`),$(`ℨ`,`\\mathfrak{Z}`),$(`\\Bbbk`,`\\Bbb{k}`),$(`\\llap`,`\\mathllap{\\textrm{#1}}`),$(`\\rlap`,`\\mathrlap{\\textrm{#1}}`),$(`\\clap`,`\\mathclap{\\textrm{#1}}`),$(`\\mathstrut`,`\\vphantom{(}`),$(`\\underbar`,`\\underline{\\text{#1}}`),$(`\\not`,`\\html@mathml{\\mathrel{\\mathrlap\\@not}\\nobreak}{\\char"338}`),$(`\\neq`,"\\html@mathml{\\mathrel{\\not=}}{\\mathrel{\\char`≠}}"),$(`\\ne`,`\\neq`),$(`≠`,`\\neq`),$(`\\notin`,"\\html@mathml{\\mathrel{{\\in}\\mathllap{/\\mskip1mu}}}{\\mathrel{\\char`∉}}"),$(`∉`,`\\notin`),$(`≘`,"\\html@mathml{\\mathrel{=\\kern{-1em}\\raisebox{0.4em}{$\\scriptsize\\frown$}}}{\\mathrel{\\char`≘}}"),$(`≙`,"\\html@mathml{\\stackrel{\\tiny\\wedge}{=}}{\\mathrel{\\char`≘}}"),$(`≚`,"\\html@mathml{\\stackrel{\\tiny\\vee}{=}}{\\mathrel{\\char`≚}}"),$(`≛`,"\\html@mathml{\\stackrel{\\scriptsize\\star}{=}}{\\mathrel{\\char`≛}}"),$(`≝`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{def}}{=}}{\\mathrel{\\char`≝}}"),$(`≞`,"\\html@mathml{\\stackrel{\\tiny\\mathrm{m}}{=}}{\\mathrel{\\char`≞}}"),$(`≟`,"\\html@mathml{\\stackrel{\\tiny?}{=}}{\\mathrel{\\char`≟}}"),$(`⟂`,`\\perp`),$(`‼`,`\\mathclose{!\\mkern-0.8mu!}`),$(`∌`,`\\notni`),$(`⌜`,`\\ulcorner`),$(`⌝`,`\\urcorner`),$(`⌞`,`\\llcorner`),$(`⌟`,`\\lrcorner`),$(`©`,`\\copyright`),$(`®`,`\\textregistered`),$(`\\ulcorner`,`\\html@mathml{\\@ulcorner}{\\mathop{\\char"231c}}`),$(`\\urcorner`,`\\html@mathml{\\@urcorner}{\\mathop{\\char"231d}}`),$(`\\llcorner`,`\\html@mathml{\\@llcorner}{\\mathop{\\char"231e}}`),$(`\\lrcorner`,`\\html@mathml{\\@lrcorner}{\\mathop{\\char"231f}}`),$(`\\vdots`,`{\\varvdots\\rule{0pt}{15pt}}`),$(`⋮`,`\\vdots`),$(`\\varGamma`,`\\mathit{\\Gamma}`),$(`\\varDelta`,`\\mathit{\\Delta}`),$(`\\varTheta`,`\\mathit{\\Theta}`),$(`\\varLambda`,`\\mathit{\\Lambda}`),$(`\\varXi`,`\\mathit{\\Xi}`),$(`\\varPi`,`\\mathit{\\Pi}`),$(`\\varSigma`,`\\mathit{\\Sigma}`),$(`\\varUpsilon`,`\\mathit{\\Upsilon}`),$(`\\varPhi`,`\\mathit{\\Phi}`),$(`\\varPsi`,`\\mathit{\\Psi}`),$(`\\varOmega`,`\\mathit{\\Omega}`),$(`\\substack`,`\\begin{subarray}{c}#1\\end{subarray}`),$(`\\colon`,`\\nobreak\\mskip2mu\\mathpunct{}\\mathchoice{\\mkern-3mu}{\\mkern-3mu}{}{}{:}\\mskip6mu\\relax`),$(`\\boxed`,`\\fbox{$\\displaystyle{#1}$}`),$(`\\iff`,`\\DOTSB\\;\\Longleftrightarrow\\;`),$(`\\implies`,`\\DOTSB\\;\\Longrightarrow\\;`),$(`\\impliedby`,`\\DOTSB\\;\\Longleftarrow\\;`),$(`\\dddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ...}}{#1}}`),$(`\\ddddot`,`{\\overset{\\raisebox{-0.1ex}{\\normalsize ....}}{#1}}`);var tX={",":`\\dotsc`,"\\not":`\\dotsb`,"+":`\\dotsb`,"=":`\\dotsb`,"<":`\\dotsb`,">":`\\dotsb`,"-":`\\dotsb`,"*":`\\dotsb`,":":`\\dotsb`,"\\DOTSB":`\\dotsb`,"\\coprod":`\\dotsb`,"\\bigvee":`\\dotsb`,"\\bigwedge":`\\dotsb`,"\\biguplus":`\\dotsb`,"\\bigcap":`\\dotsb`,"\\bigcup":`\\dotsb`,"\\prod":`\\dotsb`,"\\sum":`\\dotsb`,"\\bigotimes":`\\dotsb`,"\\bigoplus":`\\dotsb`,"\\bigodot":`\\dotsb`,"\\bigsqcup":`\\dotsb`,"\\And":`\\dotsb`,"\\longrightarrow":`\\dotsb`,"\\Longrightarrow":`\\dotsb`,"\\longleftarrow":`\\dotsb`,"\\Longleftarrow":`\\dotsb`,"\\longleftrightarrow":`\\dotsb`,"\\Longleftrightarrow":`\\dotsb`,"\\mapsto":`\\dotsb`,"\\longmapsto":`\\dotsb`,"\\hookrightarrow":`\\dotsb`,"\\doteq":`\\dotsb`,"\\mathbin":`\\dotsb`,"\\mathrel":`\\dotsb`,"\\relbar":`\\dotsb`,"\\Relbar":`\\dotsb`,"\\xrightarrow":`\\dotsb`,"\\xleftarrow":`\\dotsb`,"\\DOTSI":`\\dotsi`,"\\int":`\\dotsi`,"\\oint":`\\dotsi`,"\\iint":`\\dotsi`,"\\iiint":`\\dotsi`,"\\iiiint":`\\dotsi`,"\\idotsint":`\\dotsi`,"\\DOTSX":`\\dotsx`},nX=new Set([`bin`,`rel`]);$(`\\dots`,function(e){var t=`\\dotso`,n=e.expandAfterFuture().text;return n in tX?t=tX[n]:(n.slice(0,4)===`\\not`||n in FG.math&&nX.has(FG.math[n].group))&&(t=`\\dotsb`),t});var rX={")":!0,"]":!0,"\\rbrack":!0,"\\}":!0,"\\rbrace":!0,"\\rangle":!0,"\\rceil":!0,"\\rfloor":!0,"\\rgroup":!0,"\\rmoustache":!0,"\\right":!0,"\\bigr":!0,"\\biggr":!0,"\\Bigr":!0,"\\Biggr":!0,$:!0,";":!0,".":!0,",":!0};$(`\\dotso`,function(e){return e.future().text in rX?`\\ldots\\,`:`\\ldots`}),$(`\\dotsc`,function(e){var t=e.future().text;return t in rX&&t!==`,`?`\\ldots\\,`:`\\ldots`}),$(`\\cdots`,function(e){return e.future().text in rX?`\\@cdots\\,`:`\\@cdots`}),$(`\\dotsb`,`\\cdots`),$(`\\dotsm`,`\\cdots`),$(`\\dotsi`,`\\!\\cdots`),$(`\\dotsx`,`\\ldots\\,`),$(`\\DOTSI`,`\\relax`),$(`\\DOTSB`,`\\relax`),$(`\\DOTSX`,`\\relax`),$(`\\tmspace`,`\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax`),$(`\\,`,`\\tmspace+{3mu}{.1667em}`),$(`\\thinspace`,`\\,`),$(`\\>`,`\\mskip{4mu}`),$(`\\:`,`\\tmspace+{4mu}{.2222em}`),$(`\\medspace`,`\\:`),$(`\\;`,`\\tmspace+{5mu}{.2777em}`),$(`\\thickspace`,`\\;`),$(`\\!`,`\\tmspace-{3mu}{.1667em}`),$(`\\negthinspace`,`\\!`),$(`\\negmedspace`,`\\tmspace-{4mu}{.2222em}`),$(`\\negthickspace`,`\\tmspace-{5mu}{.277em}`),$(`\\enspace`,`\\kern.5em `),$(`\\enskip`,`\\hskip.5em\\relax`),$(`\\quad`,`\\hskip1em\\relax`),$(`\\qquad`,`\\hskip2em\\relax`),$(`\\tag`,`\\@ifstar\\tag@literal\\tag@paren`),$(`\\tag@paren`,`\\tag@literal{({#1})}`),$(`\\tag@literal`,e=>{if(e.macros.get(`\\df@tag`))throw new R(`Multiple \\tag`);return`\\gdef\\df@tag{\\text{#1}}`}),$(`\\bmod`,`\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}\\mathbin{\\rm mod}\\mathchoice{\\mskip1mu}{\\mskip1mu}{\\mskip5mu}{\\mskip5mu}`),$(`\\pod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)`),$(`\\pmod`,`\\pod{{\\rm mod}\\mkern6mu#1}`),$(`\\mod`,`\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1`),$(`\\newline`,`\\\\\\relax`),$(`\\TeX`,`\\textrm{\\html@mathml{T\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125emX}{TeX}}`);var iX=z(OG[`Main-Regular`][84][1]-.7*OG[`Main-Regular`][65][1]);$(`\\LaTeX`,`\\textrm{\\html@mathml{`+(`L\\kern-.36em\\raisebox{`+iX+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{LaTeX}}`),$(`\\KaTeX`,`\\textrm{\\html@mathml{`+(`K\\kern-.17em\\raisebox{`+iX+`}{\\scriptstyle A}`)+`\\kern-.15em\\TeX}{KaTeX}}`),$(`\\hspace`,`\\@ifstar\\@hspacer\\@hspace`),$(`\\@hspace`,`\\hskip #1\\relax`),$(`\\@hspacer`,`\\rule{0pt}{0pt}\\hskip #1\\relax`),$(`\\ordinarycolon`,`:`),$(`\\vcentcolon`,`\\mathrel{\\mathop\\ordinarycolon}`),$(`\\dblcolon`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}{\\mathop{\\char"2237}}`),$(`\\coloneqq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2254}}`),$(`\\Coloneqq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}{\\mathop{\\char"2237\\char"3d}}`),$(`\\coloneq`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"3a\\char"2212}}`),$(`\\Coloneq`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}{\\mathop{\\char"2237\\char"2212}}`),$(`\\eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2255}}`),$(`\\Eqqcolon`,`\\html@mathml{\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"3d\\char"2237}}`),$(`\\eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}{\\mathop{\\char"2239}}`),$(`\\Eqcolon`,`\\html@mathml{\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}{\\mathop{\\char"2212\\char"2237}}`),$(`\\colonapprox`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"3a\\char"2248}}`),$(`\\Colonapprox`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}{\\mathop{\\char"2237\\char"2248}}`),$(`\\colonsim`,`\\html@mathml{\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"3a\\char"223c}}`),$(`\\Colonsim`,`\\html@mathml{\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}{\\mathop{\\char"2237\\char"223c}}`),$(`∷`,`\\dblcolon`),$(`∹`,`\\eqcolon`),$(`≔`,`\\coloneqq`),$(`≕`,`\\eqqcolon`),$(`⩴`,`\\Coloneqq`),$(`\\ratio`,`\\vcentcolon`),$(`\\coloncolon`,`\\dblcolon`),$(`\\colonequals`,`\\coloneqq`),$(`\\coloncolonequals`,`\\Coloneqq`),$(`\\equalscolon`,`\\eqqcolon`),$(`\\equalscoloncolon`,`\\Eqqcolon`),$(`\\colonminus`,`\\coloneq`),$(`\\coloncolonminus`,`\\Coloneq`),$(`\\minuscolon`,`\\eqcolon`),$(`\\minuscoloncolon`,`\\Eqcolon`),$(`\\coloncolonapprox`,`\\Colonapprox`),$(`\\coloncolonsim`,`\\Colonsim`),$(`\\simcolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\simcoloncolon`,`\\mathrel{\\sim\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\approxcolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\vcentcolon}`),$(`\\approxcoloncolon`,`\\mathrel{\\approx\\mathrel{\\mkern-1.2mu}\\dblcolon}`),$(`\\notni`,"\\html@mathml{\\not\\ni}{\\mathrel{\\char`∌}}"),$(`\\limsup`,`\\DOTSB\\operatorname*{lim\\,sup}`),$(`\\liminf`,`\\DOTSB\\operatorname*{lim\\,inf}`),$(`\\injlim`,`\\DOTSB\\operatorname*{inj\\,lim}`),$(`\\projlim`,`\\DOTSB\\operatorname*{proj\\,lim}`),$(`\\varlimsup`,`\\DOTSB\\operatorname*{\\overline{lim}}`),$(`\\varliminf`,`\\DOTSB\\operatorname*{\\underline{lim}}`),$(`\\varinjlim`,`\\DOTSB\\operatorname*{\\underrightarrow{lim}}`),$(`\\varprojlim`,`\\DOTSB\\operatorname*{\\underleftarrow{lim}}`),$(`\\gvertneqq`,`\\html@mathml{\\@gvertneqq}{≩}`),$(`\\lvertneqq`,`\\html@mathml{\\@lvertneqq}{≨}`),$(`\\ngeqq`,`\\html@mathml{\\@ngeqq}{≱}`),$(`\\ngeqslant`,`\\html@mathml{\\@ngeqslant}{≱}`),$(`\\nleqq`,`\\html@mathml{\\@nleqq}{≰}`),$(`\\nleqslant`,`\\html@mathml{\\@nleqslant}{≰}`),$(`\\nshortmid`,`\\html@mathml{\\@nshortmid}{∤}`),$(`\\nshortparallel`,`\\html@mathml{\\@nshortparallel}{∦}`),$(`\\nsubseteqq`,`\\html@mathml{\\@nsubseteqq}{⊈}`),$(`\\nsupseteqq`,`\\html@mathml{\\@nsupseteqq}{⊉}`),$(`\\varsubsetneq`,`\\html@mathml{\\@varsubsetneq}{⊊}`),$(`\\varsubsetneqq`,`\\html@mathml{\\@varsubsetneqq}{⫋}`),$(`\\varsupsetneq`,`\\html@mathml{\\@varsupsetneq}{⊋}`),$(`\\varsupsetneqq`,`\\html@mathml{\\@varsupsetneqq}{⫌}`),$(`\\imath`,`\\html@mathml{\\@imath}{ı}`),$(`\\jmath`,`\\html@mathml{\\@jmath}{ȷ}`),$(`\\llbracket`,"\\html@mathml{\\mathopen{[\\mkern-3.2mu[}}{\\mathopen{\\char`⟦}}"),$(`\\rrbracket`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu]}}{\\mathclose{\\char`⟧}}"),$(`⟦`,`\\llbracket`),$(`⟧`,`\\rrbracket`),$(`\\lBrace`,"\\html@mathml{\\mathopen{\\{\\mkern-3.2mu[}}{\\mathopen{\\char`⦃}}"),$(`\\rBrace`,"\\html@mathml{\\mathclose{]\\mkern-3.2mu\\}}}{\\mathclose{\\char`⦄}}"),$(`↤`,`\\mapsfrom`),$(`\\mapsfrom`,"\\html@mathml{\\mathrel{\\mathreflectbox{\\mapsto}}}{\\mathrel{\\char`↤}}"),$(`⦃`,`\\lBrace`),$(`⦄`,`\\rBrace`),$(`\\minuso`,"\\mathbin{\\html@mathml{{\\mathrlap{\\mathchoice{\\kern{0.145em}}{\\kern{0.145em}}{\\kern{0.1015em}}{\\kern{0.0725em}}\\circ}{-}}}{\\char`⦵}}"),$(`⦵`,`\\minuso`),$(`\\darr`,`\\downarrow`),$(`\\dArr`,`\\Downarrow`),$(`\\Darr`,`\\Downarrow`),$(`\\lang`,`\\langle`),$(`\\rang`,`\\rangle`),$(`\\uarr`,`\\uparrow`),$(`\\uArr`,`\\Uparrow`),$(`\\Uarr`,`\\Uparrow`),$(`\\N`,`\\mathbb{N}`),$(`\\R`,`\\mathbb{R}`),$(`\\Z`,`\\mathbb{Z}`),$(`\\alef`,`\\aleph`),$(`\\alefsym`,`\\aleph`),$(`\\Alpha`,`\\mathrm{A}`),$(`\\Beta`,`\\mathrm{B}`),$(`\\bull`,`\\bullet`),$(`\\Chi`,`\\mathrm{X}`),$(`\\clubs`,`\\clubsuit`),$(`\\cnums`,`\\mathbb{C}`),$(`\\Complex`,`\\mathbb{C}`),$(`\\Dagger`,`\\ddagger`),$(`\\diamonds`,`\\diamondsuit`),$(`\\empty`,`\\emptyset`),$(`\\Epsilon`,`\\mathrm{E}`),$(`\\Eta`,`\\mathrm{H}`),$(`\\exist`,`\\exists`),$(`\\harr`,`\\leftrightarrow`),$(`\\hArr`,`\\Leftrightarrow`),$(`\\Harr`,`\\Leftrightarrow`),$(`\\hearts`,`\\heartsuit`),$(`\\image`,`\\Im`),$(`\\infin`,`\\infty`),$(`\\Iota`,`\\mathrm{I}`),$(`\\isin`,`\\in`),$(`\\Kappa`,`\\mathrm{K}`),$(`\\larr`,`\\leftarrow`),$(`\\lArr`,`\\Leftarrow`),$(`\\Larr`,`\\Leftarrow`),$(`\\lrarr`,`\\leftrightarrow`),$(`\\lrArr`,`\\Leftrightarrow`),$(`\\Lrarr`,`\\Leftrightarrow`),$(`\\Mu`,`\\mathrm{M}`),$(`\\natnums`,`\\mathbb{N}`),$(`\\Nu`,`\\mathrm{N}`),$(`\\Omicron`,`\\mathrm{O}`),$(`\\plusmn`,`\\pm`),$(`\\rarr`,`\\rightarrow`),$(`\\rArr`,`\\Rightarrow`),$(`\\Rarr`,`\\Rightarrow`),$(`\\real`,`\\Re`),$(`\\reals`,`\\mathbb{R}`),$(`\\Reals`,`\\mathbb{R}`),$(`\\Rho`,`\\mathrm{P}`),$(`\\sdot`,`\\cdot`),$(`\\sect`,`\\S`),$(`\\spades`,`\\spadesuit`),$(`\\sub`,`\\subset`),$(`\\sube`,`\\subseteq`),$(`\\supe`,`\\supseteq`),$(`\\Tau`,`\\mathrm{T}`),$(`\\thetasym`,`\\vartheta`),$(`\\weierp`,`\\wp`),$(`\\Zeta`,`\\mathrm{Z}`),$(`\\argmin`,`\\DOTSB\\operatorname*{arg\\,min}`),$(`\\argmax`,`\\DOTSB\\operatorname*{arg\\,max}`),$(`\\plim`,`\\DOTSB\\mathop{\\operatorname{plim}}\\limits`),$(`\\bra`,`\\mathinner{\\langle{#1}|}`),$(`\\ket`,`\\mathinner{|{#1}\\rangle}`),$(`\\braket`,`\\mathinner{\\langle{#1}\\rangle}`),$(`\\Bra`,`\\left\\langle#1\\right|`),$(`\\Ket`,`\\left|#1\\right\\rangle`);var aX=e=>t=>{var n=t.consumeArg().tokens,r=t.consumeArg().tokens,i=t.consumeArg().tokens,a=t.consumeArg().tokens,o=t.macros.get(`|`),s=t.macros.get(`\\|`);t.macros.beginGroup();var c=t=>n=>{e&&(n.macros.set(`|`,o),i.length&&n.macros.set(`\\|`,s));var a=t;return!t&&i.length&&n.future().text===`|`&&(n.popToken(),a=!0),{tokens:a?i:r,numArgs:0}};t.macros.set(`|`,c(!1)),i.length&&t.macros.set(`\\|`,c(!0));var l=t.consumeArg().tokens,u=t.expandTokens([...a,...l,...n]);return t.macros.endGroup(),{tokens:u.reverse(),numArgs:0}};$(`\\bra@ket`,aX(!1)),$(`\\bra@set`,aX(!0)),$(`\\Braket`,`\\bra@ket{\\left\\langle}{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}`),$(`\\Set`,`\\bra@set{\\left\\{\\:}{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}`),$(`\\set`,`\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}`),$(`\\angln`,`{\\angl n}`),$(`\\blue`,`\\textcolor{##6495ed}{#1}`),$(`\\orange`,`\\textcolor{##ffa500}{#1}`),$(`\\pink`,`\\textcolor{##ff00af}{#1}`),$(`\\red`,`\\textcolor{##df0030}{#1}`),$(`\\green`,`\\textcolor{##28ae7b}{#1}`),$(`\\gray`,`\\textcolor{gray}{#1}`),$(`\\purple`,`\\textcolor{##9d38bd}{#1}`),$(`\\blueA`,`\\textcolor{##ccfaff}{#1}`),$(`\\blueB`,`\\textcolor{##80f6ff}{#1}`),$(`\\blueC`,`\\textcolor{##63d9ea}{#1}`),$(`\\blueD`,`\\textcolor{##11accd}{#1}`),$(`\\blueE`,`\\textcolor{##0c7f99}{#1}`),$(`\\tealA`,`\\textcolor{##94fff5}{#1}`),$(`\\tealB`,`\\textcolor{##26edd5}{#1}`),$(`\\tealC`,`\\textcolor{##01d1c1}{#1}`),$(`\\tealD`,`\\textcolor{##01a995}{#1}`),$(`\\tealE`,`\\textcolor{##208170}{#1}`),$(`\\greenA`,`\\textcolor{##b6ffb0}{#1}`),$(`\\greenB`,`\\textcolor{##8af281}{#1}`),$(`\\greenC`,`\\textcolor{##74cf70}{#1}`),$(`\\greenD`,`\\textcolor{##1fab54}{#1}`),$(`\\greenE`,`\\textcolor{##0d923f}{#1}`),$(`\\goldA`,`\\textcolor{##ffd0a9}{#1}`),$(`\\goldB`,`\\textcolor{##ffbb71}{#1}`),$(`\\goldC`,`\\textcolor{##ff9c39}{#1}`),$(`\\goldD`,`\\textcolor{##e07d10}{#1}`),$(`\\goldE`,`\\textcolor{##a75a05}{#1}`),$(`\\redA`,`\\textcolor{##fca9a9}{#1}`),$(`\\redB`,`\\textcolor{##ff8482}{#1}`),$(`\\redC`,`\\textcolor{##f9685d}{#1}`),$(`\\redD`,`\\textcolor{##e84d39}{#1}`),$(`\\redE`,`\\textcolor{##bc2612}{#1}`),$(`\\maroonA`,`\\textcolor{##ffbde0}{#1}`),$(`\\maroonB`,`\\textcolor{##ff92c6}{#1}`),$(`\\maroonC`,`\\textcolor{##ed5fa6}{#1}`),$(`\\maroonD`,`\\textcolor{##ca337c}{#1}`),$(`\\maroonE`,`\\textcolor{##9e034e}{#1}`),$(`\\purpleA`,`\\textcolor{##ddd7ff}{#1}`),$(`\\purpleB`,`\\textcolor{##c6b9fc}{#1}`),$(`\\purpleC`,`\\textcolor{##aa87ff}{#1}`),$(`\\purpleD`,`\\textcolor{##7854ab}{#1}`),$(`\\purpleE`,`\\textcolor{##543b78}{#1}`),$(`\\mintA`,`\\textcolor{##f5f9e8}{#1}`),$(`\\mintB`,`\\textcolor{##edf2df}{#1}`),$(`\\mintC`,`\\textcolor{##e0e5cc}{#1}`),$(`\\grayA`,`\\textcolor{##f6f7f7}{#1}`),$(`\\grayB`,`\\textcolor{##f0f1f2}{#1}`),$(`\\grayC`,`\\textcolor{##e3e5e6}{#1}`),$(`\\grayD`,`\\textcolor{##d6d8da}{#1}`),$(`\\grayE`,`\\textcolor{##babec2}{#1}`),$(`\\grayF`,`\\textcolor{##888d93}{#1}`),$(`\\grayG`,`\\textcolor{##626569}{#1}`),$(`\\grayH`,`\\textcolor{##3b3e40}{#1}`),$(`\\grayI`,`\\textcolor{##21242c}{#1}`),$(`\\kaBlue`,`\\textcolor{##314453}{#1}`),$(`\\kaGreen`,`\\textcolor{##71B307}{#1}`);var oX={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0},sX=class{constructor(e,t,n){this.settings=void 0,this.expansionCount=void 0,this.lexer=void 0,this.macros=void 0,this.stack=void 0,this.mode=void 0,this.settings=t,this.expansionCount=0,this.feed(e),this.macros=new ZY(QY,t.macros),this.mode=n,this.stack=[]}feed(e){this.lexer=new XY(e,this.settings)}switchMode(e){this.mode=e}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}endGroups(){this.macros.endGroups()}future(){return this.stack.length===0&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(e){this.stack.push(e)}pushTokens(e){this.stack.push(...e)}scanArgument(e){var t,n,r;if(e){if(this.consumeSpaces(),this.future().text!==`[`)return null;t=this.popToken();var i=this.consumeArg([`]`]);r=i.tokens,n=i.end}else{var a=this.consumeArg();r=a.tokens,t=a.start,n=a.end}return this.pushToken(new XJ(`EOF`,n.loc)),this.pushTokens(r),new XJ(``,YJ.range(t,n))}consumeSpaces(){for(;this.future().text===` `;)this.stack.pop()}consumeArg(e){var t=[],n=e&&e.length>0;n||this.consumeSpaces();var r=this.future(),i,a=0,o=0;do{if(i=this.popToken(),t.push(i),i.text===`{`)++a;else if(i.text===`}`){if(--a,a===-1)throw new R(`Extra }`,i)}else if(i.text===`EOF`)throw new R(`Unexpected end of input in a macro argument, expected '`+(e&&n?e[o]:`}`)+`'`,i);if(e&&n){if((a===0||a===1&&e[o]===`{`)&&i.text===e[o]){if(++o,o===e.length){t.splice(-o,o);break}}else o=0}}while(a!==0||n);return r.text===`{`&&t[t.length-1].text===`}`&&(t.pop(),t.shift()),t.reverse(),{tokens:t,start:r,end:i}}consumeArgs(e,t){if(t){if(t.length!==e+1)throw new R(`The length of delimiters doesn't match the number of args!`);for(var n=t[0],r=0;rthis.settings.maxExpand)throw new R(`Too many expansions: infinite loop or need to increase maxExpand setting`)}expandOnce(e){var t=this.popToken(),n=t.text,r=t.noexpand?null:this._getExpansion(n);if(r==null||e&&r.unexpandable){if(e&&r==null&&n[0]===`\\`&&!this.isDefined(n))throw new R(`Undefined control sequence: `+n);return this.pushToken(t),!1}this.countExpansion(1);var i=r.tokens,a=this.consumeArgs(r.numArgs,r.delimiters);if(r.numArgs){i=i.slice();for(var o=i.length-1;o>=0;--o){var s=i[o];if(s.text===`#`){if(o===0)throw new R(`Incomplete placeholder at end of macro body`,s);if(s=i[--o],s.text===`#`)i.splice(o+1,1);else if(/^[1-9]$/.test(s.text))i.splice(o,2,...a[s.text-1]);else throw new R(`Not a valid argument number`,s)}}}return this.pushTokens(i),i.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(this.expandOnce()===!1){var e=this.stack.pop();return e.treatAsRelax&&(e.text=`\\relax`),e}}expandMacro(e){return this.macros.has(e)?this.expandTokens([new XJ(e)]):void 0}expandTokens(e){var t=[],n=this.stack.length;for(this.pushTokens(e);this.stack.length>n;)if(this.expandOnce(!0)===!1){var r=this.stack.pop();r.treatAsRelax&&=(r.noexpand=!1,!1),t.push(r)}return this.countExpansion(t.length),t}expandMacroAsText(e){var t=this.expandMacro(e);return t&&t.map(e=>e.text).join(``)}_getExpansion(e){var t=this.macros.get(e);if(t==null)return t;if(e.length===1){var n=this.lexer.catcodes[e];if(n!=null&&n!==13)return}var r=typeof t==`function`?t(this):t;if(typeof r==`string`){var i=0;if(r.includes(`#`))for(var a=r.replace(/##/g,``);a.includes(`#`+(i+1));)++i;for(var o=new XY(r,this.settings),s=[],c=o.lex();c.text!==`EOF`;)s.push(c),c=o.lex();return s.reverse(),{tokens:s,numArgs:i}}return r}isDefined(e){return this.macros.has(e)||Object.prototype.hasOwnProperty.call(VY,e)||Object.prototype.hasOwnProperty.call(FG.math,e)||Object.prototype.hasOwnProperty.call(FG.text,e)||Object.prototype.hasOwnProperty.call(oX,e)}isExpandable(e){var t=this.macros.get(e);return t==null?Object.prototype.hasOwnProperty.call(VY,e)&&!VY[e].primitive:typeof t==`string`||typeof t==`function`||!t.unexpandable}},cX=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,lX=Object.freeze({"₊":`+`,"₋":`-`,"₌":`=`,"₍":`(`,"₎":`)`,"₀":`0`,"₁":`1`,"₂":`2`,"₃":`3`,"₄":`4`,"₅":`5`,"₆":`6`,"₇":`7`,"₈":`8`,"₉":`9`,ₐ:`a`,ₑ:`e`,ₕ:`h`,ᵢ:`i`,ⱼ:`j`,ₖ:`k`,ₗ:`l`,ₘ:`m`,ₙ:`n`,ₒ:`o`,ₚ:`p`,ᵣ:`r`,ₛ:`s`,ₜ:`t`,ᵤ:`u`,ᵥ:`v`,ₓ:`x`,ᵦ:`β`,ᵧ:`γ`,ᵨ:`ρ`,ᵩ:`ϕ`,ᵪ:`χ`,"⁺":`+`,"⁻":`-`,"⁼":`=`,"⁽":`(`,"⁾":`)`,"⁰":`0`,"¹":`1`,"²":`2`,"³":`3`,"⁴":`4`,"⁵":`5`,"⁶":`6`,"⁷":`7`,"⁸":`8`,"⁹":`9`,ᴬ:`A`,ᴮ:`B`,ᴰ:`D`,ᴱ:`E`,ᴳ:`G`,ᴴ:`H`,ᴵ:`I`,ᴶ:`J`,ᴷ:`K`,ᴸ:`L`,ᴹ:`M`,ᴺ:`N`,ᴼ:`O`,ᴾ:`P`,ᴿ:`R`,ᵀ:`T`,ᵁ:`U`,ⱽ:`V`,ᵂ:`W`,ᵃ:`a`,ᵇ:`b`,ᶜ:`c`,ᵈ:`d`,ᵉ:`e`,ᶠ:`f`,ᵍ:`g`,ʰ:`h`,ⁱ:`i`,ʲ:`j`,ᵏ:`k`,ˡ:`l`,ᵐ:`m`,ⁿ:`n`,ᵒ:`o`,ᵖ:`p`,ʳ:`r`,ˢ:`s`,ᵗ:`t`,ᵘ:`u`,ᵛ:`v`,ʷ:`w`,ˣ:`x`,ʸ:`y`,ᶻ:`z`,ᵝ:`β`,ᵞ:`γ`,ᵟ:`δ`,ᵠ:`ϕ`,ᵡ:`χ`,ᶿ:`θ`}),uX={"́":{text:`\\'`,math:`\\acute`},"̀":{text:"\\`",math:`\\grave`},"̈":{text:`\\"`,math:`\\ddot`},"̃":{text:`\\~`,math:`\\tilde`},"̄":{text:`\\=`,math:`\\bar`},"̆":{text:`\\u`,math:`\\breve`},"̌":{text:`\\v`,math:`\\check`},"̂":{text:`\\^`,math:`\\hat`},"̇":{text:`\\.`,math:`\\dot`},"̊":{text:`\\r`,math:`\\mathring`},"̋":{text:`\\H`},"̧":{text:`\\c`}},dX={á:`á`,à:`à`,ä:`ä`,ǟ:`ǟ`,ã:`ã`,ā:`ā`,ă:`ă`,ắ:`ắ`,ằ:`ằ`,ẵ:`ẵ`,ǎ:`ǎ`,â:`â`,ấ:`ấ`,ầ:`ầ`,ẫ:`ẫ`,ȧ:`ȧ`,ǡ:`ǡ`,å:`å`,ǻ:`ǻ`,ḃ:`ḃ`,ć:`ć`,ḉ:`ḉ`,č:`č`,ĉ:`ĉ`,ċ:`ċ`,ç:`ç`,ď:`ď`,ḋ:`ḋ`,ḑ:`ḑ`,é:`é`,è:`è`,ë:`ë`,ẽ:`ẽ`,ē:`ē`,ḗ:`ḗ`,ḕ:`ḕ`,ĕ:`ĕ`,ḝ:`ḝ`,ě:`ě`,ê:`ê`,ế:`ế`,ề:`ề`,ễ:`ễ`,ė:`ė`,ȩ:`ȩ`,ḟ:`ḟ`,ǵ:`ǵ`,ḡ:`ḡ`,ğ:`ğ`,ǧ:`ǧ`,ĝ:`ĝ`,ġ:`ġ`,ģ:`ģ`,ḧ:`ḧ`,ȟ:`ȟ`,ĥ:`ĥ`,ḣ:`ḣ`,ḩ:`ḩ`,í:`í`,ì:`ì`,ï:`ï`,ḯ:`ḯ`,ĩ:`ĩ`,ī:`ī`,ĭ:`ĭ`,ǐ:`ǐ`,î:`î`,ǰ:`ǰ`,ĵ:`ĵ`,ḱ:`ḱ`,ǩ:`ǩ`,ķ:`ķ`,ĺ:`ĺ`,ľ:`ľ`,ļ:`ļ`,ḿ:`ḿ`,ṁ:`ṁ`,ń:`ń`,ǹ:`ǹ`,ñ:`ñ`,ň:`ň`,ṅ:`ṅ`,ņ:`ņ`,ó:`ó`,ò:`ò`,ö:`ö`,ȫ:`ȫ`,õ:`õ`,ṍ:`ṍ`,ṏ:`ṏ`,ȭ:`ȭ`,ō:`ō`,ṓ:`ṓ`,ṑ:`ṑ`,ŏ:`ŏ`,ǒ:`ǒ`,ô:`ô`,ố:`ố`,ồ:`ồ`,ỗ:`ỗ`,ȯ:`ȯ`,ȱ:`ȱ`,ő:`ő`,ṕ:`ṕ`,ṗ:`ṗ`,ŕ:`ŕ`,ř:`ř`,ṙ:`ṙ`,ŗ:`ŗ`,ś:`ś`,ṥ:`ṥ`,š:`š`,ṧ:`ṧ`,ŝ:`ŝ`,ṡ:`ṡ`,ş:`ş`,ẗ:`ẗ`,ť:`ť`,ṫ:`ṫ`,ţ:`ţ`,ú:`ú`,ù:`ù`,ü:`ü`,ǘ:`ǘ`,ǜ:`ǜ`,ǖ:`ǖ`,ǚ:`ǚ`,ũ:`ũ`,ṹ:`ṹ`,ū:`ū`,ṻ:`ṻ`,ŭ:`ŭ`,ǔ:`ǔ`,û:`û`,ů:`ů`,ű:`ű`,ṽ:`ṽ`,ẃ:`ẃ`,ẁ:`ẁ`,ẅ:`ẅ`,ŵ:`ŵ`,ẇ:`ẇ`,ẘ:`ẘ`,ẍ:`ẍ`,ẋ:`ẋ`,ý:`ý`,ỳ:`ỳ`,ÿ:`ÿ`,ỹ:`ỹ`,ȳ:`ȳ`,ŷ:`ŷ`,ẏ:`ẏ`,ẙ:`ẙ`,ź:`ź`,ž:`ž`,ẑ:`ẑ`,ż:`ż`,Á:`Á`,À:`À`,Ä:`Ä`,Ǟ:`Ǟ`,Ã:`Ã`,Ā:`Ā`,Ă:`Ă`,Ắ:`Ắ`,Ằ:`Ằ`,Ẵ:`Ẵ`,Ǎ:`Ǎ`,Â:`Â`,Ấ:`Ấ`,Ầ:`Ầ`,Ẫ:`Ẫ`,Ȧ:`Ȧ`,Ǡ:`Ǡ`,Å:`Å`,Ǻ:`Ǻ`,Ḃ:`Ḃ`,Ć:`Ć`,Ḉ:`Ḉ`,Č:`Č`,Ĉ:`Ĉ`,Ċ:`Ċ`,Ç:`Ç`,Ď:`Ď`,Ḋ:`Ḋ`,Ḑ:`Ḑ`,É:`É`,È:`È`,Ë:`Ë`,Ẽ:`Ẽ`,Ē:`Ē`,Ḗ:`Ḗ`,Ḕ:`Ḕ`,Ĕ:`Ĕ`,Ḝ:`Ḝ`,Ě:`Ě`,Ê:`Ê`,Ế:`Ế`,Ề:`Ề`,Ễ:`Ễ`,Ė:`Ė`,Ȩ:`Ȩ`,Ḟ:`Ḟ`,Ǵ:`Ǵ`,Ḡ:`Ḡ`,Ğ:`Ğ`,Ǧ:`Ǧ`,Ĝ:`Ĝ`,Ġ:`Ġ`,Ģ:`Ģ`,Ḧ:`Ḧ`,Ȟ:`Ȟ`,Ĥ:`Ĥ`,Ḣ:`Ḣ`,Ḩ:`Ḩ`,Í:`Í`,Ì:`Ì`,Ï:`Ï`,Ḯ:`Ḯ`,Ĩ:`Ĩ`,Ī:`Ī`,Ĭ:`Ĭ`,Ǐ:`Ǐ`,Î:`Î`,İ:`İ`,Ĵ:`Ĵ`,Ḱ:`Ḱ`,Ǩ:`Ǩ`,Ķ:`Ķ`,Ĺ:`Ĺ`,Ľ:`Ľ`,Ļ:`Ļ`,Ḿ:`Ḿ`,Ṁ:`Ṁ`,Ń:`Ń`,Ǹ:`Ǹ`,Ñ:`Ñ`,Ň:`Ň`,Ṅ:`Ṅ`,Ņ:`Ņ`,Ó:`Ó`,Ò:`Ò`,Ö:`Ö`,Ȫ:`Ȫ`,Õ:`Õ`,Ṍ:`Ṍ`,Ṏ:`Ṏ`,Ȭ:`Ȭ`,Ō:`Ō`,Ṓ:`Ṓ`,Ṑ:`Ṑ`,Ŏ:`Ŏ`,Ǒ:`Ǒ`,Ô:`Ô`,Ố:`Ố`,Ồ:`Ồ`,Ỗ:`Ỗ`,Ȯ:`Ȯ`,Ȱ:`Ȱ`,Ő:`Ő`,Ṕ:`Ṕ`,Ṗ:`Ṗ`,Ŕ:`Ŕ`,Ř:`Ř`,Ṙ:`Ṙ`,Ŗ:`Ŗ`,Ś:`Ś`,Ṥ:`Ṥ`,Š:`Š`,Ṧ:`Ṧ`,Ŝ:`Ŝ`,Ṡ:`Ṡ`,Ş:`Ş`,Ť:`Ť`,Ṫ:`Ṫ`,Ţ:`Ţ`,Ú:`Ú`,Ù:`Ù`,Ü:`Ü`,Ǘ:`Ǘ`,Ǜ:`Ǜ`,Ǖ:`Ǖ`,Ǚ:`Ǚ`,Ũ:`Ũ`,Ṹ:`Ṹ`,Ū:`Ū`,Ṻ:`Ṻ`,Ŭ:`Ŭ`,Ǔ:`Ǔ`,Û:`Û`,Ů:`Ů`,Ű:`Ű`,Ṽ:`Ṽ`,Ẃ:`Ẃ`,Ẁ:`Ẁ`,Ẅ:`Ẅ`,Ŵ:`Ŵ`,Ẇ:`Ẇ`,Ẍ:`Ẍ`,Ẋ:`Ẋ`,Ý:`Ý`,Ỳ:`Ỳ`,Ÿ:`Ÿ`,Ỹ:`Ỹ`,Ȳ:`Ȳ`,Ŷ:`Ŷ`,Ẏ:`Ẏ`,Ź:`Ź`,Ž:`Ž`,Ẑ:`Ẑ`,Ż:`Ż`,ά:`ά`,ὰ:`ὰ`,ᾱ:`ᾱ`,ᾰ:`ᾰ`,έ:`έ`,ὲ:`ὲ`,ή:`ή`,ὴ:`ὴ`,ί:`ί`,ὶ:`ὶ`,ϊ:`ϊ`,ΐ:`ΐ`,ῒ:`ῒ`,ῑ:`ῑ`,ῐ:`ῐ`,ό:`ό`,ὸ:`ὸ`,ύ:`ύ`,ὺ:`ὺ`,ϋ:`ϋ`,ΰ:`ΰ`,ῢ:`ῢ`,ῡ:`ῡ`,ῠ:`ῠ`,ώ:`ώ`,ὼ:`ὼ`,Ύ:`Ύ`,Ὺ:`Ὺ`,Ϋ:`Ϋ`,Ῡ:`Ῡ`,Ῠ:`Ῠ`,Ώ:`Ώ`,Ὼ:`Ὼ`},fX=class e{constructor(e,t){this.mode=void 0,this.gullet=void 0,this.settings=void 0,this.leftrightDepth=void 0,this.nextToken=void 0,this.mode=`math`,this.gullet=new sX(e,t,this.mode),this.settings=t,this.leftrightDepth=0,this.nextToken=null}expect(e,t){if(t===void 0&&(t=!0),this.fetch().text!==e)throw new R(`Expected '`+e+`', got '`+this.fetch().text+`'`,this.fetch());t&&this.consume()}consume(){this.nextToken=null}fetch(){return this.nextToken??=this.gullet.expandNextToken(),this.nextToken}switchMode(e){this.mode=e,this.gullet.switchMode(e)}parse(){this.settings.globalGroup||this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set(`\\color`,`\\textcolor`);try{var e=this.parseExpression(!1);return this.expect(`EOF`),this.settings.globalGroup||this.gullet.endGroup(),e}finally{this.gullet.endGroups()}}subparse(e){var t=this.nextToken;this.consume(),this.gullet.pushToken(new XJ(`}`)),this.gullet.pushTokens(e);var n=this.parseExpression(!1);return this.expect(`}`),this.nextToken=t,n}parseExpression(t,n){for(var r=[];;){this.mode===`math`&&this.consumeSpaces();var i=this.fetch();if(e.endOfExpression.has(i.text)||n&&i.text===n||t&&VY[i.text]&&VY[i.text].infix)break;var a=this.parseAtom(n);if(!a)break;a.type!==`internal`&&r.push(a)}return this.mode===`text`&&this.formLigatures(r),this.handleInfixNodes(r)}handleInfixNodes(e){for(var t=-1,n,r=0;r=128)this.settings.strict&&(GW(t.charCodeAt(0))?this.mode===`math`&&this.settings.reportNonstrict(`unicodeTextInMathMode`,`Unicode text character "`+t[0]+`" used in math mode`,e):this.settings.reportNonstrict(`unknownSymbol`,`Unrecognized Unicode character "`+t[0]+`"`+(` (`+t.charCodeAt(0)+`)`),e)),a={type:`textord`,mode:`text`,loc:YJ.range(e),text:t};else return null;if(this.consume(),i)for(var c=0;ce.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertBlockMath:e=>({commands:t,editor:n})=>{let{latex:r,pos:i}=e;return r?t.insertContentAt(i??n.state.selection.from,{type:this.name,attrs:{latex:r}}):!1},deleteBlockMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateBlockMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r??a.attrs.latex}),!0)}}},parseHTML(){return[{tag:`div[data-type="block-math"]`}]},renderHTML({HTMLAttributes:e}){return[`div`,j(e,{"data-type":`block-math`})]},parseMarkdown:e=>({type:`blockMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>[`$$`,e.attrs?.latex||``,`$$`].join(` +`),markdownTokenizer:{name:`blockMath`,level:`block`,start:e=>e.indexOf(`$$`),tokenize:e=>{let t=e.match(/^\$\$([^$]+)\$\$/);if(!t)return;let[n,r]=t;return{type:`blockMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new cp({find:/^\$\$\$([^$]+)\$\$\$$/,handler:({state:e,range:t,match:n})=>{let[,r]=n,{tr:i}=e,a=e.doc.resolve(t.from),o=this.type.create({latex:r}),s=a.depth>0&&a.parent.isTextblock&&t.from===a.start()&&t.to===a.end()&&a.node(-1).canReplaceWith(a.index(-1),a.indexAfter(-1),this.type)?{from:a.before(),to:a.after()}:t;i.replaceWith(s.from,s.to,o)}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`div`),i=document.createElement(`div`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),i.className=`block-math-inner`,r.dataset.type=`block-math`,r.setAttribute(`data-latex`,t.attrs.latex),r.appendChild(i);function a(){try{yX.render(t.attrs.latex,i,e),r.classList.remove(`block-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`block-math-error`)}}let o=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,o),a(),{dom:r,destroy(){r.removeEventListener(`click`,o)}}}}}),xX=e=>{let t=/\$\$([^$\n]+?)\$\$(?!\$)/g,n=t.exec(e);for(;n!==null;){if(n.index===0||e[n.index-1]!==`$`)return{index:n.index,text:n[0],data:{latex:n[1]}};t.lastIndex=n.index+1,n=t.exec(e)}return null},SX=qp.create({name:`inlineMath`,group:`inline`,inline:!0,atom:!0,addOptions(){return{onClick:void 0,katexOptions:void 0}},addAttributes(){return{latex:{default:``,parseHTML:e=>e.getAttribute(`data-latex`),renderHTML:e=>({"data-latex":e.latex})}}},addCommands(){return{insertInlineMath:e=>({editor:t,tr:n})=>{let r=e.latex,i=e?.pos??t.state.selection.from;return r?(n.replaceWith(i,i,this.type.create({latex:r})),!0):!1},deleteInlineMath:e=>({editor:t,tr:n})=>{let r=e?.pos??t.state.selection.$from.pos,i=t.state.doc.nodeAt(r);return!i||i.type.name!==this.name?!1:(n.delete(r,r+i.nodeSize),!0)},updateInlineMath:e=>({editor:t,tr:n})=>{let r=e?.latex,i=e?.pos;i===void 0&&(i=t.state.selection.$from.pos);let a=t.state.doc.nodeAt(i);return!a||a.type.name!==this.name?!1:(n.setNodeMarkup(i,this.type,{...a.attrs,latex:r}),!0)}}},parseHTML(){return[{tag:`span[data-type="inline-math"]`}]},renderHTML({HTMLAttributes:e}){return[`span`,j(e,{"data-type":`inline-math`})]},parseMarkdown:e=>({type:`inlineMath`,attrs:{latex:e.latex}}),renderMarkdown:e=>`$${e.attrs?.latex||``}$`,markdownTokenizer:{name:`inlineMath`,level:`inline`,start:e=>e.indexOf(`$`),tokenize:e=>{let t=e.match(/^\$([^$]+)\$(?!\$)/);if(!t)return;let[n,r]=t;return{type:`inlineMath`,raw:n,latex:r.trim()}}},addInputRules(){return[new cp({find:xX,handler:({state:e,range:t,match:n})=>{let r=n.data?.latex;if(typeof r!=`string`)return null;let{tr:i}=e,a=t.from,o=t.to;i.replaceWith(a,o,this.type.create({latex:r}))}})]},addNodeView(){let{katexOptions:e}=this.options;return({node:t,getPos:n})=>{let r=document.createElement(`span`);r.className=`tiptap-mathematics-render`,this.editor.isEditable&&r.classList.add(`tiptap-mathematics-render--editable`),r.dataset.type=`inline-math`,r.setAttribute(`data-latex`,t.attrs.latex);function i(){try{yX.render(t.attrs.latex,r,e),r.classList.remove(`inline-math-error`)}catch{r.textContent=t.attrs.latex,r.classList.add(`inline-math-error`)}}let a=e=>{e.preventDefault(),e.stopPropagation();let r=n();r!=null&&this.options.onClick&&this.options.onClick(t,r)};return this.options.onClick&&r.addEventListener(`click`,a),i(),{dom:r,destroy(){r.removeEventListener(`click`,a)}}}}}),CX=wp.create({name:`Mathematics`,addOptions(){return{inlineOptions:void 0,blockOptions:void 0,katexOptions:void 0}},addExtensions(){return[bX.configure({...this.options.blockOptions,katexOptions:this.options.katexOptions}),SX.configure({...this.options.inlineOptions,katexOptions:this.options.katexOptions})]}});function wX(e,t){let n=n=>(r,i)=>{let a=t();if(!a?.isEditable)return;let o=a.view.nodeDOM(i);if(!(o instanceof HTMLElement))return;let s=e.blocks;tU({anchor:o,value:String(r.attrs.latex??``),label:s.latex,multiline:n===`block`,monospace:!0,labels:{done:s.done,cancel:s.cancel,remove:s.remove},onSave:e=>{let t=a.chain().setNodeSelection(i);e.trim()?(n===`inline`?t.updateInlineMath({latex:e,pos:i}):t.updateBlockMath({latex:e,pos:i})).focus().run():(n===`inline`?t.deleteInlineMath({pos:i}):t.deleteBlockMath({pos:i})).focus().run()},onRemove:()=>{let e=a.chain();(n===`inline`?e.deleteInlineMath({pos:i}):e.deleteBlockMath({pos:i})).focus().run()}})};return CX.configure({katexOptions:{throwOnError:!1,strict:!1,trust:!1},inlineOptions:{onClick:n(`inline`)},blockOptions:{onClick:n(`block`)}})}function TX({editor:e,overrideSuggestionOptions:t,extensionName:n,char:r=`@`}){return{editor:e,char:r,pluginKey:new O,command:({editor:e,range:t,props:i})=>{var a,o;let s=e.view.state.selection.$to.nodeAfter;s!=null&&(a=s.text)!=null&&a.startsWith(` `)&&(t.to+=1),e.chain().focus().insertContentAt(t,[{type:n,attrs:{...i,mentionSuggestionChar:r}},{type:`text`,text:` `}]).run(),(o=e.view.dom.ownerDocument.defaultView)==null||(o=o.getSelection())==null||o.collapseToEnd()},allow:({state:e,range:t})=>{let r=e.doc.resolve(t.from),i=e.schema.nodes[n];return!!r.parent.type.contentMatch.matchType(i)},...t}}function EX(e){return(e.options.suggestions.length?e.options.suggestions:[e.options.suggestion]).map(t=>TX({editor:e.editor,overrideSuggestionOptions:t,extensionName:e.name,char:t.char}))}function DX(e,t){let n=EX(e);return n.find(e=>e.char===t)||(n.length?n[0]:null)}var OX=qp.create({name:`mention`,priority:101,addOptions(){return{HTMLAttributes:{},renderText({node:e,suggestion:t}){return`${t?.char??`@`}${e.attrs.label??e.attrs.id}`},deleteTriggerWithBackspace:!1,renderHTML({options:e,node:t,suggestion:n}){return[`span`,j(this.HTMLAttributes,e.HTMLAttributes),`${n?.char??`@`}${t.attrs.label??t.attrs.id}`]},suggestions:[],suggestion:{}}},group:`inline`,inline:!0,selectable:!1,atom:!0,addAttributes(){return{id:{default:null,parseHTML:e=>e.getAttribute(`data-id`),renderHTML:e=>e.id?{"data-id":e.id}:{}},label:{default:null,parseHTML:e=>e.getAttribute(`data-label`),renderHTML:e=>e.label?{"data-label":e.label}:{}},mentionSuggestionChar:{default:`@`,parseHTML:e=>e.getAttribute(`data-mention-suggestion-char`),renderHTML:e=>({"data-mention-suggestion-char":e.mentionSuggestionChar})}}},parseHTML(){return[{tag:`span[data-type="${this.name}"]`}]},renderHTML({node:e,HTMLAttributes:t}){let n=DX(this,e.attrs.mentionSuggestionChar);if(this.options.renderLabel!==void 0)return console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),[`span`,j({"data-type":this.name},this.options.HTMLAttributes,t),this.options.renderLabel({options:this.options,node:e,suggestion:n})];let r={...this.options};r.HTMLAttributes=j({"data-type":this.name},this.options.HTMLAttributes,t);let i=this.options.renderHTML({options:r,node:e,suggestion:n});return typeof i==`string`?[`span`,j({"data-type":this.name},this.options.HTMLAttributes,t),i]:i},...Qf({nodeName:`mention`,name:`@`,selfClosing:!0,allowedAttributes:[`id`,`label`,{name:`mentionSuggestionChar`,skipIfDefault:`@`}],parseAttributes:e=>{let t={},n=/(?:^|\s)(\w+)=(?:"([^"]*)"|'([^']*)')/g,r=n.exec(e);for(;r!==null;){let[,i,a,o]=r;t[i===`char`?`mentionSuggestionChar`:i]=a??o,r=n.exec(e)}return t},serializeAttributes:e=>Object.entries(e).filter(([,e])=>e!=null).map(([e,t])=>`${e===`mentionSuggestionChar`?`char`:e}="${t}"`).join(` `)}),renderText({node:e}){let t={options:this.options,node:e,suggestion:DX(this,e.attrs.mentionSuggestionChar)};return this.options.renderLabel===void 0?this.options.renderText(t):(console.warn(`renderLabel is deprecated use renderText and renderHTML instead`),this.options.renderLabel(t))},addKeyboardShortcuts(){return{Backspace:()=>this.editor.commands.command(({tr:e,state:t})=>{let n=!1,{selection:r}=t,{empty:i,anchor:a}=r;if(!i)return!1;let o=new ce,s=0;return t.doc.nodesBetween(a-1,a,(e,t)=>{if(e.type.name===this.name)return n=!0,o=e,s=t,!1}),n&&e.insertText(this.options.deleteTriggerWithBackspace?``:o.attrs.mentionSuggestionChar,s,s+o.nodeSize),n})}},addProseMirrorPlugins(){return EX(this).map(OH)}});function kX(e,t){return OX.configure({HTMLAttributes:{class:`dw-mention`},renderText:({node:e})=>`@${e.attrs.label??e.attrs.id}`,suggestion:{char:`@`,allow:()=>!!t,findSuggestionMatch:t=>{let n=mH({...t,allowSpaces:!0});return n&&lH(n.query,e)?n:mH({...t,allowSpaces:!1})},items:async({query:n})=>{if(!t)return[];let r=cH(n,e,!!t.me).map(e=>({date:e})),i=(await t.search(n).catch(()=>[])).map(e=>({person:e}));return n.trim()?[...r,...i].slice(0,8):[...i.slice(0,6),...r]},render:Hj({label:e.mentions,empty:e.noPeople,toItem:t=>`person`in t?{label:t.person.label,description:t.person.hint,icon:`at`}:{label:oH(t.date.date,e),description:t.date.remind?`${e.dates.remindMe} · ${sH(t.date.date,e)}`:sH(t.date.date,e),icon:t.date.remind?`bell`:`calendar`},pick:(e,n)=>{`person`in n?e.command({id:n.person.id,label:n.person.label}):fH(e.editor,e.range,n.date,t?.me)}})}})}var AX=`flowchart LR + Idea --> Draft --> Review --> Published`,jX=null;function MX(e){return jX??=e().then(e=>(e.initialize({startOnLoad:!1,securityLevel:`strict`,theme:document.documentElement.classList.contains(`dark`)?`dark`:`neutral`,fontFamily:`inherit`}),e)),jX}var NX=0;async function PX(e,t,n,r){if(e.classList.remove(`dw-mermaid__body--error`),!t.trim())e.textContent=``;else if(r)try{let{svg:n}=await(await MX(r)).render(`dw-mermaid-${++NX}`,t);e.innerHTML=n}catch(t){e.classList.add(`dw-mermaid__body--error`),e.textContent=`${n.blocks.mermaidError} ${t instanceof Error?t.message:String(t)}`}else{let n=document.createElement(`pre`);n.className=`dw-mermaid__source`,n.textContent=t,e.replaceChildren(n)}}var FX=qp.create({name:`mermaid`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null,load:void 0}},addAttributes(){return{code:{default:``,parseHTML:e=>e.getAttribute(`data-code`)??e.textContent??``,renderHTML:e=>({"data-code":e.code})}}},parseHTML(){return[{tag:`div[data-type='mermaid']`},{tag:`pre.mermaid`}]},renderHTML({node:e,HTMLAttributes:t}){return[`div`,j(t,{"data-type":`mermaid`}),[`pre`,{},String(e.attrs.code)]]},addCommands(){return{insertMermaid:(e=AX)=>({commands:t})=>t.insertContent({type:this.name,attrs:{code:e}})}},addNodeView(){return({node:e,editor:t,getPos:n})=>{let r=this.options.labels,i=this.options.load,a=document.createElement(`div`);a.className=`dw-mermaid`,a.setAttribute(`data-type`,`mermaid`);let o=document.createElement(`div`);o.className=`dw-mermaid__body`,a.append(o);let s=String(e.attrs.code);return PX(o,s,r,i),a.addEventListener(`click`,()=>{if(!t.isEditable)return;let e=typeof n==`function`?n():void 0;if(e===void 0)return;let c=r.blocks;tU({anchor:a,value:s,label:c.mermaid,multiline:!0,monospace:!0,labels:{done:c.done,cancel:c.cancel,remove:c.remove},onInput:e=>void PX(o,e,r,i),onSave:n=>{t.chain().setNodeSelection(e).updateAttributes(`mermaid`,{code:n}).run(),PX(o,n,r,i)},onRemove:()=>t.chain().setNodeSelection(e).deleteSelection().focus().run(),onCancel:()=>void PX(o,s,r,i)})}),{dom:a,update:e=>e.type.name===`mermaid`&&(e.attrs.code!==s&&(s=String(e.attrs.code),PX(o,s,r,i)),!0),ignoreMutation:()=>!0,stopEvent:()=>!1}}}});function IX(e){return new Promise(t=>{let n=document.createElement(`input`);n.type=`file`,n.accept=e,n.multiple=!0,n.onchange=()=>t([...n.files??[]]),n.click()})}function LX(e,t,n,r,i=!1,a,o=!!r?.children){let s=(t,n,r,i)=>({id:t,icon:n,keywords:r,label:e.slash[t]?.label??t,description:e.slash[t]?.description??``,run:i}),c=[s(`text`,`text`,[`paragraph`,`p`],(e,t)=>e.chain().focus().deleteRange(t).setParagraph().run()),s(`h1`,`heading`,[`heading`,`title`,`#`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:1}).run()),s(`h2`,`heading`,[`heading`,`subtitle`,`##`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:2}).run()),s(`h3`,`heading`,[`heading`,`###`],(e,t)=>e.chain().focus().deleteRange(t).setHeading({level:3}).run()),{...s(`otherHeadings`,`heading`,[`other`,`more headings`,`smaller`],()=>{}),children:[4,5,6].map(e=>s(`h${e}`,`heading`,[`heading`,`#`.repeat(e)],(t,n)=>t.chain().focus().deleteRange(n).setHeading({level:e}).run()))},s(`bullet`,`list`,[`list`,`ul`,`-`],(e,t)=>e.chain().focus().deleteRange(t).toggleBulletList().run()),s(`ordered`,`list-ordered`,[`list`,`ol`,`1.`],(e,t)=>e.chain().focus().deleteRange(t).toggleOrderedList().run()),s(`todo`,`todo`,[`task`,`checkbox`,`checklist`,`[]`],(e,t)=>e.chain().focus().deleteRange(t).toggleTaskList().run()),s(`callout`,`callout`,[`note`,`info`,`tip`,`warning`,`aside`,`box`],(e,t)=>e.chain().focus().deleteRange(t).setCallout().run()),{...s(`columns`,`columns`,[`layout`,`side by side`,`split`,`grid`,`multi-column`],()=>{}),children:[2,3,4,5].map(e=>s(`columns${e}`,`columns`,[`columns`,`layout`,`side by side`,String(e)],(t,n)=>t.chain().focus().deleteRange(n).insertColumns(e).run()))},s(`table`,`table`,[`grid`,`rows`,`columns`,`spreadsheet`],(e,t)=>e.chain().focus().deleteRange(t).insertTable({rows:3,cols:3,withHeaderRow:!0}).run()),s(`database`,`database`,[`kanban`,`board`,`calendar`,`records`,`tracker`,`notion`],(e,t)=>e.chain().focus().deleteRange(t).insertDatabase().run()),s(`quote`,`quote`,[`blockquote`,`>`],(e,t)=>e.chain().focus().deleteRange(t).toggleBlockquote().run()),s(`code`,`code`,[`codeblock`,"```",`snippet`],(e,t)=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()),s(`tabs`,`tabs`,[`tab`,`tabbed`,`switch`,`panes`],(e,t)=>e.chain().focus().deleteRange(t).insertTabs().run()),s(`toggle`,`chevron-right`,[`details`,`collapse`,`expand`,`fold`,`>`],(e,t)=>e.chain().focus().deleteRange(t).setDetails().run()),s(`divider`,`divider`,[`hr`,`rule`,`line`,`---`],(e,t)=>e.chain().focus().deleteRange(t).setHorizontalRule().run()),s(`pageBreak`,`page-break`,[`print`,`new page`,`break`,`pdf`],(e,t)=>e.chain().focus().deleteRange(t).setPageBreak().run()),s(`footnote`,`footnote`,[`note`,`reference`,`citation`,`source`,`fn`],(e,t)=>e.chain().focus().deleteRange(t).insertFootnote().run()),s(`status`,`status`,[`badge`,`label`,`state`,`progress`,`tag`],(e,t)=>e.chain().focus().deleteRange(t).insertStatus().run()),s(`emoji`,`smile`,[`emoticon`,`smiley`,`:`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`:`).run()),s(`toc`,`list`,[`contents`,`outline`,`headings`,`index`],(e,t)=>e.chain().focus().deleteRange(t).insertTableOfContents().run()),s(`math`,`sigma`,[`latex`,`formula`,`equation`,`katex`,`$$`],(e,t)=>e.chain().focus().deleteRange(t).insertBlockMath({latex:`E = mc^2`}).run()),s(`mathInline`,`sigma`,[`latex`,`formula`,`equation`,`$`],(e,t)=>e.chain().focus().deleteRange(t).insertInlineMath({latex:`x^2`}).run()),s(`mermaid`,`diagram`,[`diagram`,`flowchart`,`chart`,`sequence`,`graph`],(e,t)=>e.chain().focus().deleteRange(t).insertMermaid().run()),s(`embed`,`video`,[`video`,`youtube`,`vimeo`,`figma`,`loom`,`iframe`,`map`],(t,r)=>{t.chain().focus().deleteRange(r).run(),cU(t,e,a,n)}),s(`linkCard`,`link`,[`bookmark`,`preview`,`card`,`url`,`web`],(t,r)=>{t.chain().focus().deleteRange(r).run(),lU(t,e,a,n)})],l=e=>{let t=new Date;return nH(new Date(t.getFullYear(),t.getMonth(),t.getDate()+e))};if(c.push(s(`today`,`calendar`,[`date`,`day`],(e,t)=>fH(e,t,{date:l(0),remind:!1})),s(`tomorrow`,`calendar`,[`date`,`day`],(e,t)=>fH(e,t,{date:l(1),remind:!1})),s(`yesterday`,`calendar`,[`date`,`day`],(e,t)=>fH(e,t,{date:l(-1),remind:!1})),s(`now`,`clock`,[`time`,`date`,`timestamp`],(t,n)=>{fH(t,n,{date:l(0),remind:!1});let r=new Intl.DateTimeFormat(e.locale,{hour:`numeric`,minute:`2-digit`}).format(new Date);t.chain().focus().insertContent(`${r} `).run()})),r&&(c.push(s(`pageLink`,`link`,[`page`,`link`,`[[`,`wiki`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`[[`).run())),c.push(s(`syncedPage`,`copy`,[`embed`,`transclude`,`include`,`mirror`,`![[`],(e,t)=>e.chain().focus().deleteRange(t).insertContent(`![[`).run())),c.push(s(`syncedBlock`,`copy`,[`sync`,`transclude`,`mirror`,`reuse`,`block`],(t,r)=>{t.chain().focus().deleteRange(r).run();let i=window.prompt(e.blocks.syncedBlockUrl,``);if(i===null||!i.trim())return;let a=zH(i);a?t.chain().focus().insertSyncedPage({id:a.page,title:``,block:a.block}).run():n?.(Error(e.blocks.syncedBlockInvalid))})),r.create&&c.push(s(`newPage`,`page-plus`,[`page`,`doc`,`subpage`,`create`],(e,t)=>{e.chain().focus().deleteRange(t).run(),PH(e,r,``).catch(n)}))),o&&c.push(s(`subpages`,`layers`,[`children`,`child pages`,`sub pages`,`index`,`contents`],(e,t)=>e.chain().focus().deleteRange(t).insertSubpages().run())),t?.upload){let e=e=>(r,i)=>{r.chain().focus().deleteRange(i).run(),IX(e).then(e=>gU(r,t,e).catch(n))},r=e=>(r,i)=>{r.chain().focus().deleteRange(i).run(),IX(e).then(async e=>{for(let n of e){let e=await t.upload(n),i=KU(e.mime,e.name),a=i?{type:i,attrs:{src:e.url,name:e.name,mime:e.mime}}:{type:`fileAttachment`,attrs:{url:e.url,name:e.name,size:e.size,mime:e.mime}};r.chain().focus().insertContentAt(r.state.selection.to,a).run()}}).catch(n)};c.push(s(`image`,`image`,[`picture`,`photo`,`img`],e(`image/*`)),s(`video`,`video`,[`movie`,`clip`,`mp4`,`player`],r(`video/*`)),s(`audio`,`music`,[`sound`,`recording`,`podcast`,`mp3`,`voice`],r(`audio/*`)),s(`file`,`paperclip`,[`attachment`,`upload`,`pdf`],e(``)),s(`drawio`,`diagram`,[`diagram`,`diagrams.net`,`draw`,`chart`,`uml`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`drawio`).run())),i&&c.push(s(`excalidraw`,`pencil`,[`drawing`,`sketch`,`whiteboard`,`draw`],(e,t)=>e.chain().focus().deleteRange(t).insertDiagram(`excalidraw`).run()))}return c}function RX(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=e=>e.label.toLowerCase().includes(n)||e.id.startsWith(n)||e.keywords.some(e=>e.toLowerCase().startsWith(n));return e.flatMap(e=>{let t=e.children?.filter(r)??[];return t.length?t:r(e)?[e]:[]})}var zX=wp.create({name:`slashMenu`,addOptions(){return{commands:[],labels:void 0}},addProseMirrorPlugins(){return[kH({editor:this.editor,pluginKey:new O(`slashMenu`),char:`/`,allowSpaces:!1,startOfLine:!1,allow:({state:e,range:t})=>!e.doc.resolve(t.from).parent.type.spec.code,items:({query:e})=>RX(this.options.commands,e),render:Hj({label:this.options.labels.slashMenu,empty:this.options.labels.noMatches,showQuery:!0,toItem:e=>({label:e.label,description:e.description,icon:e.icon}),children:e=>e.children,pick:(e,t)=>t.run(e.editor,e.range)})})]}}),BX=`suggestInsert`,VX=`suggestDelete`,HX=`suggestionSkip`,UX=new O(`suggestions`),WX=()=>Math.random().toString(36).slice(2,10);function GX(e,t){return gp.create({name:e,inclusive:!1,excludes:``,priority:1100,addAttributes(){return{id:{default:``,parseHTML:e=>e.getAttribute(`data-suggestion`)??``},author:{default:``,parseHTML:e=>e.getAttribute(`data-author`)??``},name:{default:``,parseHTML:e=>e.getAttribute(`data-name`)??``},at:{default:0,parseHTML:e=>Number(e.getAttribute(`data-at`))||0}}},parseHTML(){return[{tag:`${t}[data-suggestion]`}]},renderHTML({mark:e,HTMLAttributes:n}){let r=e.attrs;return[t,j({class:t===`ins`?`dw-suggest-ins`:`dw-suggest-del`},{"data-suggestion":r.id,"data-author":r.author,"data-name":r.name,"data-at":String(r.at),title:r.name},Object.fromEntries(Object.entries(n).filter(([e])=>e===`class`||e===`style`))),0]}})}var KX=GX(BX,`ins`),qX=GX(VX,`del`),JX=(e,t)=>e.marks.find(e=>e.type===t);function YX(e,t){let n=new Map;return e.descendants((e,r)=>{if(!e.isInline)return!0;for(let i of e.marks){if(i.type.name!==BX&&i.type.name!==VX)continue;let a=String(i.attrs.id);if(t&&a!==t)continue;let o=n.get(a)??[],s=i.type.name===BX,c=o[o.length-1];c&&c.to===r&&c.insert===s?c.to=r+e.nodeSize:o.push({from:r,to:r+e.nodeSize,insert:s}),n.set(a,o)}return!1}),n}function XX(e,t,n){let r=YX(e.doc,n);if(!r.size)return!1;let i=e.doc.type.schema,a=[];for(let n of r.values())for(let r of n){let n=i.marks[r.insert?BX:VX];r.insert===t?e.removeMark(r.from,r.to,n):a.push(r)}a.sort((e,t)=>t.from-e.from);for(let t of a)e.delete(t.from,t.to);return e.setMeta(HX,!0),!0}function ZX(e){let t=!1;return e.descendants(e=>(e.isInline&&(t=!0),!t)),t}function QX(e,t,n,r,i){let a=[];return e.forEach(e=>{if(e.isInline){let o=JX(e,n);if(o&&o.attrs.author===i)return;a.push(JX(e,t)?e:e.mark(t.create(r).addToSet(e.marks)))}else a.push(e.copy(QX(e.content,t,n,r,i)))}),s.from(a)}function $X(e,t,n,r){let i=e.resolve(Math.min(Math.max(t,0),e.content.size));for(let e of[i.nodeBefore,i.nodeAfter]){let t=e&&JX(e,n);if(t&&t.attrs.author===r)return t.attrs}return null}function eZ(e,t,n,r){if(!e.steps.length||!e.steps.every(e=>e instanceof Et))return null;let i=n.schema,a=i.marks[BX],o=i.marks[VX],s=n.tr,c=Date.now(),l=null,u=e.steps.length===1;if(e.steps.forEach((n,i)=>{let d=n,f=e.docs[i].slice(d.from,d.to),m=s.mapping.map(e.mapping.slice(i+1).map(d.from,-1),-1),h=d.slice.size;if(h>0&&ZX(d.slice.content)){let e=m+h,t=$X(s.doc,m,a,r.id)??$X(s.doc,e,a,r.id)??{id:WX(),author:r.id,name:r.name,at:c};s.doc.nodesBetween(m,e,(n,r)=>{if(!n.isInline)return!0;let i=Math.max(r,m),c=Math.min(r+n.nodeSize,e);return JX(n,o)&&s.removeMark(i,c,o),s.addMark(i,c,a.create(t)),!1})}let g=0;if(f.size>0&&ZX(f.content)){let e=$X(s.doc,m,o,r.id)??$X(s.doc,m+1,o,r.id)??{id:WX(),author:r.id,name:r.name,at:c},t=QX(f.content,o,a,e,r.id);if(ZX(t)){let e=new p(t,f.openStart,f.openEnd),n=s.doc.content.size;s.replace(m,m,e),g=s.doc.content.size-n}}if(u){let e=t.selection;l=h>0?m+g+h:e.empty&&e.head===d.to?m:m+g}}),!s.docChanged)return null;if(l!==null){let t=Math.min(Math.max(l,0),s.doc.content.size);s.setSelection(T.near(s.doc.resolve(t),tZ(e)))}return s.setMeta(HX,!0),s}function tZ(e){return e.steps[0].slice.size>0?1:-1}var nZ=wp.create({name:`suggestions`,addOptions(){return{onSelect:void 0}},addExtensions(){return[KX,qX]},addCommands(){return{setSuggesting:e=>({tr:t,dispatch:n})=>(n&&t.setMeta(UX,{author:e}).setMeta(HX,!0).setMeta(`addToHistory`,!1),!0),acceptSuggestion:e=>({tr:t})=>XX(t,!0,e),rejectSuggestion:e=>({tr:t})=>XX(t,!1,e),acceptAllSuggestions:()=>({tr:e})=>XX(e,!0),rejectAllSuggestions:()=>({tr:e})=>XX(e,!1)}},addProseMirrorPlugins(){let e=()=>this.options.onSelect;return[new D({key:UX,state:{init:()=>({author:null}),apply:(e,t)=>e.getMeta(UX)??t},appendTransaction(e,t,n){let r=UX.getState(n)?.author;if(!r||e.length!==1)return null;let i=e[0];return!i.docChanged||i.getMeta(HX)||i.getMeta(PS)?.isChangeOrigin||i.getMeta(`history$`)||i.getMeta(`isUndoRedo`)?null:eZ(i,t,n,r)},props:{attributes:e=>UX.getState(e)?.author?{"data-suggesting":`true`}:{},handleClick(t,n,r){let i=r.target?.closest?.(`[data-suggestion]`),a=i?.getAttribute(`data-suggestion`);return!i||!a||e()?.(a,i),!1}}})]}});function rZ(e,t){let n=!0,r=e.firstChild?.childCount??0;return e.forEach(e=>{t===`column`&&e.childCount!==r&&(n=!1),e.forEach(e=>{((t===`row`?e.attrs.rowspan:e.attrs.colspan)??1)>1&&(n=!1)})}),n}function iZ(e,t,n){let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r}var aZ=e=>{let t=[];return e.forEach(e=>t.push(e)),t};function oZ(e,t,n,r,i,a=0){let o=e.doc.nodeAt(t);if(!o||o.type.name!==`table`||!rZ(o,n))return null;let c=aZ(o),l=n===`row`?c.length:c[0]?.childCount??0;if(r===i||r<0||i<0||r>=l||i>=l)return null;let u=n===`row`?iZ(c,r,i):c.map(e=>e.copy(s.fromArray(iZ(aZ(e),r,i)))),d=e.tr.replaceWith(t,t+o.nodeSize,o.copy(s.fromArray(u))),[f,p]=n===`row`?[i,0]:[Math.min(a,u.length-1),i],m=t+1;for(let e=0;e0;e--)if(n.node(e).type.name===`table`)return{tablePos:n.before(e),row:n.index(e),column:e+1<=n.depth?n.index(e+1):0};return null}var cZ=wp.create({name:`tableMove`,addOptions(){return{labels:null}},addCommands(){let e=e=>t=>({state:n,dispatch:r})=>{let i=sZ(n,n.selection.from);if(!i)return!1;let a=e===`row`?i.row:i.column,o=oZ(n,i.tablePos,e,a,a+t,i.row);return o?(r?.(o),!0):!1};return{moveTableRow:e(`row`),moveTableColumn:e(`column`)}},addKeyboardShortcuts(){return{"Mod-Alt-ArrowUp":()=>this.editor.commands.moveTableRow(-1),"Mod-Alt-ArrowDown":()=>this.editor.commands.moveTableRow(1),"Mod-Alt-ArrowLeft":()=>this.editor.commands.moveTableColumn(-1),"Mod-Alt-ArrowRight":()=>this.editor.commands.moveTableColumn(1)}},addProseMirrorPlugins(){let e=this.options.labels?.table;return[new D({key:new O(`tableMove`),view:t=>new lZ(t,{row:e?.dragRow??`Drag to move the row`,column:e?.dragColumn??`Drag to move the column`})})]}}),lZ=class{view;grips={row:document.createElement(`button`),column:document.createElement(`button`)};line=document.createElement(`div`);cell=null;drag=null;constructor(e,t){this.view=e;for(let e of[`row`,`column`]){let n=this.grips[e];n.type=`button`,n.className=`dw-table-grip dw-table-grip--${e}`,n.contentEditable=`false`,n.setAttribute(`aria-label`,t[e]),n.title=t[e],n.hidden=!0,n.tabIndex=-1,n.addEventListener(`pointerdown`,t=>this.start(t,e)),n.addEventListener(`mouseleave`,this.leave)}this.line.className=`dw-table-drop`,this.line.hidden=!0,e.dom.addEventListener(`mousemove`,this.move),e.dom.addEventListener(`mouseleave`,this.leave)}get host(){let e=this.view.dom.parentElement;return e&&this.line.parentElement!==e&&(e.classList.add(`dw-block-host`),e.append(this.grips.row,this.grips.column,this.line)),e}hide=()=>{this.drag||(this.grips.row.hidden=!0,this.grips.column.hidden=!0,this.cell=null)};leave=e=>{let t=e.relatedTarget;t&&(this.grips.row.contains(t)||this.grips.column.contains(t)||this.view.dom.contains(t))||this.hide()};move=e=>{if(this.drag)return;let t=e.target?.closest?.(`td, th`),n=this.host;if(!this.view.editable||!n||!(t instanceof HTMLTableCellElement)||!this.view.dom.contains(t))return this.hide();let r=this.locate(t),i=r&&this.view.state.doc.nodeAt(r.tablePos);if(!r||!i)return this.hide();this.cell=t;let a=n.getBoundingClientRect(),o=t.closest(`table`).getBoundingClientRect(),s=t.parentElement.getBoundingClientRect(),c=t.getBoundingClientRect(),l=i.childCount>1&&rZ(i,`row`),u=(i.firstChild?.childCount??0)>1&&rZ(i,`column`);Object.assign(this.grips.row.style,{top:`${s.top-a.top+s.height/2-11}px`,left:`${o.left-a.left-7}px`}),Object.assign(this.grips.column.style,{top:`${o.top-a.top-7}px`,left:`${c.left-a.left+c.width/2-11}px`}),this.grips.row.hidden=!l,this.grips.column.hidden=!u};locate(e){try{return sZ(this.view.state,this.view.posAtDOM(e,0))}catch{return null}}start(e,t){let n=this.cell;if(!n||e.button!==0)return;let r=this.locate(n),i=n.parentElement?.parentElement;if(!r||!i)return;e.preventDefault();let a=this.grips[t];a.setPointerCapture(e.pointerId);let o=[...i.children].filter(e=>e instanceof HTMLTableRowElement),s=t===`row`?r.row:r.column,c=t===`row`?o:[...o[0]?.children??[]],l=t===`row`?[o[s]]:o.map(e=>e.children[s]).filter(Boolean);for(let e of l)e.classList.add(`dw-table-dragging`);this.drag={axis:t,tablePos:r.tablePos,from:s,slots:c,dimmed:l,to:s,cursorRow:r.row},a.addEventListener(`pointermove`,this.dragMove),a.addEventListener(`pointerup`,this.drop),a.addEventListener(`pointercancel`,this.cancel)}dragMove=e=>{let t=this.drag,n=this.host;if(!t||!n)return;let r=t.axis===`row`,i=r?e.clientY:e.clientX,a=t.slots.length;for(let[e,n]of t.slots.entries()){let t=n.getBoundingClientRect();if(i<(r?t.top+t.height/2:t.left+t.width/2)){a=e;break}}t.to=a>t.from?a-1:a;let o=n.getBoundingClientRect(),s=t.slots[0].closest(`table`).getBoundingClientRect(),c=t.slots.at(-1).getBoundingClientRect(),l=t.slots[a]?.getBoundingClientRect(),u=r?l?.top??c.bottom:l?.left??c.right;Object.assign(this.line.style,r?{top:`${u-o.top-1}px`,left:`${s.left-o.left}px`,width:`${s.width}px`,height:`2px`}:{top:`${s.top-o.top}px`,left:`${u-o.left-1}px`,width:`2px`,height:`${s.height}px`}),this.line.hidden=t.to===t.from};drop=()=>{let e=this.drag;if(this.cancel(),!e||e.to===e.from)return;let t=oZ(this.view.state,e.tablePos,e.axis,e.from,e.to,e.cursorRow);t&&this.view.dispatch(t),this.view.focus()};cancel=()=>{let e=this.drag;for(let t of e?.dimmed??[])t.classList.remove(`dw-table-dragging`);this.drag=null,this.line.hidden=!0;for(let e of Object.values(this.grips))e.removeEventListener(`pointermove`,this.dragMove),e.removeEventListener(`pointerup`,this.drop),e.removeEventListener(`pointercancel`,this.cancel);this.hide()};update(){this.cell&&!this.cell.isConnected&&this.hide()}destroy(){this.cancel();for(let e of Object.values(this.grips))e.remove();this.line.remove(),this.view.dom.removeEventListener(`mousemove`,this.move),this.view.dom.removeEventListener(`mouseleave`,this.leave)}};function uZ(e){let t=[];return e.descendants((e,n)=>e.type.name!==`heading`||(t.push({level:Number(e.attrs.level)||1,text:e.textContent.trim(),pos:n}),!1)),t}function dZ(e,t){let n=e.view.nodeDOM(t);n instanceof HTMLElement&&n.scrollIntoView({behavior:`smooth`,block:`start`}),e.isEditable&&e.commands.setTextSelection(t+1)}var fZ=qp.create({name:`tableOfContents`,group:`block`,atom:!0,draggable:!0,addOptions(){return{labels:null}},parseHTML(){return[{tag:`nav[data-type='toc']`}]},renderHTML(){return[`nav`,{"data-type":`toc`}]},addCommands(){return{insertTableOfContents:()=>({commands:e})=>e.insertContent({type:this.name})}},addNodeView(){return({editor:e})=>{let t=this.options.labels.blocks,n=document.createElement(`nav`);n.className=`dw-toc`,n.setAttribute(`data-type`,`toc`),n.setAttribute(`aria-label`,t.toc),n.contentEditable=`false`;let r=document.createElement(`p`);r.className=`dw-toc__title`,r.textContent=t.toc;let i=document.createElement(`ol`);i.className=`dw-toc__list`,n.append(r,i);let a=``,o=()=>{let n=uZ(e.state.doc),r=JSON.stringify(n.map(e=>[e.level,e.text]));if(r===a){i.querySelectorAll(`a`).forEach((e,t)=>e.dataset.pos=String(n[t]?.pos??0));return}if(a=r,i.replaceChildren(),!n.length){let e=document.createElement(`li`);e.className=`dw-toc__empty`,e.textContent=t.tocEmpty,i.append(e);return}let o=Math.min(...n.map(e=>e.level));for(let t of n){let n=document.createElement(`li`);n.style.paddingLeft=`${(t.level-o)*1}rem`;let r=document.createElement(`a`);r.href=`#`,r.textContent=t.text||`…`,r.dataset.pos=String(t.pos),r.addEventListener(`click`,t=>{t.preventDefault(),dZ(e,Number(r.dataset.pos))}),n.append(r),i.append(n)}};return o(),e.on(`update`,o),{dom:n,update:e=>e.type.name===`tableOfContents`,ignoreMutation:()=>!0,stopEvent:e=>e.target instanceof Element&&!!e.target.closest(`a`),destroy:()=>e.off(`update`,o)}}}}),pZ=(e,t)=>{let n=t.view.domAtPos(e).node,r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return r?r.offsetParent!==null:!1},mZ=(e,t,n)=>{for(let r=e.depth;r>0;--r){let i=e.node(r),a=t(i),o=pZ(e.start(r),n);if(a&&o)return{pos:r>0?e.before(r):0,start:e.start(r),depth:r,node:i}}},hZ=(e,t)=>{let{state:n,view:r,extensionManager:i}=e,{schema:a,selection:o}=n,{empty:s,$anchor:c}=o,l=!!i.extensions.find(e=>e.name===`gapCursor`);if(!s||c.parent.type!==a.nodes.detailsSummary||!l||t===`right`&&c.parentOffset!==c.parent.nodeSize-2)return!1;let u=vu(e=>e.type===a.nodes.details)(o);if(!u)return!1;let d=hu(u.node,e=>e.type===a.nodes.detailsContent);if(!d.length||pZ(u.start+d[0].pos+1,e))return!1;let f=n.doc.resolve(u.pos+u.node.nodeSize),p=Rw.findFrom(f,1,!1);if(!p)return!1;let{tr:m}=n,h=new Rw(p);return m.setSelection(h),m.scrollIntoView(),r.dispatch(m),!0},gZ=qp.create({name:`details`,content:`detailsSummary detailsContent`,group:`block`,defining:!0,isolating:!0,allowGapCursor:!1,addOptions(){return{persist:!1,openClassName:`is-open`,HTMLAttributes:{},renderToggleButton:({element:e,isOpen:t})=>{e.setAttribute(`aria-label`,t?`Collapse details content`:`Expand details content`)}}},addAttributes(){return this.options.persist?{open:{default:!1,parseHTML:e=>e.hasAttribute(`open`),renderHTML:({open:e})=>e?{open:``}:{}}}:[]},parseHTML(){return[{tag:`details`}]},renderHTML({HTMLAttributes:e}){return[`details`,j(this.options.HTMLAttributes,e),0]},...Yf({nodeName:`details`,content:`block`}),addNodeView(){return({editor:e,getPos:t,node:n,HTMLAttributes:r})=>{let i=document.createElement(`div`),a=j(this.options.HTMLAttributes,r,{"data-type":this.name});Object.entries(a).forEach(([e,t])=>i.setAttribute(e,t));let o=document.createElement(`button`);o.type=`button`;let s=e=>{this.options.renderToggleButton({element:o,...e})};i.append(o);let c=document.createElement(`div`);i.append(c);let l=e=>{let{setToValue:t,node:r=n}=e||{};if(t!==void 0){if(t){if(i.classList.contains(this.options.openClassName))return;i.classList.add(this.options.openClassName)}else{if(!i.classList.contains(this.options.openClassName))return;i.classList.remove(this.options.openClassName)}}else i.classList.toggle(this.options.openClassName);let a=i.classList.contains(this.options.openClassName);s({isOpen:a,node:r});let o=new Event(`toggleDetailsContent`);c.querySelector(`:scope > div[data-type="detailsContent"]`)?.dispatchEvent(o)};return s({isOpen:!!n.attrs.open,node:n}),n.attrs.open&&setTimeout(()=>l()),o.addEventListener(`click`,()=>{if(l(),!this.options.persist)e.commands.focus(void 0,{scrollIntoView:!1});else if(e.isEditable&&typeof t==`function`){let{from:n,to:r}=e.state.selection;e.chain().command(({tr:e})=>{let n=t();if(typeof n!=`number`)return!1;let r=e.doc.nodeAt(n);return r?.type===this.type&&(e.setNodeMarkup(n,void 0,{open:!r.attrs.open}),!0)}).setTextSelection({from:n,to:r}).focus(void 0,{scrollIntoView:!1}).run()}}),{dom:i,contentDOM:c,ignoreMutation(e){if(e.type===`selection`)return!1;let t=e.target,n=i.contains(t);return o.contains(t)||!n||i===t},update:e=>e.type===this.type&&(e.attrs.open===void 0?s({isOpen:i.classList.contains(this.options.openClassName),node:e}):l({setToValue:e.attrs.open,node:e}),!0)}}},addCommands(){return{setDetails:()=>({state:e,chain:t})=>{let{schema:n,selection:r}=e,{$from:i,$to:a}=r,o=i.blockRange(a);if(!o)return!1;let s=e.doc.slice(o.start,o.end);if(!n.nodes.detailsContent.contentMatch.matchFragment(s.content))return!1;let c=s.toJSON()?.content||[];return t().insertContentAt({from:o.start,to:o.end},{type:this.name,content:[{type:`detailsSummary`},{type:`detailsContent`,content:c}]}).setTextSelection(o.start+2).run()},unsetDetails:()=>({state:e,chain:t})=>{let{selection:n,schema:r}=e,i=vu(e=>e.type===this.type)(n);if(!i)return!1;let a=hu(i.node,e=>e.type===r.nodes.detailsSummary),o=hu(i.node,e=>e.type===r.nodes.detailsContent);if(!a.length||!o.length)return!1;let s=a[0],c=o[0],l=i.pos,u=e.doc.resolve(l),d={from:l,to:l+i.node.nodeSize},f=c.node.content.toJSON()||[],p=[u.parent.type.contentMatch.defaultType?.create(null,s.node.content).toJSON(),...f];return t().insertContentAt(d,p).setTextSelection(l+1).run()}}},addKeyboardShortcuts(){return{Backspace:()=>{let{schema:e,selection:t}=this.editor.state,{empty:n,$anchor:r}=t;return!n||r.parent.type!==e.nodes.detailsSummary?!1:r.parentOffset===0?this.editor.commands.unsetDetails():this.editor.commands.command(({tr:e})=>{let t=r.pos-1,n=r.pos;return e.delete(t,n),!0})},Enter:({editor:e})=>{let{state:t,view:n}=e,{schema:r,selection:i}=t,{$head:a}=i;if(a.parent.type!==r.nodes.detailsSummary)return!1;let o=pZ(a.after()+1,e),s=o?t.doc.nodeAt(a.after()):a.node(-2);if(!s)return!1;let c=o?0:a.indexAfter(-1),l=Il(s.contentMatchAt(c));if(!l||!s.canReplaceWith(c,c,l))return!1;let u=l.createAndFill();if(!u)return!1;let d=o?a.after()+1:a.after(-1),f=t.tr.replaceWith(d,d,u),p=f.doc.resolve(d),m=w.near(p,1);return f.setSelection(m),f.scrollIntoView(),n.dispatch(f),!0},ArrowRight:({editor:e})=>hZ(e,`right`),ArrowDown:({editor:e})=>hZ(e,`down`)}},addProseMirrorPlugins(){return[new D({key:new O(`detailsSelection`),appendTransaction:(e,t,n)=>{let{editor:r,type:i}=this;if(r.view.composing||!e.some(e=>e.selectionSet)||!t.selection.empty||!n.selection.empty||!od(n,i.name))return;let{$from:a}=n.selection;if(pZ(a.pos,r))return;let o=mZ(a,e=>e.type===i,r);if(!o)return;let s=hu(o.node,e=>e.type===n.schema.nodes.detailsSummary);if(!s.length)return;let c=s[0],l=(t.selection.from{let t=document.createElement(`div`),n=j(this.options.HTMLAttributes,e,{"data-type":this.name,hidden:`hidden`});return Object.entries(n).forEach(([e,n])=>t.setAttribute(e,n)),t.addEventListener(`toggleDetailsContent`,()=>{t.toggleAttribute(`hidden`)}),{dom:t,contentDOM:t,ignoreMutation(e){return e.type===`selection`?!1:!t.contains(e.target)||t===e.target},update:e=>e.type===this.type}}},addKeyboardShortcuts(){return{Enter:({editor:e})=>{let{state:t,view:n}=e,{selection:r}=t,{$from:i,empty:a}=r,o=vu(e=>e.type===this.type)(r);if(!a||!o||!o.node.childCount)return!1;let s=i.index(o.depth),{childCount:c}=o.node;if(c!==s+1)return!1;let l=o.node.type.contentMatch.defaultType?.createAndFill();if(!l)return!1;let u=t.doc.resolve(o.pos+1),d=c-1,f=o.node.child(d),p=u.posAtIndex(d,o.depth);if(!f.eq(l))return!1;let m=i.node(-3);if(!m)return!1;let h=i.indexAfter(-3),g=Il(m.contentMatchAt(h));if(!g||!m.canReplaceWith(h,h,g))return!1;let _=g.createAndFill();if(!_)return!1;let{tr:v}=t,y=i.after(-2);v.replaceWith(y,y,_);let b=v.doc.resolve(y),x=w.near(b,1);v.setSelection(x);let S=p,C=p+f.nodeSize;return v.delete(S,C),v.scrollIntoView(),n.dispatch(v),!0}}},...Yf({nodeName:`detailsContent`})}),vZ=qp.create({name:`detailsSummary`,content:`text*`,defining:!0,selectable:!1,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`summary`}]},renderHTML({HTMLAttributes:e}){return[`summary`,j(this.options.HTMLAttributes,e),0]},...Yf({nodeName:`detailsSummary`,content:`inline`})});function yZ(e){return[gZ.configure({persist:!1,HTMLAttributes:{class:`dw-toggle`},renderToggleButton:({element:t,isOpen:n})=>{t.setAttribute(`aria-label`,n?e.blocks.collapse:e.blocks.expand),t.setAttribute(`aria-expanded`,String(n))}}),vZ,_Z]}function bZ(e={}){let t=e.labels??BR,n=null,r=wp.create({name:`editorRef`,onCreate(){n=this.editor}}),i={host:e.files,labels:t,drawioUrl:e.drawioUrl,loadExcalidraw:e.loadExcalidraw,onError:e.onError},a=[r,Jk.configure({heading:{levels:[1,2,3,4,5,6]},codeBlock:!1,link:{openOnClick:!1,autolink:!0},undoRedo:e.collab||e.syncedDoc||e.rowBody||e.rowFragmentReadOnly?!1:void 0}),mT.configure({placeholder:e.placeholder??`Type '/' for commands…`}),_U.configure({host:e.files}),yU.configure({host:e.files,loadPdf:e.loadPdf,labels:t}),JU.configure({host:e.files}),YU.configure({host:e.files}),XU.configure({labels:t}),QU.configure({labels:t}),GU.configure({labels:t}),rW.configure({labels:t}),iW,$U.configure({children:xZ(e),labels:t,onNavigate:e.onNavigate}),jU.configure({labels:t}),Ij.configure({lineNumbers:e.codeLineNumbers??!1}),AP,kP,IP,LP,...DP(),...OP(),cZ.configure({labels:t}),BP.configure({labels:t}),qP.configure({labels:t}),JP.configure({labels:t}),bU.configure({host:e.files,onError:e.onError}),kX(t,e.mentions),uH.configure({labels:t,me:()=>e.mentions?.me,onOpen:e.onOpenDate}),zX.configure({commands:LX(t,e.files,e.onError,e.pages,!!e.loadExcalidraw,e.links,!!xZ(e)),labels:t}),eH.configure({onSelect:e.onCommentSelect}),nZ.configure({onSelect:e.onSuggestionSelect}),wX(t,()=>n),FX.configure({labels:t,load:e.loadMermaid}),fZ.configure({labels:t}),QH.configure(i),$H.configure(i),FH.configure({host:e.pages,labels:t,onNavigate:e.onNavigate}),HH.configure({host:e.syncedPages,pages:e.pages,labels:t,onNavigate:e.onNavigate,nested:(t,n)=>bZ({syncedDoc:t,syncedBlock:n,files:e.files,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:``})}),...yZ(t),dU.configure({labels:t}),fU.configure({labels:t}),tM.configure({labels:t,link:e.blockLink,onCopied:e.onBlockLinkCopied}),uW,GV.configure({labels:t,doc:e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc,readOnlyDoc:!!e.syncedDoc,undoScope:!e.rowBody,files:e.files,people:e.mentions,recordLink:e.blockLink,linkedPages:e.syncedPages,pages:e.pages,onNavigate:e.onNavigate,recordPage:e.recordPage,onLinkCopied:e.onBlockLinkCopied,me:()=>{let t=e.mentions?.me;return t?{id:t,name:e.collab?.user.name??``}:null},rowExtensions:n=>{let r=e.collab?.provider.doc??e.syncedDoc??e.rowBody?.doc;return bZ({rowBody:n&&r&&!e.syncedDoc?{doc:r,fragment:n}:void 0,files:e.files,mentions:e.mentions,pages:e.pages,links:e.links,onNavigate:e.onNavigate,drawioUrl:e.drawioUrl,loadMermaid:e.loadMermaid,loadExcalidraw:e.loadExcalidraw,loadPdf:e.loadPdf,codeLineNumbers:e.codeLineNumbers,labels:e.labels,placeholder:t.database.bodyPlaceholder,rowFragmentReadOnly:n&&e.syncedDoc?n:void 0})}})],o={trackedOrigins:[RB]};return e.syncedDoc&&e.syncedBlock&&a.push(BH.configure({block:e.syncedBlock})),e.rowBody?a.push(Aw.configure({document:e.rowBody.doc,fragment:e.rowBody.fragment,yUndoOptions:o})):e.rowFragmentReadOnly?a.push(Aw.configure({fragment:e.rowFragmentReadOnly})):e.syncedDoc?a.push(Aw.configure({document:e.syncedDoc})):e.collab&&a.push(Aw.configure({document:e.collab.provider.doc,yUndoOptions:o}),Fw.configure({provider:e.collab.provider,user:e.collab.user,render:SZ})),a}function xZ(e){if(e.children)return e.children;let t=e.pages;return t?.children?()=>t.children():void 0}function SZ(e){let t=typeof e.color==`string`&&/^#[0-9a-f]{3,8}$/i.test(e.color)?e.color:`#888`,n=document.createElement(`span`);n.classList.add(`collaboration-carets__caret`),n.style.borderColor=t;let r=document.createElement(`div`);return r.classList.add(`collaboration-carets__label`),r.setAttribute(`aria-hidden`,`true`),r.style.backgroundColor=t,r.textContent=typeof e.name==`string`?e.name:``,n.append(r),n}function CZ(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var wZ=CZ();function TZ(e){wZ=e}var EZ={exec:()=>null};function DZ(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(kZ.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var OZ=(()=>{try{return!0}catch{return!1}})(),kZ={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},AZ=/^(?:[ \t]*(?:\n|$))+/,jZ=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,MZ=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,NZ=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,PZ=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,FZ=/(?:[*+-]|\d{1,9}[.)])/,IZ=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,LZ=DZ(IZ).replace(/bull/g,FZ).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),RZ=DZ(IZ).replace(/bull/g,FZ).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),zZ=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,BZ=/^[^\n]+/,VZ=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,HZ=DZ(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,VZ).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),UZ=DZ(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,FZ).getRegex(),WZ=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,GZ=/\x3C!--(?:-?>|[\s\S]*?(?:-->|$))/,KZ=DZ(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,GZ).replace(`tag`,WZ).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),qZ=DZ(zZ).replace(`hr`,NZ).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,WZ).getRegex(),JZ={blockquote:DZ(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,qZ).getRegex(),code:jZ,def:HZ,fences:MZ,heading:PZ,hr:NZ,html:KZ,lheading:LZ,list:UZ,newline:AZ,paragraph:qZ,table:EZ,text:BZ},YZ=DZ(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,NZ).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,WZ).getRegex(),XZ={...JZ,lheading:RZ,table:YZ,paragraph:DZ(zZ).replace(`hr`,NZ).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,YZ).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,WZ).getRegex()},ZZ={...JZ,html:DZ(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,GZ).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:EZ,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:DZ(zZ).replace(`hr`,NZ).replace(`heading`,` *#{1,6} *[^ +]`).replace(`lheading`,LZ).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},QZ=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,$Z=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,eQ=/^( {2,}|\\)\n(?!\s*$)/,tQ=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\`+)[^`]+\k(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,OZ?"(?`+)[^`]+\k(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),uQ=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,dQ=DZ(uQ,`u`).replace(/punct/g,nQ).getRegex(),fQ=DZ(uQ,`u`).replace(/punct/g,oQ).getRegex(),pQ=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,mQ=DZ(pQ,`gu`).replace(/notPunctSpace/g,iQ).replace(/punctSpace/g,rQ).replace(/punct/g,nQ).getRegex(),hQ=DZ(pQ,`gu`).replace(/notPunctSpace/g,cQ).replace(/punctSpace/g,sQ).replace(/punct/g,oQ).getRegex(),gQ=DZ(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,iQ).replace(/punctSpace/g,rQ).replace(/punct/g,nQ).getRegex(),_Q=DZ(/\\(punct)/,`gu`).replace(/punct/g,nQ).getRegex(),vQ=DZ(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),yQ=DZ(GZ).replace(`(?:-->|$)`,`-->`).getRegex(),bQ=DZ(`^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^`).replace(`comment`,yQ).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),xQ=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,SQ=DZ(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace(`label`,xQ).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),CQ=DZ(/^!?\[(label)\]\[(ref)\]/).replace(`label`,xQ).replace(`ref`,VZ).getRegex(),wQ=DZ(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,VZ).getRegex(),TQ=DZ(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,CQ).replace(`nolink`,wQ).getRegex(),EQ=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,DQ={_backpedal:EZ,anyPunctuation:_Q,autolink:vQ,blockSkip:lQ,br:eQ,code:$Z,del:EZ,emStrongLDelim:dQ,emStrongRDelimAst:mQ,emStrongRDelimUnd:gQ,escape:QZ,link:SQ,nolink:wQ,punctuation:aQ,reflink:CQ,reflinkSearch:TQ,tag:bQ,text:tQ,url:EZ},OQ={...DQ,link:DZ(/^!?\[(label)\]\((.*?)\)/).replace(`label`,xQ).getRegex(),reflink:DZ(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,xQ).getRegex()},kQ={...DQ,emStrongRDelimAst:hQ,emStrongLDelim:fQ,url:DZ(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,EQ).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:DZ(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\":`>`,'"':`"`,"'":`'`},PQ=e=>NQ[e];function FQ(e,t){if(t){if(kZ.escapeTest.test(e))return e.replace(kZ.escapeReplace,PQ)}else if(kZ.escapeTestNoEncode.test(e))return e.replace(kZ.escapeReplaceNoEncode,PQ);return e}function IQ(e){try{e=encodeURI(e).replace(kZ.percentDecode,`%`)}catch{return null}return e}function LQ(e,t){let n=e.replace(kZ.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(kZ.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length0?-2:-1}function BQ(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function VQ(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(` `).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(` -`)}var uZ=class{options;rules;lexer;constructor(e){this.options=e||KY}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,``);return{type:`code`,raw:t[0],codeBlockStyle:`indented`,text:this.options.pedantic?e:oZ(e,` -`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=lZ(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=oZ(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:oZ(t[0],` -`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=oZ(t[0],` +`)}var HQ=class{options;rules;lexer;constructor(e){this.options=e||wZ}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=t[0].replace(this.rules.other.codeRemoveIndent,``);return{type:`code`,raw:t[0],codeBlockStyle:`indented`,text:this.options.pedantic?e:RQ(e,` +`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=VQ(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=RQ(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:RQ(t[0],` +`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=RQ(t[0],` `).split(` `),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o=0;for(;o=d||!l.trim())s+=` `+p.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=` `+l}!u&&!l.trim()&&(u=!0),r+=f+` -`,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0));let f=null,p;this.options.gfm&&(f=this.rules.other.listIsTask.exec(s),f&&(p=f[0]!==`[ ] `,s=s.replace(this.rules.other.listReplaceTask,``))),i.items.push({type:`list_item`,raw:r,task:!!f,checked:p,loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e=0;ee.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}if(i.loose)for(let e=0;e({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:`heading`,raw:t[0],depth:t[2].charAt(0)===`=`?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===` -`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=oZ(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=sZ(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),cZ(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return cZ(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:`del`,raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},dZ=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||KY,this.options.tokenizer=this.options.tokenizer||new uZ,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:ZY,block:$X.normal,inline:eZ.normal};this.options.pedantic?(t.block=$X.pedantic,t.inline=eZ.pedantic):this.options.gfm&&(t.block=$X.gfm,t.inline=this.options.breaks?eZ.breaks:eZ.gfm),this.tokenizer.rules=t}static get rules(){return{block:$X,inline:eZ}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(ZY.carriageReturn,` -`),this.blockTokens(e,this.tokens);for(let e=0;e(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=` +`,e=e.substring(f.length+1),c=p.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0));let f=null,p;this.options.gfm&&(f=this.rules.other.listIsTask.exec(s),f&&(p=f[0]!==`[ ] `,s=s.replace(this.rules.other.listReplaceTask,``))),i.items.push({type:`list_item`,raw:r,task:!!f,checked:p,loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e=0;ee.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}if(i.loose)for(let e=0;e({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:`heading`,raw:t[0],depth:t[2].charAt(0)===`=`?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===` +`?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=RQ(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=zQ(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),BQ(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return BQ(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!=null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:`del`,raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},UQ=class e{tokens;options;state;tokenizer;inlineQueue;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||wZ,this.options.tokenizer=this.options.tokenizer||new HQ,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:kZ,block:jQ.normal,inline:MQ.normal};this.options.pedantic?(t.block=jQ.pedantic,t.inline=MQ.pedantic):this.options.gfm&&(t.block=jQ.gfm,t.inline=this.options.breaks?MQ.breaks:MQ.gfm),this.tokenizer.rules=t}static get rules(){return{block:jQ,inline:MQ}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(kZ.carriageReturn,` +`),this.blockTokens(e,this.tokens);for(let e=0;e(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.space(e)){e=e.substring(r.raw.length);let n=t.at(-1);r.raw.length===1&&n!==void 0?n.raw+=` `:t.push(r);continue}if(r=this.tokenizer.code(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(` `)?``:` `)+r.raw,n.text+=` @@ -464,16 +466,16 @@ ${c}`:c;let l=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo `+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(r),n=i.length!==e.length,e=e.substring(r.raw.length)}else if(r=this.tokenizer.text(e)){e=e.substring(r.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(` `)?``:` `)+r.raw,n.text+=` -`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)i=r[2]?r[2].length:0,n=n.slice(0,r.index+i)+`[`+`a`.repeat(r[0].length-i-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let a=!1,o=``;for(;e;){a||(o=``),a=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if((r=this.tokenizer.escape(e))||(r=this.tokenizer.tag(e))||(r=this.tokenizer.link(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if((r=this.tokenizer.emStrong(e,n,o))||(r=this.tokenizer.codespan(e))||(r=this.tokenizer.br(e))||(r=this.tokenizer.del(e))||(r=this.tokenizer.autolink(e))||!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(i)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(o=r.raw.slice(-1)),a=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return t}},fZ=class{options;parser;constructor(e){this.options=e||KY}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(ZY.notSpaceStart)?.[0],i=e.replace(ZY.endingNewline,``)+` -`;return r?`
`+(n?i:rZ(i,!0))+`
-`:`
`+(n?i:rZ(i,!0))+`
+`+r.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)i=r[2]?r[2].length:0,n=n.slice(0,r.index+i)+`[`+`a`.repeat(r[0].length-i-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let a=!1,o=``;for(;e;){a||(o=``),a=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if((r=this.tokenizer.escape(e))||(r=this.tokenizer.tag(e))||(r=this.tokenizer.link(e))){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if((r=this.tokenizer.emStrong(e,n,o))||(r=this.tokenizer.codespan(e))||(r=this.tokenizer.br(e))||(r=this.tokenizer.del(e))||(r=this.tokenizer.autolink(e))||!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(i)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(o=r.raw.slice(-1)),a=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r)}else if(e){let t=`Infinite loop on byte: `+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw Error(t)}}return t}},WQ=class{options;parser;constructor(e){this.options=e||wZ}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(kZ.notSpaceStart)?.[0],i=e.replace(kZ.endingNewline,``)+` +`;return r?`
`+(n?i:FQ(i,!0))+`
+`:`
`+(n?i:FQ(i,!0))+`
`}blockquote({tokens:e}){return`
${this.parser.parse(e)}
`}html({text:e}){return e}def(e){return``}heading({tokens:e,depth:t}){return`${this.parser.parseInline(e)} `}hr(e){return`
`}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t `+r+` -`}listitem(e){let t=``;if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?e.tokens[0]?.type===`paragraph`?(e.tokens[0].text=n+` `+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type===`text`&&(e.tokens[0].tokens[0].text=n+` `+rZ(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:`text`,raw:n+` `,text:n+` `,escaped:!0}):t+=n+` `}return t+=this.parser.parse(e.tokens,!!e.loose),`
  • ${t}
  • +`}listitem(e){let t=``;if(e.task){let n=this.checkbox({checked:!!e.checked});e.loose?e.tokens[0]?.type===`paragraph`?(e.tokens[0].text=n+` `+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type===`text`&&(e.tokens[0].tokens[0].text=n+` `+FQ(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:`text`,raw:n+` `,text:n+` `,escaped:!0}):t+=n+` `}return t+=this.parser.parse(e.tokens,!!e.loose),`
  • ${t}
  • `}checkbox({checked:e}){return``}paragraph({tokens:e}){return`

    ${this.parser.parseInline(e)}

    `}table(e){let t=``,n=``;for(let t=0;t${r}`,` @@ -482,15 +484,15 @@ ${this.parser.parse(e)} `}tablerow({text:e}){return` ${e} `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+` -`}strong({tokens:e}){return`${this.parser.parseInline(e)}`}em({tokens:e}){return`${this.parser.parseInline(e)}`}codespan({text:e}){return`${rZ(e,!0)}`}br(e){return`
    `}del({tokens:e}){return`${this.parser.parseInline(e)}`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=iZ(e);if(i===null)return r;e=i;let a=``+r+``,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=iZ(e);if(i===null)return rZ(n);e=i;let a=`${n}`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:rZ(e.text)}},pZ=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}},mZ=class e{options;renderer;textRenderer;constructor(e){this.options=e||KY,this.options.renderer=this.options.renderer||new fZ,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new pZ}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n=``;for(let r=0;r{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new fZ(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new uZ(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new hZ;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=hZ.passThroughHooks.has(n)?e=>{if(this.defaults.async&&hZ.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return dZ.lex(e,t??this.defaults)}parser(e,t){return mZ.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?dZ.lex:dZ.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser():e?mZ.parse:mZ.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?dZ.lex:dZ.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?mZ.parse:mZ.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=` -Please report this to https://github.com/markedjs/marked.`,e){let e=`

    An error occurred:

    `+rZ(n.message+``,!0)+`
    `;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function _Z(e,t){return gZ.parse(e,t)}_Z.options=_Z.setOptions=function(e){return gZ.setOptions(e),_Z.defaults=gZ.defaults,qY(_Z.defaults),_Z},_Z.getDefaults=GY,_Z.defaults=KY,_Z.use=function(...e){return gZ.use(...e),_Z.defaults=gZ.defaults,qY(_Z.defaults),_Z},_Z.walkTokens=function(e,t){return gZ.walkTokens(e,t)},_Z.parseInline=gZ.parseInline,_Z.Parser=mZ,_Z.parser=mZ.parse,_Z.Renderer=fZ,_Z.TextRenderer=pZ,_Z.Lexer=dZ,_Z.lexer=dZ.lex,_Z.Tokenizer=uZ,_Z.Hooks=hZ,_Z.parse=_Z,_Z.options,_Z.setOptions,_Z.use,_Z.walkTokens,_Z.parseInline,mZ.parse,dZ.lex;function vZ(e){let t=e??BR;return{...xF,...t.edgeless,colors:{...xF.colors,...t.colors}}}function yZ(e){let t=e?.surface;return Array.isArray(t?.elements)?t.elements:[]}function bZ(e,t,n){let r={...n,placeholder:n.placeholder??``},i=new Vp({element:e,editable:t.kind!==`json`&&t.editable,content:t.kind===`json`?t.content:void 0,extensions:t.kind===`page`?UY({...r,collab:{provider:t.provider,user:t.user}}):t.kind===`body`?UY({...r,rowBody:{doc:t.doc,fragment:t.fragment}}):UY(r),editorProps:{attributes:{class:`dw-prose`}}});return{destroy:()=>i.destroy(),focus:()=>i.commands.focus(`end`),setEditable:e=>i.setEditable(e&&t.kind!==`json`)}}function xZ(e,t){let n=!!t.provider,r,i=null;if(t.provider)r=t.provider.doc;else{i=new Cv,r=i;let e=t.content;i.transact(()=>iR(i.getXmlFragment(`default`),e?.content??[]));let n=yZ(e);if(n.length){let e=new dR(i,{undo:!1});e.load(n),e.destroy()}}let a={...t};delete a.provider,delete a.content;let o=new kR(e,{doc:r,editable:n&&t.editable,notes:{mount:(e,r)=>{let i=n?r.page?{kind:`page`,provider:t.provider,user:t.user??{name:`?`,color:`#888`},editable:r.editable}:{kind:`body`,doc:r.doc,fragment:r.fragment,editable:r.editable}:{kind:`json`,content:r.page&&t.content?t.content:{type:`doc`,content:rR(r.fragment)}};return t.mountNote?t.mountNote(e,i):bZ(e,i,a)}},labels:vZ(t.labels),files:t.files,links:t.links,embedSource:dH,styles:t.styles,onStyles:t.onStyles,viewKey:t.viewKey,pageTitle:t.pageTitle,undo:n,onError:t.onError,onComment:t.onComment,onCommentSelect:t.onCommentSelect});return{view:o,setEditable:e=>o.setEditable(n&&e),destroy:()=>{o.destroy(),i?.destroy()}}}function SZ(e,t,n){let r=Yj(t),i=JB(t);if(!r&&!i)return()=>{};let a=()=>i?XB(e,i.database,i.row):tM(e,r),o=!1,s,c=()=>{clearTimeout(s),s=setTimeout(()=>{o||e.isDestroyed||!a()||(o=!0,l(),n?.())},50)},l=()=>{e.off(`transaction`,c),clearTimeout(u)},u=setTimeout(l,5e3);return e.on(`transaction`,c),c(),()=>{l(),clearTimeout(s)}}var CZ=3e4,wZ=class extends pm{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Fh();this.getLocalState()!==null&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&TZ(this,t,`timeout`)},mm(CZ/10)),e.on(`destroy`,()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit(`destroy`,[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:Fh()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),tg(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},TZ=(e,t,n)=>{let r=[];for(let n=0;n0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},EZ=(e,t,n=e.states)=>{let r=t.length,i=Fm();j(i,r);for(let a=0;a{let r=hh(t),i=Fh(),a=[],o=[],s=[],c=[],l=M(r);for(let t=0;t0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},OZ=(e,t)=>{j(e,0),qm(e,Jv(t))},kZ=(e,t,n)=>{j(e,1),qm(e,Hv(t,n))},AZ=(e,t,n)=>kZ(t,n,vh(e)),jZ=(e,t,n,r)=>{try{zv(t,vh(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},MZ=(e,t)=>{j(e,2),qm(e,t)},NZ=jZ,PZ=(e,t,n,r,i)=>{let a=M(e);switch(a){case 0:AZ(e,t,n);break;case 1:jZ(e,n,r,i);break;case 2:NZ(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},FZ=0,IZ=1,LZ=4401,RZ=4404,zZ=4409,BZ=class{opts;doc=new Cv;awareness=new wZ(this.doc);status=`connecting`;synced=!1;ws=null;retries=0;retryTimer;destroyed=!1;listeners=new Set;constructor(e){this.opts=e,this.doc.on(`update`,this.onDocUpdate),this.awareness.on(`update`,this.onAwarenessUpdate),e.readOnly&&this.awareness.setLocalState(null),window.addEventListener(`beforeunload`,this.onUnload),this.connect()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}destroy(){this.destroyed||(this.destroyed=!0,this.listeners.clear(),clearTimeout(this.retryTimer),window.removeEventListener(`beforeunload`,this.onUnload),TZ(this.awareness,[this.doc.clientID],`local`),this.doc.off(`update`,this.onDocUpdate),this.awareness.off(`update`,this.onAwarenessUpdate),this.ws?.close(),this.awareness.destroy(),this.doc.destroy(),this.listeners.clear())}set(e,t=this.synced){(e!==this.status||t!==this.synced)&&(this.status=e,this.synced=t,this.listeners.forEach(e=>e()))}connect(){let e=new WebSocket(`${this.opts.url}?page=${encodeURIComponent(this.opts.page)}`);e.binaryType=`arraybuffer`,this.ws=e,e.onopen=()=>{e.send(this.opts.token()??``);let t=Fm();j(t,FZ),OZ(t,this.doc),e.send(Rm(t)),this.awareness.getLocalState()!==null&&this.sendAwareness([this.doc.clientID])},e.onmessage=e=>this.onMessage(new Uint8Array(e.data)),e.onclose=t=>{if(this.ws!==e)return;this.ws=null;let n=[...this.awareness.getStates().keys()].filter(e=>e!==this.doc.clientID);TZ(this.awareness,n,this),this.destroyed||(t.code===LZ||t.code===RZ?this.set(`denied`,!1):t.code===zZ?this.set(`changed`):(this.set(`offline`),this.retryTimer=setTimeout(()=>this.connect(),Math.min(1e3*2**this.retries++,3e4))))}}onMessage(e){let t=hh(e),n=M(t);if(n===FZ){let e=Fm();j(e,FZ);let n=PZ(t,e,this.doc,this);Lm(e)>1&&!this.opts.readOnly&&this.ws?.send(Rm(e)),n===1&&(this.retries=0,this.set(`connected`,!0))}else n===IZ&&DZ(this.awareness,vh(t),this)}onDocUpdate=(e,t)=>{if(t===this||this.opts.readOnly||this.ws?.readyState!==WebSocket.OPEN)return;let n=Fm();j(n,FZ),MZ(n,e),this.ws.send(Rm(n))};onAwarenessUpdate=({added:e,updated:t,removed:n},r)=>{r===this||this.opts.readOnly||this.sendAwareness([...e,...t,...n])};sendAwareness(e){if(this.ws?.readyState!==WebSocket.OPEN)return;let t=Fm();j(t,IZ),qm(t,EZ(this.awareness,e)),this.ws.send(Rm(t))}onUnload=()=>TZ(this.awareness,[this.doc.clientID],`unload`)},VZ=`.dw-db-peek, .dw-db-pop, .dw-block-menu`,HZ={bold:e=>e.chain().focus().toggleBold().run(),italic:e=>e.chain().focus().toggleItalic().run(),strike:e=>e.chain().focus().toggleStrike().run(),code:e=>e.chain().focus().toggleCode().run(),heading1:e=>e.chain().focus().toggleHeading({level:1}).run(),heading2:e=>e.chain().focus().toggleHeading({level:2}).run(),heading3:e=>e.chain().focus().toggleHeading({level:3}).run(),bulletList:e=>e.chain().focus().toggleBulletList().run(),orderedList:e=>e.chain().focus().toggleOrderedList().run(),blockquote:e=>e.chain().focus().toggleBlockquote().run(),codeBlock:e=>e.chain().focus().toggleCodeBlock().run(),underline:e=>e.chain().focus().toggleUnderline().run(),taskList:e=>e.chain().focus().toggleTaskList().run(),callout:e=>e.isActive(`callout`)?e.chain().focus().unsetCallout().run():e.chain().focus().setCallout().run(),table:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),undo:e=>e.chain().focus().undo().run(),redo:e=>e.chain().focus().redo().run()},UZ=[[`bold`,e=>e.isActive(`bold`)],[`italic`,e=>e.isActive(`italic`)],[`strike`,e=>e.isActive(`strike`)],[`code`,e=>e.isActive(`code`)],[`heading1`,e=>e.isActive(`heading`,{level:1})],[`heading2`,e=>e.isActive(`heading`,{level:2})],[`heading3`,e=>e.isActive(`heading`,{level:3})],[`bulletList`,e=>e.isActive(`bulletList`)],[`orderedList`,e=>e.isActive(`orderedList`)],[`blockquote`,e=>e.isActive(`blockquote`)],[`codeBlock`,e=>e.isActive(`codeBlock`)],[`underline`,e=>e.isActive(`underline`)],[`taskList`,e=>e.isActive(`taskList`)],[`callout`,e=>e.isActive(`callout`)],[`table`,e=>e.isActive(`table`)]],WZ=class{el;send;editor;provider=null;lastState=``;editable=!0;overlay=!1;overlays=new MutationObserver(()=>this.reportOverlay());inner=null;onFocusIn=e=>this.track(e.target);canvas=null;canvasEl=null;mode=`page`;lastContent=null;title=``;labels={...BR,blocks:{...BR.blocks}};transcribeOn=!1;words=null;pendingTranscripts=new Map;nextTranscript=1;picked=null;files={resolve:e=>e};constructor(e,t){this.el=e,this.send=t,Object.defineProperty(this.files,"transcribe",{get:()=>this.transcribeOn?(e,t)=>this.requestTranscript(e,t):void 0}),this.editor=this.create({}),this.overlays.observe(document.body,{childList:!0}),document.addEventListener(`focusin`,this.onFocusIn),t({type:`ready`,version:4})}receive(e){try{let t=typeof e==`string`?JSON.parse(e):e;this.handle(t)}catch(e){this.send({type:`error`,message:e instanceof Error?e.message:String(e)})}}get content(){return this.editor.getJSON()}destroy(){this.overlays.disconnect(),document.removeEventListener(`focusin`,this.onFocusIn),this.setInner(null),this.closeCanvas(),this.editor.destroy(),this.provider?.destroy()}handle(e){switch(e.type){case`hello`:this.send({type:`ready`,version:4}),this.lastState=``,this.reportState();return;case`setContent`:this.lastContent=e.content,this.editor.commands.setContent(e.content??``,{emitUpdate:!1}),this.reportState(),this.mode===`edgeless`&&!this.provider&&this.openCanvas();return;case`setEditable`:this.editable=e.editable,this.editor.setEditable(e.editable),this.canvas?.setEditable(e.editable);return;case`setTheme`:document.documentElement.classList.toggle(`dark`,e.dark);return;case`setLayout`:{let t=document.documentElement.classList;t.toggle(`dw-full-width`,e.fullWidth),t.toggle(`dw-font-serif`,e.font===`serif`),t.toggle(`dw-font-mono`,e.font===`mono`);return}case`command`:{let t=HZ[e.command];if(!t)throw Error(`unknown command ${e.command}`);t(this.target);return}case`focus`:this.editor.commands.focus();return;case`blur`:this.editor.commands.blur();return;case`connect`:this.connect(e);return;case`follow`:SZ(this.editor,e.hash);return;case`setMode`:this.mode=e.mode===`edgeless`?`edgeless`:`page`,typeof e.title==`string`&&(this.title=e.title),this.mode===`edgeless`?this.openCanvas():this.closeCanvas();return;case`dismiss`:[...document.querySelectorAll(VZ)].at(-1)?.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0,cancelable:!0}));return;case`setAi`:this.transcribeOn=e.transcribe,this.words=e.words,Object.assign(this.labels.blocks,{transcribe:e.words.transcribe,transcribeHint:e.words.transcribeHint,transcribing:e.words.transcribing,transcribeFailed:e.words.transcribeFailed}),KZ(this.editor);return;case`getSelection`:{let e=this.target,{from:t,to:n}=e.state.selection;this.picked={editor:e,from:t,to:n},this.send({type:`selection`,text:e.state.doc.textBetween(t,n,` +`}strong({tokens:e}){return`${this.parser.parseInline(e)}`}em({tokens:e}){return`${this.parser.parseInline(e)}`}codespan({text:e}){return`${FQ(e,!0)}`}br(e){return`
    `}del({tokens:e}){return`${this.parser.parseInline(e)}`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=IQ(e);if(i===null)return r;e=i;let a=``+r+``,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=IQ(e);if(i===null)return FQ(n);e=i;let a=`${n}`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:FQ(e.text)}},GQ=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}},KQ=class e{options;renderer;textRenderer;constructor(e){this.options=e||wZ,this.options.renderer=this.options.renderer||new WQ,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new GQ}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e,t=!0){let n=``;for(let r=0;r{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new WQ(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new HQ(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new qQ;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=qQ.passThroughHooks.has(n)?e=>{if(this.defaults.async&&qQ.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return UQ.lex(e,t??this.defaults)}parser(e,t){return KQ.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?UQ.lex:UQ.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser():e?KQ.parse:KQ.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?UQ.lex:UQ.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?KQ.parse:KQ.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=` +Please report this to https://github.com/markedjs/marked.`,e){let e=`

    An error occurred:

    `+FQ(n.message+``,!0)+`
    `;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function YQ(e,t){return JQ.parse(e,t)}YQ.options=YQ.setOptions=function(e){return JQ.setOptions(e),YQ.defaults=JQ.defaults,TZ(YQ.defaults),YQ},YQ.getDefaults=CZ,YQ.defaults=wZ,YQ.use=function(...e){return JQ.use(...e),YQ.defaults=JQ.defaults,TZ(YQ.defaults),YQ},YQ.walkTokens=function(e,t){return JQ.walkTokens(e,t)},YQ.parseInline=JQ.parseInline,YQ.Parser=KQ,YQ.parser=KQ.parse,YQ.Renderer=WQ,YQ.TextRenderer=GQ,YQ.Lexer=UQ,YQ.lexer=UQ.lex,YQ.Tokenizer=HQ,YQ.Hooks=qQ,YQ.parse=YQ,YQ.options,YQ.setOptions,YQ.use,YQ.walkTokens,YQ.parseInline,KQ.parse,UQ.lex;function XQ(e){let t=e??BR;return{...bF,...t.edgeless,colors:{...bF.colors,...t.colors}}}function ZQ(e){let t=e?.surface;return Array.isArray(t?.elements)?t.elements:[]}function QQ(e,t,n){let r={...n,placeholder:n.placeholder??``},i=new Bp({element:e,editable:t.kind!==`json`&&t.editable,content:t.kind===`json`?t.content:void 0,extensions:t.kind===`page`?bZ({...r,collab:{provider:t.provider,user:t.user}}):t.kind===`body`?bZ({...r,rowBody:{doc:t.doc,fragment:t.fragment}}):bZ(r),editorProps:{attributes:{class:`dw-prose`}}});return{destroy:()=>i.destroy(),focus:()=>i.commands.focus(`end`),setEditable:e=>i.setEditable(e&&t.kind!==`json`)}}function $Q(e,t){let n=!!t.provider,r,i=null;if(t.provider)r=t.provider.doc;else{i=new Sv,r=i;let e=t.content;i.transact(()=>rR(i.getXmlFragment(`default`),e?.content??[]));let n=ZQ(e);if(n.length){let e=new uR(i,{undo:!1});e.load(n),e.destroy()}}let a={...t};delete a.provider,delete a.content;let o=new OR(e,{doc:r,editable:n&&t.editable,notes:{mount:(e,r)=>{let i=n?r.page?{kind:`page`,provider:t.provider,user:t.user??{name:`?`,color:`#888`},editable:r.editable}:{kind:`body`,doc:r.doc,fragment:r.fragment,editable:r.editable}:{kind:`json`,content:r.page&&t.content?t.content:{type:`doc`,content:nR(r.fragment)}};return t.mountNote?t.mountNote(e,i):QQ(e,i,a)}},labels:XQ(t.labels),files:t.files,links:t.links,embedSource:iU,styles:t.styles,onStyles:t.onStyles,viewKey:t.viewKey,pageTitle:t.pageTitle,undo:n,onError:t.onError,onComment:t.onComment,onCommentSelect:t.onCommentSelect});return{view:o,setEditable:e=>o.setEditable(n&&e),destroy:()=>{o.destroy(),i?.destroy()}}}function e$(e,t,n){let r=Jj(t),i=IV(t);if(!r&&!i)return()=>{};let a=()=>i?RV(e,i.database,i.row):eM(e,r),o=!1,s,c=()=>{clearTimeout(s),s=setTimeout(()=>{o||e.isDestroyed||!a()||(o=!0,l(),n?.())},50)},l=()=>{e.off(`transaction`,c),clearTimeout(u)},u=setTimeout(l,5e3);return e.on(`transaction`,c),c(),()=>{l(),clearTimeout(s)}}var t$=3e4,n$=class extends fm{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=Ph();this.getLocalState()!==null&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&r$(this,t,`timeout`)},pm(t$/10)),e.on(`destroy`,()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit(`destroy`,[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:Ph()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),eg(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},r$=(e,t,n)=>{let r=[];for(let n=0;n0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},i$=(e,t,n=e.states)=>{let r=t.length,i=Pm();M(i,r);for(let a=0;a{let r=mh(t),i=Ph(),a=[],o=[],s=[],c=[],l=N(r);for(let t=0;t0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},o$=(e,t)=>{M(e,0),Km(e,qv(t))},s$=(e,t,n)=>{M(e,1),Km(e,Vv(t,n))},c$=(e,t,n)=>s$(t,n,_h(e)),l$=(e,t,n,r)=>{try{Rv(t,_h(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},u$=(e,t)=>{M(e,2),Km(e,t)},d$=l$,f$=(e,t,n,r,i)=>{let a=N(e);switch(a){case 0:c$(e,t,n);break;case 1:l$(e,n,r,i);break;case 2:d$(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},p$=0,m$=1,h$=4401,g$=4404,_$=4409,v$=class{opts;doc=new Sv;awareness=new n$(this.doc);status=`connecting`;synced=!1;ws=null;retries=0;retryTimer;destroyed=!1;listeners=new Set;constructor(e){this.opts=e,this.doc.on(`update`,this.onDocUpdate),this.awareness.on(`update`,this.onAwarenessUpdate),e.readOnly&&this.awareness.setLocalState(null),window.addEventListener(`beforeunload`,this.onUnload),this.connect()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}destroy(){this.destroyed||(this.destroyed=!0,this.listeners.clear(),clearTimeout(this.retryTimer),window.removeEventListener(`beforeunload`,this.onUnload),r$(this.awareness,[this.doc.clientID],`local`),this.doc.off(`update`,this.onDocUpdate),this.awareness.off(`update`,this.onAwarenessUpdate),this.ws?.close(),this.awareness.destroy(),this.doc.destroy(),this.listeners.clear())}set(e,t=this.synced){(e!==this.status||t!==this.synced)&&(this.status=e,this.synced=t,this.listeners.forEach(e=>e()))}connect(){let e=new WebSocket(`${this.opts.url}?page=${encodeURIComponent(this.opts.page)}`);e.binaryType=`arraybuffer`,this.ws=e,e.onopen=()=>{e.send(this.opts.token()??``);let t=Pm();M(t,p$),o$(t,this.doc),e.send(Lm(t)),this.awareness.getLocalState()!==null&&this.sendAwareness([this.doc.clientID])},e.onmessage=e=>this.onMessage(new Uint8Array(e.data)),e.onclose=t=>{if(this.ws!==e)return;this.ws=null;let n=[...this.awareness.getStates().keys()].filter(e=>e!==this.doc.clientID);r$(this.awareness,n,this),this.destroyed||(t.code===h$||t.code===g$?this.set(`denied`,!1):t.code===_$?this.set(`changed`):(this.set(`offline`),this.retryTimer=setTimeout(()=>this.connect(),Math.min(1e3*2**this.retries++,3e4))))}}onMessage(e){let t=mh(e),n=N(t);if(n===p$){let e=Pm();M(e,p$);let n=f$(t,e,this.doc,this);Im(e)>1&&!this.opts.readOnly&&this.ws?.send(Lm(e)),n===1&&(this.retries=0,this.set(`connected`,!0))}else n===m$&&a$(this.awareness,_h(t),this)}onDocUpdate=(e,t)=>{if(t===this||this.opts.readOnly||this.ws?.readyState!==WebSocket.OPEN)return;let n=Pm();M(n,p$),u$(n,e),this.ws.send(Lm(n))};onAwarenessUpdate=({added:e,updated:t,removed:n},r)=>{r===this||this.opts.readOnly||this.sendAwareness([...e,...t,...n])};sendAwareness(e){if(this.ws?.readyState!==WebSocket.OPEN)return;let t=Pm();M(t,m$),Km(t,i$(this.awareness,e)),this.ws.send(Lm(t))}onUnload=()=>r$(this.awareness,[this.doc.clientID],`unload`)},y$=`.dw-db-peek, .dw-db-pop, .dw-block-menu`,b$={bold:e=>e.chain().focus().toggleBold().run(),italic:e=>e.chain().focus().toggleItalic().run(),strike:e=>e.chain().focus().toggleStrike().run(),code:e=>e.chain().focus().toggleCode().run(),heading1:e=>e.chain().focus().toggleHeading({level:1}).run(),heading2:e=>e.chain().focus().toggleHeading({level:2}).run(),heading3:e=>e.chain().focus().toggleHeading({level:3}).run(),bulletList:e=>e.chain().focus().toggleBulletList().run(),orderedList:e=>e.chain().focus().toggleOrderedList().run(),blockquote:e=>e.chain().focus().toggleBlockquote().run(),codeBlock:e=>e.chain().focus().toggleCodeBlock().run(),underline:e=>e.chain().focus().toggleUnderline().run(),taskList:e=>e.chain().focus().toggleTaskList().run(),callout:e=>e.isActive(`callout`)?e.chain().focus().unsetCallout().run():e.chain().focus().setCallout().run(),table:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),footnote:e=>e.chain().focus().insertFootnote().run(),status:e=>e.chain().focus().insertStatus().run(),tabs:e=>e.chain().focus().insertTabs().run(),pageBreak:e=>e.chain().focus().setPageBreak().run(),emoji:e=>{let{$from:t}=e.state.selection,n=t.parent.textBetween(Math.max(0,t.parentOffset-1),t.parentOffset,``,` `);return e.chain().focus().insertContent(n&&n!==` `?` :`:`:`).run()},subpages:e=>e.chain().focus().insertSubpages().run(),undo:e=>e.chain().focus().undo().run(),redo:e=>e.chain().focus().redo().run()},x$=[[`bold`,e=>e.isActive(`bold`)],[`italic`,e=>e.isActive(`italic`)],[`strike`,e=>e.isActive(`strike`)],[`code`,e=>e.isActive(`code`)],[`heading1`,e=>e.isActive(`heading`,{level:1})],[`heading2`,e=>e.isActive(`heading`,{level:2})],[`heading3`,e=>e.isActive(`heading`,{level:3})],[`bulletList`,e=>e.isActive(`bulletList`)],[`orderedList`,e=>e.isActive(`orderedList`)],[`blockquote`,e=>e.isActive(`blockquote`)],[`codeBlock`,e=>e.isActive(`codeBlock`)],[`underline`,e=>e.isActive(`underline`)],[`taskList`,e=>e.isActive(`taskList`)],[`callout`,e=>e.isActive(`callout`)],[`table`,e=>e.isActive(`table`)],[`tabs`,e=>e.isActive(`tabs`)]],S$=class{el;send;editor;provider=null;lastState=``;editable=!0;overlay=!1;overlays=new MutationObserver(()=>this.reportOverlay());inner=null;onFocusIn=e=>this.track(e.target);canvas=null;canvasEl=null;mode=`page`;lastContent=null;title=``;labels={...BR,blocks:{...BR.blocks}};transcribeOn=!1;words=null;pendingTranscripts=new Map;nextTranscript=1;pendingSubpages=new Map;nextSubpages=1;picked=null;files={resolve:e=>e};constructor(e,t){this.el=e,this.send=t,Object.defineProperty(this.files,"transcribe",{get:()=>this.transcribeOn?(e,t)=>this.requestTranscript(e,t):void 0}),this.editor=this.create({}),this.overlays.observe(document.body,{childList:!0}),document.addEventListener(`focusin`,this.onFocusIn),t({type:`ready`,version:5})}receive(e){try{let t=typeof e==`string`?JSON.parse(e):e;this.handle(t)}catch(e){this.send({type:`error`,message:e instanceof Error?e.message:String(e)})}}get content(){return this.editor.getJSON()}destroy(){this.overlays.disconnect(),document.removeEventListener(`focusin`,this.onFocusIn),this.setInner(null),this.closeCanvas(),this.editor.destroy(),this.provider?.destroy()}handle(e){switch(e.type){case`hello`:this.send({type:`ready`,version:5}),this.lastState=``,this.reportState();return;case`setContent`:this.lastContent=e.content,this.editor.commands.setContent(e.content??``,{emitUpdate:!1}),this.reportState(),this.mode===`edgeless`&&!this.provider&&this.openCanvas();return;case`setEditable`:this.editable=e.editable,this.editor.setEditable(e.editable),this.canvas?.setEditable(e.editable);return;case`setTheme`:document.documentElement.classList.toggle(`dark`,e.dark);return;case`setLayout`:{let t=document.documentElement.classList;t.toggle(`dw-full-width`,e.fullWidth),t.toggle(`dw-font-serif`,e.font===`serif`),t.toggle(`dw-font-mono`,e.font===`mono`);return}case`command`:{let t=b$[e.command];if(!t)throw Error(`unknown command ${e.command}`);t(this.target);return}case`focus`:this.editor.commands.focus();return;case`blur`:this.editor.commands.blur();return;case`connect`:this.connect(e);return;case`follow`:e$(this.editor,e.hash);return;case`setMode`:this.mode=e.mode===`edgeless`?`edgeless`:`page`,typeof e.title==`string`&&(this.title=e.title),this.mode===`edgeless`?this.openCanvas():this.closeCanvas();return;case`dismiss`:[...document.querySelectorAll(y$)].at(-1)?.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0,cancelable:!0}));return;case`setAi`:this.transcribeOn=e.transcribe,this.words=e.words,Object.assign(this.labels.blocks,{transcribe:e.words.transcribe,transcribeHint:e.words.transcribeHint,transcribing:e.words.transcribing,transcribeFailed:e.words.transcribeFailed}),w$(this.editor);return;case`getSelection`:{let e=this.target,{from:t,to:n}=e.state.selection;this.picked={editor:e,from:t,to:n},this.send({type:`selection`,text:e.state.doc.textBetween(t,n,` `),before:e.state.doc.textBetween(Math.max(0,t-4e3),t,` -`)});return}case`insertMarkdown`:this.insertMarkdown(e.markdown,e.mode);return;case`transcribed`:{let t=this.pendingTranscripts.get(e.id);if(!t)return;this.pendingTranscripts.delete(e.id),e.result&&this.words?t.resolve(Qp(e.result,this.words,GZ)):t.reject(Error(e.error||this.labels.blocks.transcribeFailed));return}default:throw Error(`unknown message ${e.type}`)}}requestTranscript(e,t){let n=this.nextTranscript++;return new Promise((r,i)=>{this.pendingTranscripts.set(n,{resolve:r,reject:i}),this.send({type:`transcribe`,id:n,src:e,name:t})})}insertMarkdown(e,t){let n=this.picked,r=n&&!n.editor.isDestroyed?n.editor:this.target,i=GZ(e);if(!i.trim())return;let a=r.state.doc.content.size,o=Math.min(n?.from??r.state.selection.from,a),s=Math.min(n?.to??r.state.selection.to,a);if(t===`replace`)r.chain().focus().insertContentAt({from:o,to:s},i).run();else{let e=r.state.doc.resolve(s);r.chain().focus().insertContentAt(e.depth>=1?e.after(1):s,i).run()}this.picked=null}connect(e){this.provider?.destroy();let t=new BZ({url:e.url,page:e.page,token:()=>e.token});t.onChange(()=>this.send({type:`collab`,status:t.status})),this.provider=t,this.editor.destroy(),this.editor=this.create({collab:{provider:t,user:e.user}}),this.mode===`edgeless`&&this.openCanvas()}openCanvas(){this.closeCanvas();let e=document.createElement(`div`);e.className=`dw-bridge-canvas`,document.body.append(e),this.canvasEl=e,this.el.hidden=!0,this.canvas=xZ(e,{provider:this.provider??void 0,content:this.provider?void 0:this.lastContent??this.editor.getJSON(),editable:this.editable&&!!this.provider,pageTitle:()=>this.title,onNavigate:e=>this.send({type:`navigate`,path:e}),onError:e=>this.send({type:`error`,message:e instanceof Error?e.message:String(e)})})}closeCanvas(){this.canvas?.destroy(),this.canvas=null,this.canvasEl?.remove(),this.canvasEl=null,this.el.hidden=!1}create(e){return this.el.replaceChildren(),new Vp({element:this.el,editable:this.editable,extensions:UY({...e,files:this.files,labels:this.labels,onNavigate:e=>this.send({type:`navigate`,path:e})}),editorProps:{attributes:{class:`dw-prose`}},onUpdate:({editor:e})=>this.send({type:`change`,content:e.getJSON()}),onSelectionUpdate:()=>this.reportState(),onTransaction:()=>this.reportState(),onFocus:()=>this.reportState(),onBlur:()=>this.reportState()})}get target(){return this.inner&&!this.inner.isDestroyed?this.inner:this.editor}track(e){let t=(e instanceof Element?e.closest(`.ProseMirror`):null)?.editor;t&&(this.setInner(t===this.editor?null:t),this.reportState())}innerChanged=()=>this.reportState();innerGone=()=>{this.setInner(null),this.reportState()};setInner(e){if(e!==this.inner){if(this.inner){for(let e of[`selectionUpdate`,`transaction`,`focus`,`blur`])this.inner.off(e,this.innerChanged);this.inner.off(`destroy`,this.innerGone)}if(this.inner=e,e){for(let t of[`selectionUpdate`,`transaction`,`focus`,`blur`])e.on(t,this.innerChanged);e.on(`destroy`,this.innerGone)}}}reportOverlay(){let e=document.querySelector(VZ)!==null;e!==this.overlay&&(this.overlay=e,this.send({type:`overlay`,open:e}))}reportState(){let e=this.target;if(e.isDestroyed)return;let t={active:UZ.filter(([,t])=>t(e)).map(([e])=>e),canUndo:e.can().undo(),canRedo:e.can().redo(),focused:e.isFocused},n=JSON.stringify(t);n!==this.lastState&&(this.lastState=n,this.send({type:`state`,state:t}))}};function GZ(e){return _Z.parse(e.trim(),{async:!1,gfm:!0})}function KZ(e){if(e.isDestroyed)return;let t=e.view.props.nodeViews??{},n=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)]));e.view.setProps({nodeViews:n})}function qZ(e){let t=JSON.stringify(e);window.DocwellNative?window.DocwellNative.postMessage(t):(window.parent.postMessage(t,`*`),console.debug(`[docwell bridge]`,e))}var JZ=new WZ(document.getElementById(`editor`),qZ);window.docwell={receive:e=>JZ.receive(e)}; +`)});return}case`insertMarkdown`:this.insertMarkdown(e.markdown,e.mode);return;case`transcribed`:{let t=this.pendingTranscripts.get(e.id);if(!t)return;this.pendingTranscripts.delete(e.id),e.result&&this.words?t.resolve(Zp(e.result,this.words,C$)):t.reject(Error(e.error||this.labels.blocks.transcribeFailed));return}case`subpageList`:{let t=this.pendingSubpages.get(e.id);this.pendingSubpages.delete(e.id),t?.(Array.isArray(e.pages)?e.pages:[]);return}default:throw Error(`unknown message ${e.type}`)}}requestSubpages(){let e=this.nextSubpages++;return new Promise(t=>{let n=setTimeout(()=>{this.pendingSubpages.delete(e),t([])},1e4);this.pendingSubpages.set(e,e=>{clearTimeout(n),t(e)}),this.send({type:`subpages`,id:e})})}requestTranscript(e,t){let n=this.nextTranscript++;return new Promise((r,i)=>{this.pendingTranscripts.set(n,{resolve:r,reject:i}),this.send({type:`transcribe`,id:n,src:e,name:t})})}insertMarkdown(e,t){let n=this.picked,r=n&&!n.editor.isDestroyed?n.editor:this.target,i=C$(e);if(!i.trim())return;let a=r.state.doc.content.size,o=Math.min(n?.from??r.state.selection.from,a),s=Math.min(n?.to??r.state.selection.to,a);if(t===`replace`)r.chain().focus().insertContentAt({from:o,to:s},i).run();else{let e=r.state.doc.resolve(s);r.chain().focus().insertContentAt(e.depth>=1?e.after(1):s,i).run()}this.picked=null}connect(e){this.provider?.destroy();let t=new v$({url:e.url,page:e.page,token:()=>e.token});t.onChange(()=>this.send({type:`collab`,status:t.status})),this.provider=t,this.editor.destroy(),this.editor=this.create({collab:{provider:t,user:e.user}}),this.mode===`edgeless`&&this.openCanvas()}openCanvas(){this.closeCanvas();let e=document.createElement(`div`);e.className=`dw-bridge-canvas`,document.body.append(e),this.canvasEl=e,this.el.hidden=!0,this.canvas=$Q(e,{provider:this.provider??void 0,content:this.provider?void 0:this.lastContent??this.editor.getJSON(),editable:this.editable&&!!this.provider,pageTitle:()=>this.title,onNavigate:e=>this.send({type:`navigate`,path:e}),onError:e=>this.send({type:`error`,message:e instanceof Error?e.message:String(e)})})}closeCanvas(){this.canvas?.destroy(),this.canvas=null,this.canvasEl?.remove(),this.canvasEl=null,this.el.hidden=!1}create(e){return this.el.replaceChildren(),new Bp({element:this.el,editable:this.editable,extensions:bZ({...e,files:this.files,labels:this.labels,children:()=>this.requestSubpages(),onNavigate:e=>this.send({type:`navigate`,path:e})}),editorProps:{attributes:{class:`dw-prose`}},onUpdate:({editor:e})=>this.send({type:`change`,content:e.getJSON()}),onSelectionUpdate:()=>this.reportState(),onTransaction:()=>this.reportState(),onFocus:()=>this.reportState(),onBlur:()=>this.reportState()})}get target(){return this.inner&&!this.inner.isDestroyed?this.inner:this.editor}track(e){let t=(e instanceof Element?e.closest(`.ProseMirror`):null)?.editor;t&&(this.setInner(t===this.editor?null:t),this.reportState())}innerChanged=()=>this.reportState();innerGone=()=>{this.setInner(null),this.reportState()};setInner(e){if(e!==this.inner){if(this.inner){for(let e of[`selectionUpdate`,`transaction`,`focus`,`blur`])this.inner.off(e,this.innerChanged);this.inner.off(`destroy`,this.innerGone)}if(this.inner=e,e){for(let t of[`selectionUpdate`,`transaction`,`focus`,`blur`])e.on(t,this.innerChanged);e.on(`destroy`,this.innerGone)}}}reportOverlay(){let e=document.querySelector(y$)!==null;e!==this.overlay&&(this.overlay=e,this.send({type:`overlay`,open:e}))}reportState(){let e=this.target;if(e.isDestroyed)return;let t={active:x$.filter(([,t])=>t(e)).map(([e])=>e),canUndo:e.can().undo(),canRedo:e.can().redo(),focused:e.isFocused},n=JSON.stringify(t);n!==this.lastState&&(this.lastState=n,this.send({type:`state`,state:t}))}};function C$(e){return YQ.parse(e.trim(),{async:!1,gfm:!0})}function w$(e){if(e.isDestroyed)return;let t=e.view.props.nodeViews??{},n=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)]));e.view.setProps({nodeViews:n})}function T$(e){let t=JSON.stringify(e);window.DocwellNative?window.DocwellNative.postMessage(t):(window.parent.postMessage(t,`*`),console.debug(`[docwell bridge]`,e))}var E$=new S$(document.getElementById(`editor`),T$);window.docwell={receive:e=>E$.receive(e)}; diff --git a/Packages/editor-bridge/src/bridge.test.ts b/Packages/editor-bridge/src/bridge.test.ts index d2af6ed..49207ed 100644 --- a/Packages/editor-bridge/src/bridge.test.ts +++ b/Packages/editor-bridge/src/bridge.test.ts @@ -248,4 +248,49 @@ describe("EditorBridge AI", () => { bridge.receive({ type: "setAi", transcribe: false, words }); expect(el.querySelector("[data-testid=file-transcribe]")).toBeNull(); }); + + it("inserts footnotes, status badges, tabs, page breaks and subpages from the toolbar", () => { + const { bridge, sent } = setup(); + bridge.receive({ type: "setEditable", editable: true }); + bridge.receive({ type: "setContent", content: doc }); + bridge.receive({ type: "command", command: "footnote" }); + bridge.receive({ type: "command", command: "status" }); + const inline = JSON.stringify(bridge.content); + expect(inline).toContain('"type":"footnote"'); + expect(inline).toContain('"type":"status"'); + + for (const command of ["pageBreak", "subpages", "tabs"] as const) { + bridge.receive({ type: "command", command }); + } + const types = (bridge.content.content ?? []).map((n) => n.type); + expect(types).toEqual(expect.arrayContaining(["pageBreak", "subpages", "tabs"])); + const state = sent.filter((m) => m.type === "state").at(-1); + expect(state?.type === "state" && state.state.active).toContain("tabs"); + }); + + it("opens the emoji list after a space", () => { + // jsdom draws no layout; the list scrolls its active row into view. + Element.prototype.scrollIntoView ??= () => {}; + const { bridge } = setup(); + bridge.receive({ type: "setEditable", editable: true }); + bridge.receive({ type: "setContent", content: doc }); + bridge.receive({ type: "command", command: "emoji" }); + expect(JSON.stringify(bridge.content)).toContain("Hello :"); + }); + + it("asks the app for the page's subpages and lists them", async () => { + const { bridge, sent, el } = setup(); + bridge.receive({ type: "setContent", content: { type: "doc", content: [{ type: "subpages" }] } }); + const ask = sent.find((m) => m.type === "subpages"); + expect(ask).toBeDefined(); + bridge.receive({ + type: "subpageList", + id: ask!.type === "subpages" ? ask!.id : 0, + pages: [{ id: "c1", title: "Setup", icon: "🛠" }], + }); + await Promise.resolve(); + await Promise.resolve(); + expect(el.querySelector(".dw-subpages a")?.getAttribute("href")).toBe("/p/c1"); + expect(el.querySelector(".dw-subpages")?.textContent).toContain("Setup"); + }); }); diff --git a/Packages/editor-bridge/src/bridge.ts b/Packages/editor-bridge/src/bridge.ts index 7c68e0a..f3c96c5 100644 --- a/Packages/editor-bridge/src/bridge.ts +++ b/Packages/editor-bridge/src/bridge.ts @@ -15,6 +15,7 @@ import { type EditorMessage, type EditorState, type HostMessage, + type SubpageRef, type TranscribeWords, } from "./protocol"; @@ -39,6 +40,21 @@ const commands: Record boolean> = { callout: (e) => e.isActive("callout") ? e.chain().focus().unsetCallout().run() : e.chain().focus().setCallout().run(), table: (e) => e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(), + footnote: (e) => e.chain().focus().insertFootnote().run(), + status: (e) => e.chain().focus().insertStatus().run(), + tabs: (e) => e.chain().focus().insertTabs().run(), + pageBreak: (e) => e.chain().focus().setPageBreak().run(), + // Opens the ":" emoji list, which starts after a space or at the start of a line. + emoji: (e) => { + const { $from } = e.state.selection; + const before = $from.parent.textBetween(Math.max(0, $from.parentOffset - 1), $from.parentOffset, "", " "); + return e + .chain() + .focus() + .insertContent(before && before !== " " ? " :" : ":") + .run(); + }, + subpages: (e) => e.chain().focus().insertSubpages().run(), undo: (e) => e.chain().focus().undo().run(), redo: (e) => e.chain().focus().redo().run(), }; @@ -60,6 +76,7 @@ const activeChecks: [Command, (e: Editor) => boolean][] = [ ["taskList", (e) => e.isActive("taskList")], ["callout", (e) => e.isActive("callout")], ["table", (e) => e.isActive("table")], + ["tabs", (e) => e.isActive("tabs")], ]; /** @@ -99,6 +116,9 @@ export class EditorBridge { { resolve: (html: string) => void; reject: (e: Error) => void } >(); private nextTranscript = 1; + /** Subpage lists the app is looking up, by request id. */ + private readonly pendingSubpages = new Map void>(); + private nextSubpages = 1; /** The range "getSelection" reported, for "insertMarkdown". */ private picked: { editor: Editor; from: number; to: number } | null = null; /** @@ -237,11 +257,33 @@ export class EditorBridge { else p.reject(new Error(msg.error || this.labels.blocks.transcribeFailed)); return; } + case "subpageList": { + const done = this.pendingSubpages.get(msg.id); + this.pendingSubpages.delete(msg.id); + done?.(Array.isArray(msg.pages) ? msg.pages : []); + return; + } default: throw new Error(`unknown message ${(msg as { type: string }).type}`); } } + /** Asks the app for the page's subpages; an app that does not answer in 10 s lists none. */ + private requestSubpages(): Promise { + const id = this.nextSubpages++; + return new Promise((resolve) => { + const timer = setTimeout(() => { + this.pendingSubpages.delete(id); + resolve([]); + }, 10_000); + this.pendingSubpages.set(id, (pages) => { + clearTimeout(timer); + resolve(pages); + }); + this.send({ type: "subpages", id }); + }); + } + /** Asks the app to transcribe a file; resolves with the HTML to insert. */ private requestTranscript(src: string, name: string): Promise { const id = this.nextTranscript++; @@ -319,6 +361,7 @@ export class EditorBridge { ...opts, files: this.files, labels: this.labels, + children: () => this.requestSubpages(), onNavigate: (path) => this.send({ type: "navigate", path }), }), editorProps: { attributes: { class: "dw-prose" } }, diff --git a/Packages/editor-bridge/src/protocol.ts b/Packages/editor-bridge/src/protocol.ts index 6da43b8..dd59e2f 100644 --- a/Packages/editor-bridge/src/protocol.ts +++ b/Packages/editor-bridge/src/protocol.ts @@ -22,6 +22,12 @@ export type Command = | "taskList" | "callout" | "table" + | "footnote" + | "status" + | "tabs" + | "pageBreak" + | "emoji" + | "subpages" | "undo" | "redo"; @@ -70,7 +76,16 @@ export type HostMessage = id: number; error?: string; result?: { name: string; text: string; summary: string; summaryError?: string }; - }; + } + /** The answer to a "subpages" request: the page's child pages, in order. */ + | { type: "subpageList"; id: number; pages: SubpageRef[] }; + +/** A child page the subpages block lists. */ +export interface SubpageRef { + id: string; + title: string; + icon?: string; +} /** The words of the Transcribe button and of what it inserts. */ export interface TranscribeWords { @@ -109,7 +124,9 @@ export type EditorMessage = | { type: "selection"; text: string; before: string } /** The user asked to transcribe a file (src is its /api/v1/files/ path); answer with "transcribed". */ | { type: "transcribe"; id: number; src: string; name: string } + /** A subpages block wants the page's child pages; answer with "subpageList". */ + | { type: "subpages"; id: number } | { type: "error"; message: string }; /** Bumped when a message changes shape, so the app can refuse a stale bundle. */ -export const PROTOCOL_VERSION = 4; +export const PROTOCOL_VERSION = 5; diff --git a/Packages/editor/package.json b/Packages/editor/package.json index d9f9e61..7b89c09 100644 --- a/Packages/editor/package.json +++ b/Packages/editor/package.json @@ -14,7 +14,8 @@ "./edgeless": "./src/edgeless.ts", "./ai": "./src/ai.ts", "./files": "./src/files.ts", - "./labels": "./src/labels.ts" + "./labels": "./src/labels.ts", + "./emoji": "./src/emoji.ts" }, "scripts": { "test": "vitest run" diff --git a/Packages/editor/src/columns.test.ts b/Packages/editor/src/columns.test.ts index 3f4511a..8f47fca 100644 --- a/Packages/editor/src/columns.test.ts +++ b/Packages/editor/src/columns.test.ts @@ -29,7 +29,7 @@ function inColumn(e: Editor, i: number): number { } describe("columns", () => { - it("inserts two to four columns from the slash menu and puts the caret in the first", () => { + it("inserts two to five columns from the slash menu and puts the caret in the first", () => { const e = setup("

    "); const cmd = filterCommands(slashCommands(englishLabels), "3 columns")[0]; expect(cmd?.id).toBe("columns3"); @@ -63,9 +63,10 @@ describe("columns", () => { expect(row(e)?.content?.[2]?.content?.[0]?.content?.[0]?.text).toBe("B"); }); - it("stops at four columns", () => { + it("stops at five columns", () => { const e = setup("

    "); - e.commands.insertColumns(4); + e.commands.insertColumns(5); + expect(row(e)?.content).toHaveLength(5); e.commands.setTextSelection(inColumn(e, 0)); expect(e.commands.addColumn()).toBe(false); }); diff --git a/Packages/editor/src/columns.ts b/Packages/editor/src/columns.ts index e328958..14e34ae 100644 --- a/Packages/editor/src/columns.ts +++ b/Packages/editor/src/columns.ts @@ -19,7 +19,7 @@ declare module "@tiptap/core" { } export const minColumns = 2; -export const maxColumns = 4; +export const maxColumns = 5; /** No column gets narrower than this share of the row (percent). */ const minWidth = 10; @@ -60,7 +60,7 @@ function isEmptyColumn(col: PMNode): boolean { } /** - * Side-by-side columns: a row ("columns") of two to four columns, each + * Side-by-side columns: a row ("columns") of two to five columns, each * holding ordinary blocks. Columns share the width equally until someone * drags the line between two of them. On narrow screens they stack. * Backspace in an empty column removes it, and a row left with one column diff --git a/Packages/editor/src/docmostblocks.test.ts b/Packages/editor/src/docmostblocks.test.ts new file mode 100644 index 0000000..a49e85e --- /dev/null +++ b/Packages/editor/src/docmostblocks.test.ts @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { Editor, type JSONContent } from "@tiptap/core"; +import { afterEach, describe, expect, it } from "vitest"; +import { emojiMatches } from "./emojipicker"; +import { docwellExtensions } from "./extensions"; +import { cleanNoteContent, footnotesOf, noteText } from "./footnotes"; +import { englishLabels } from "./labels"; +import { mediaKind } from "./media"; +import { filterCommands, slashCommands } from "./slash"; +import { parseBlockLink, syncedPath } from "./syncedpage"; + +let editor: Editor | undefined; +afterEach(() => editor?.destroy()); + +function setup(content: string | JSONContent, opts: Parameters[0] = {}) { + editor = new Editor({ extensions: docwellExtensions(opts), content }); + return editor; +} + +const json = (e: Editor) => e.getJSON().content as JSONContent[]; + +describe("page breaks, status badges and footnotes", () => { + it("inserts a page break and reads it back from HTML", () => { + const e = setup("

    "); + e.commands.setPageBreak(); + expect(json(e)[0]?.type).toBe("pageBreak"); + const again = setup(e.getHTML()); + expect(json(again)[0]?.type).toBe("pageBreak"); + }); + + it("keeps a status badge's words and colour through HTML", () => { + const e = setup('

    Plan In review

    '); + expect(json(e)[0]?.content?.[1]).toMatchObject({ type: "status", attrs: { text: "In review", color: "green" } }); + expect(e.getHTML()).toContain(">In review"); + expect(e.getText()).toBe("Plan In review"); + }); + + it("gives a new status badge the default words", () => { + const e = setup("

    "); + e.commands.insertStatus(); + expect(json(e)[0]?.content?.[0]).toMatchObject({ type: "status", attrs: { text: "To do", color: "gray" } }); + }); + + it("numbers footnotes in reading order and keeps their text", () => { + const e = setup( + '

    One two

    ', + ); + expect(footnotesOf(e.state.doc).map((f) => f.text)).toEqual(["First", "Second"]); + expect(e.getHTML()).toContain('data-text="Second"'); + }); +}); + +describe("tabs", () => { + it("inserts two named tabs and puts the caret in the first", () => { + const e = setup("

    "); + e.commands.insertTabs(); + const tabs = json(e)[0]; + expect(tabs?.type).toBe("tabs"); + expect(tabs?.content?.map((t) => t.attrs?.title)).toEqual(["Tab 1", "Tab 2"]); + expect(e.state.selection.$from.node(-1).type.name).toBe("tab"); + }); + + it("reads tabs back from HTML", () => { + const e = setup( + '

    ⌘

    ' + + '

    Ctrl

    ', + ); + expect(json(e)[0]?.content?.[1]).toMatchObject({ type: "tab", attrs: { title: "Windows" } }); + }); +}); + +describe("video and audio", () => { + it("tells video from audio", () => { + expect(mediaKind("video/mp4", "a.mp4")).toBe("video"); + expect(mediaKind("", "talk.m4a")).toBe("audio"); + expect(mediaKind("application/pdf", "a.pdf")).toBeNull(); + }); + + it("keeps a player's file through HTML", () => { + const e = setup( + '', + ); + expect(json(e)[0]).toMatchObject({ type: "video", attrs: { src: "/api/v1/files/abc", name: "demo.mp4" } }); + expect(json(e)[1]).toMatchObject({ type: "audio", attrs: { src: "/api/v1/files/def" } }); + }); +}); + +describe("synced blocks", () => { + it("reads the page and block from a copied block link", () => { + expect(parseBlockLink("https://docs.example.com/p/Ab12_x#b-k3j9x2a1")).toEqual({ + page: "Ab12_x", + block: "k3j9x2a1", + }); + expect(parseBlockLink("/p/Ab12_x")).toBeNull(); + expect(parseBlockLink("just text")).toBeNull(); + }); + + it("stores the block on the synced page and links to it", () => { + const e = setup('
    '); + expect(json(e)[0]).toMatchObject({ type: "syncedPage", attrs: { page: "Ab12", block: "k3j9x2a1" } }); + expect(e.getHTML()).toContain(`href="${syncedPath("Ab12", "k3j9x2a1")}"`); + }); +}); + +describe("the slash menu", () => { + const all = slashCommands( + englishLabels, + { resolve: (s) => s, upload: async () => ({ url: "", name: "", mime: "", size: 0 }) }, + undefined, + { search: async () => [], children: async () => [] }, + ); + const ids = (cmds: typeof all) => cmds.flatMap((c) => [c.id, ...(c.children ?? []).map((k) => k.id)]); + + it("offers the blocks Docmost has", () => { + for (const id of [ + "columns5", + "video", + "audio", + "pageBreak", + "footnote", + "tabs", + "status", + "emoji", + "subpages", + "syncedBlock", + ]) { + expect(ids(all)).toContain(id); + } + }); + + it("finds them by name", () => { + expect(filterCommands(all, "page break")[0]?.id).toBe("pageBreak"); + expect(filterCommands(all, "5 col")[0]?.id).toBe("columns5"); + }); + + it("puts five columns in a row", () => { + const e = setup("

    "); + filterCommands(all, "5 columns")[0]!.run(e, { from: 1, to: 1 }); + expect(json(e)[0]?.content).toHaveLength(5); + }); +}); + +describe("emoji", () => { + it("finds emoji by word and offers some before a word is typed", () => { + expect(emojiMatches("thumbs")[0]?.char).toBe("👍"); + expect(emojiMatches("").length).toBeGreaterThan(0); + }); +}); + +describe("formatted footnotes", () => { + it("keeps text runs, marks and safe links, and drops anything else", () => { + const content = cleanNoteContent([ + { type: "text", text: "See " }, + { type: "text", text: "docs", marks: [{ type: "bold" }, { type: "link", attrs: { href: "https://x.dev" } }] }, + { + type: "text", + text: "!", + marks: [{ type: "link", attrs: { href: "javascript:alert(1)" } }, { type: "heading" }], + }, + { type: "paragraph", content: [{ type: "text", text: "no" }] }, + { type: "hardBreak" }, + ]); + expect(content).toEqual([ + { type: "text", text: "See " }, + { type: "text", text: "docs", marks: [{ type: "bold" }, { type: "link", attrs: { href: "https://x.dev" } }] }, + { type: "text", text: "!" }, + ]); + expect(noteText(content)).toBe("See docs!"); + expect(cleanNoteContent("text")).toBeNull(); + }); + + it("keeps a footnote's formatted text through HTML", () => { + const content = [{ type: "text", text: "Bold", marks: [{ type: "bold" }] }]; + const e = setup( + `

    A

    `, + ); + expect(footnotesOf(e.state.doc)[0]).toMatchObject({ text: "Bold", content }); + const again = setup(e.getHTML()); + expect(footnotesOf(again.state.doc)[0]?.content).toEqual(content); + }); +}); diff --git a/Packages/editor/src/editor.css b/Packages/editor/src/editor.css index a37eb90..f5308b5 100644 --- a/Packages/editor/src/editor.css +++ b/Packages/editor/src/editor.css @@ -2969,3 +2969,320 @@ .dark .dw-suggest-del { --dw-suggest-del: #ff8a7a; } + +/* ---- Page break (pagebreak.ts): a labelled dashed line on screen, a new page in print ---- */ +.dw-prose .dw-page-break { + position: relative; + height: 24px; + margin: 12px 0; + break-after: page; +} +.dw-prose .dw-page-break::before { + content: ""; + position: absolute; + top: 50%; + left: 0; + right: 0; + border-top: 1px dashed var(--color-line-strong, var(--color-line)); +} +.dw-prose .dw-page-break::after { + content: attr(data-label); + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + padding: 0 8px; + background: var(--color-surface); + font-family: var(--font-sans); + font-size: 11px; + letter-spacing: 0.04em; + text-transform: uppercase; + color: var(--color-ink-faint); +} +.dw-prose .dw-page-break.ProseMirror-selectednode::before { + border-top-color: var(--color-accent); +} +@media print { + .dw-prose .dw-page-break { + height: 0; + margin: 0; + } + .dw-prose .dw-page-break::before, + .dw-prose .dw-page-break::after { + display: none; + } +} + +/* ---- Status badges (status.ts) ---- */ +.dw-prose .dw-status { + display: inline-block; + padding: 0 6px; + border-radius: var(--radius-xs, 4px); + background: var(--dw-bg, var(--dw-bg-gray)); + color: var(--dw-c, var(--dw-c-gray)); + font-family: var(--font-sans); + font-size: 0.75em; + font-weight: 600; + line-height: 1.6; + letter-spacing: 0.02em; + text-transform: uppercase; + vertical-align: 0.1em; + white-space: nowrap; + cursor: default; +} +.dw-prose[contenteditable="true"] .dw-status { + cursor: pointer; +} +.dw-prose .dw-status.ProseMirror-selectednode { + outline: 2px solid var(--color-focus-ring); + outline-offset: 1px; +} +.dw-status-pop { + display: grid; + gap: 8px; + padding: 8px; + /* Room for all nine colours on one line. */ + width: 240px; +} +.dw-status-pop__colors { + display: flex; + flex-wrap: wrap; + gap: 4px; +} +.dw-status-pop__swatch { + width: 20px; + height: 20px; + border: 1px solid var(--color-line); + border-radius: var(--radius-xs, 4px); + background: var(--dw-bg); + cursor: pointer; +} +.dw-status-pop__swatch[aria-checked="true"], +.dw-status-pop__swatch:hover { + outline: 2px solid var(--dw-c); + outline-offset: 1px; +} + +/* ---- Emoji in the ":" list (emojipicker.ts) ---- */ +.dw-suggest__icon--glyph { + font-size: 20px; + line-height: 1; +} + +/* ---- Video and audio (media.ts) ---- */ +.dw-prose .dw-media { + margin: 8px 0; +} +.dw-prose .dw-media video { + display: block; + width: 100%; + max-height: 70vh; + border-radius: var(--radius-md); + background: #000; +} +.dw-prose .dw-media audio { + display: block; + width: 100%; +} +.dw-prose .dw-media.ProseMirror-selectednode { + outline: 2px solid var(--color-focus-ring); + outline-offset: 2px; + border-radius: var(--radius-md); +} + +/* ---- Footnotes (footnotes.ts): numbers in the text, notes at the end ---- */ +.dw-prose sup.dw-footnote { + cursor: pointer; + font-family: var(--font-sans); + font-size: 0.7em; + font-weight: 600; + color: var(--color-accent); +} +.dw-prose sup.dw-footnote::after { + content: "[" attr(data-n) "]"; +} +.dw-prose sup.dw-footnote.ProseMirror-selectednode { + outline: 2px solid var(--color-focus-ring); + border-radius: 2px; +} +.dw-prose .dw-footnotes { + margin-top: 32px; + padding-top: 8px; + border-top: 1px solid var(--color-line); + font-size: 0.875em; + color: var(--color-ink-muted); +} +.dw-prose .dw-footnotes ol { + margin: 0; + padding-left: 1.5em; +} +.dw-prose .dw-footnotes li { + margin: 2px 0; +} +.dw-prose[contenteditable="true"] .dw-footnotes__text { + cursor: text; +} +.dw-prose .dw-footnotes__back { + text-decoration: none; + color: var(--color-accent); +} +.dw-footnote-pop { + padding: 8px; + width: 300px; +} +.dw-footnote-pop__tools { + display: flex; + gap: 2px; + margin-bottom: 6px; +} +.dw-footnote-pop__tool { + display: grid; + place-items: center; + width: 26px; + height: 26px; + border: none; + border-radius: var(--radius-sm); + background: none; + color: var(--color-ink-muted); + cursor: pointer; +} +.dw-footnote-pop__tool:hover { + background: var(--color-surface-hover); + color: var(--color-ink); +} +.dw-footnote-pop__text .dw-footnote-pop__field { + min-height: 64px; + max-height: 40vh; + overflow-y: auto; + padding: 6px 8px; + border: 1px solid var(--color-line); + border-radius: var(--radius-sm); + background: var(--color-surface); + font-family: var(--font-sans); + font-size: 14px; + line-height: 1.5; + outline: none; +} +.dw-footnote-pop__text .dw-footnote-pop__field:focus { + border-color: var(--color-accent); +} +.dw-footnote-pop__field p { + margin: 0; +} +.dw-footnote-pop__field code, +.dw-prose .dw-footnotes code { + padding: 0 3px; + border-radius: 3px; + background: var(--color-surface-hover); + font-family: var(--font-mono); + font-size: 0.9em; +} +.dw-footnote-pop__field a, +.dw-footnote-pop__read a { + color: var(--color-accent); +} +.dw-footnote-pop__read { + font-family: var(--font-sans); + font-size: 14px; + line-height: 1.5; +} + +/* ---- Tabs (tabs.ts) ---- */ +.dw-prose .dw-tabs { + margin: 8px 0; + border: 1px solid var(--color-line); + border-radius: var(--radius-md); +} +.dw-tabs__strip { + display: flex; + align-items: center; + gap: 2px; + padding: 4px 4px 0; + border-bottom: 1px solid var(--color-line); + overflow-x: auto; + font-family: var(--font-sans); + font-size: var(--text-ui-md, 14px); +} +.dw-tabs__tab { + padding: 6px 12px; + border: none; + border-bottom: 2px solid transparent; + background: none; + color: var(--color-ink-muted); + font: inherit; + white-space: nowrap; + cursor: pointer; +} +.dw-tabs__tab:hover { + color: var(--color-ink); +} +.dw-tabs__tab.is-active { + border-bottom-color: var(--color-accent); + color: var(--color-ink); + font-weight: 600; +} +.dw-tabs__action { + display: grid; + place-items: center; + width: 24px; + height: 24px; + border: none; + border-radius: var(--radius-sm); + background: none; + color: var(--color-ink-muted); + font-size: 16px; + line-height: 1; + cursor: pointer; +} +.dw-tabs__action:hover { + background: var(--color-surface-hover); +} +.dw-tabs__delete { + margin-left: auto; +} +.dw-tabs__body { + padding: 4px 16px; +} +.dw-tabs__body > [hidden] { + display: none; +} + +/* ---- Subpages (subpages.ts) ---- */ +.dw-prose .dw-subpages { + margin: 8px 0; + font-family: var(--font-sans); +} +.dw-prose .dw-subpages ul { + margin: 0; + padding: 0; + list-style: none; +} +.dw-prose .dw-subpages__link { + display: flex; + align-items: center; + gap: 8px; + padding: 4px 6px; + border-radius: var(--radius-sm); + color: var(--color-ink); + text-decoration: none; +} +.dw-prose .dw-subpages__link:hover { + background: var(--color-surface-hover); +} +.dw-prose .dw-subpages__link span:last-child { + border-bottom: 1px solid var(--color-line); +} +.dw-prose .dw-subpages__icon { + width: 16px; + text-align: center; +} +.dw-prose .dw-subpages__note { + margin: 0; + font-size: 13px; + color: var(--color-ink-muted); +} + +/* ---- Synced blocks (syncedpage.ts): one block of another page ---- */ +.dw-prose .dw-synced-hidden { + display: none !important; +} diff --git a/Packages/editor/src/emoji.ts b/Packages/editor/src/emoji.ts new file mode 100644 index 0000000..d53f65a --- /dev/null +++ b/Packages/editor/src/emoji.ts @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +// The emoji the page icon picker and the editor's ":" picker offer, by group, +// each with English words to find it by. Any other emoji can still be typed +// or pasted into the search. + +export type EmojiGroup = "smileys" | "people" | "nature" | "food" | "activity" | "travel" | "objects" | "symbols"; + +export interface Emoji { + char: string; + words: string; +} + +const raw: Record = { + smileys: `😀 grinning smile happy|😃 smiley happy|😄 smile laugh|😁 grin beam|😆 laughing|😅 sweat smile|🤣 rofl rolling laugh|😂 joy tears laugh|🙂 slight smile|🙃 upside down|😉 wink|😊 blush happy|😇 innocent halo angel|🥰 love hearts|😍 heart eyes love|🤩 star struck|😘 kiss blow|😋 yum tasty|😛 tongue|😜 wink tongue|🤪 zany crazy|🤑 money|🤗 hug|🤭 oops giggle|🤫 shush quiet|🤔 thinking|🤐 zipper mouth|😐 neutral|😑 expressionless|😶 no mouth|😏 smirk|😒 unamused|🙄 eye roll|😬 grimace|😌 relieved|😔 pensive sad|😪 sleepy|😴 sleeping|😷 mask sick|🤒 thermometer ill|🤯 mind blown exploding|🥳 party celebrate|😎 cool sunglasses|🤓 nerd geek|🧐 monocle|😕 confused|😟 worried|😮 surprised open mouth|😲 astonished|😳 flushed|🥺 pleading|😢 cry tear|😭 sob crying|😱 scream fear|😤 triumph steam|😡 angry rage|🤬 cursing|😈 devil|💀 skull dead|💩 poop|🤡 clown|👻 ghost|👽 alien|🤖 robot|😺 cat smile|❤️ heart love red`, + people: `👋 wave hello hi|🤚 raised back hand|✋ hand stop|👌 ok okay|✌️ victory peace|🤞 crossed fingers luck|🤟 love you|🤘 rock horns|👈 point left|👉 point right|👆 point up|👇 point down|☝️ index up|👍 thumbs up like yes|👎 thumbs down no|✊ fist|👊 punch|👏 clap applause|🙌 raised hands hooray|🤝 handshake deal|🙏 pray thanks please|✍️ writing|💪 muscle strong|🧠 brain|👀 eyes look|👁️ eye|👤 person user|👥 people users team|🧑‍💻 developer coder technologist|🧑‍🏫 teacher|🧑‍🎓 student|🧑‍🔬 scientist|🧑‍🎨 artist|🧑‍🍳 cook chef|🧑‍🔧 mechanic|🧑‍⚕️ doctor health|🧑‍💼 office worker business|🕵️ detective|👷 construction worker|🦸 superhero|🧙 wizard mage|🏃 running|🚶 walking|🧘 yoga meditation|👪 family|👶 baby`, + nature: `🐶 dog puppy|🐱 cat kitten|🐭 mouse|🐰 rabbit bunny|🦊 fox|🐻 bear|🐼 panda|🐨 koala|🐯 tiger|🦁 lion|🐮 cow|🐷 pig|🐸 frog|🐵 monkey|🐔 chicken|🐧 penguin|🐦 bird|🦉 owl|🦄 unicorn|🐝 bee|🐛 bug|🦋 butterfly|🐢 turtle|🐍 snake|🐙 octopus|🐬 dolphin|🐳 whale|🐟 fish|🦈 shark|🌵 cactus|🎄 christmas tree|🌲 evergreen tree|🌳 tree|🌴 palm|🌱 seedling sprout|🌿 herb|🍀 clover luck|🍁 maple leaf|🍂 fallen leaves autumn|🌷 tulip|🌹 rose|🌻 sunflower|🌸 blossom|💐 bouquet flowers|🍄 mushroom|🌍 earth world globe|🌙 moon night|⭐ star|🌟 glowing star|✨ sparkles|⚡ lightning zap|🔥 fire hot|🌈 rainbow|☀️ sun|⛅ cloud sun|☁️ cloud|🌧️ rain|❄️ snow snowflake|💧 droplet water|🌊 wave ocean sea`, + food: `🍏 green apple|🍎 apple red|🍐 pear|🍊 orange|🍋 lemon|🍌 banana|🍉 watermelon|🍇 grapes|🍓 strawberry|🫐 blueberries|🍒 cherries|🍑 peach|🥭 mango|🍍 pineapple|🥥 coconut|🥝 kiwi|🍅 tomato|🥑 avocado|🥦 broccoli|🥕 carrot|🌽 corn|🌶️ pepper hot|🥔 potato|🍞 bread|🥐 croissant|🧀 cheese|🥚 egg|🍳 cooking|🥞 pancakes|🥓 bacon|🍔 burger|🍟 fries|🍕 pizza|🌭 hot dog|🌮 taco|🌯 burrito|🥗 salad|🍝 pasta spaghetti|🍜 ramen noodles|🍣 sushi|🍱 bento|🍦 ice cream|🍩 doughnut|🍪 cookie|🎂 birthday cake|🍰 cake|🧁 cupcake|🍫 chocolate|🍬 candy|🍿 popcorn|☕ coffee|🍵 tea|🧃 juice|🥤 drink|🍺 beer|🍷 wine|🍸 cocktail|🥂 cheers champagne|🍽️ dinner plate`, + activity: `⚽ soccer football|🏀 basketball|🏈 american football|⚾ baseball|🎾 tennis|🏐 volleyball|🏉 rugby|🎱 billiards|🏓 ping pong|🏸 badminton|🥅 goal|⛳ golf|🏹 archery|🎣 fishing|🥊 boxing|🎽 running shirt|⛸️ ice skate|🎿 ski|🏂 snowboard|🏋️ weights gym|🚴 cycling bike|🏆 trophy win|🥇 gold medal first|🥈 silver medal|🥉 bronze medal|🏅 medal|🎖️ military medal|🎫 ticket|🎪 circus|🎭 theatre drama|🎨 art palette paint|🎬 movie clapper film|🎤 microphone sing|🎧 headphones music|🎼 score|🎹 piano|🥁 drum|🎷 saxophone|🎺 trumpet|🎸 guitar|🎻 violin|🎲 dice game|♟️ chess|🎯 target goal dart|🎳 bowling|🎮 video game|🧩 puzzle|🎉 party popper tada|🎊 confetti|🎈 balloon|🎁 gift present`, + travel: `🚗 car|🚕 taxi|🚌 bus|🚎 trolleybus|🏎️ race car|🚓 police car|🚑 ambulance|🚒 fire engine|🚚 truck delivery|🚜 tractor|🛵 scooter|🚲 bicycle|🛴 kick scooter|🚂 train locomotive|🚆 train|🚇 metro subway|✈️ airplane flight|🛫 departure|🛬 arrival|🚀 rocket launch|🛸 ufo|🚁 helicopter|⛵ sailboat|🚤 speedboat|🚢 ship|⚓ anchor|🗺️ map|🧭 compass|🏔️ mountain snow|⛰️ mountain|🌋 volcano|🏕️ camping|🏖️ beach|🏝️ island|🏠 house home|🏡 garden home|🏢 office building|🏬 department store|🏭 factory|🏥 hospital|🏦 bank|🏨 hotel|🏪 shop store|🏫 school|🏛️ classical building|⛪ church|🏰 castle|🗼 tower|🗽 statue liberty|⛲ fountain|🌆 city|🌃 night city|🌉 bridge|🎡 ferris wheel|🎢 roller coaster|🚦 traffic light|🚧 construction|⛽ fuel`, + objects: `📄 page document|📃 curl page|📑 bookmark tabs|📝 memo note write|📋 clipboard|📌 pushpin pin|📍 location pin|📎 paperclip|🖇️ paperclips|📏 ruler|📐 triangle ruler|✂️ scissors|🗂️ dividers index|📁 folder|📂 open folder|🗃️ card box|🗄️ cabinet|🗑️ trash wastebasket|📅 calendar date|📆 tear off calendar|🗓️ spiral calendar|📇 card index|📈 chart up growth|📉 chart down|📊 bar chart stats|📒 ledger|📓 notebook|📔 notebook decorative|📕 book closed|📗 green book|📘 blue book|📙 orange book|📚 books library|📖 open book read|🔖 bookmark|🏷️ label tag|💼 briefcase work|💻 laptop computer|🖥️ desktop computer|⌨️ keyboard|🖱️ mouse computer|📱 phone mobile|☎️ telephone|📞 receiver call|📠 fax|🔋 battery|🔌 plug|💡 bulb idea|🔦 flashlight|🕯️ candle|💰 money bag|💳 card credit|🧾 receipt|✉️ envelope mail|📧 email|📨 incoming mail|📦 package box|📮 postbox|🔒 lock locked|🔓 unlocked|🔑 key|🗝️ old key|🔨 hammer|🛠️ tools|🔧 wrench|🔩 nut bolt|⚙️ gear settings|🧰 toolbox|🧲 magnet|🧪 test tube|🔬 microscope|🔭 telescope|📡 satellite|💊 pill|🩺 stethoscope|🛒 cart shopping|🎓 graduation cap|👑 crown|💎 gem diamond|⏰ alarm clock|⏳ hourglass|⌛ hourglass done|🕐 clock time|📷 camera photo|🎥 video camera|📺 television tv|📻 radio|🔔 bell notification|📣 megaphone announce|📢 loudspeaker|🔍 search magnifier|🧭 compass direction`, + symbols: `✅ check done yes|☑️ ballot check|✔️ check mark|❌ cross no|❎ cross button|➕ plus add|➖ minus|➗ divide|✖️ multiply|❓ question|❔ white question|❗ exclamation important|‼️ double exclamation|⚠️ warning|🚫 prohibited|⛔ no entry|🛑 stop|💯 hundred|🔴 red circle|🟠 orange circle|🟡 yellow circle|🟢 green circle|🔵 blue circle|🟣 purple circle|⚫ black circle|⚪ white circle|🟥 red square|🟧 orange square|🟨 yellow square|🟩 green square|🟦 blue square|🟪 purple square|⬛ black square|⬜ white square|🔶 orange diamond|🔷 blue diamond|♻️ recycle|⚛️ atom|☮️ peace|☯️ yin yang|♾️ infinity|💲 dollar|💱 exchange|©️ copyright|®️ registered|™️ trademark|🔝 top|🔜 soon|🆕 new|🆓 free|🆗 ok|🆙 up|🆒 cool|ℹ️ info information|🔤 abc letters|🔢 numbers|#️⃣ hash|➡️ right arrow|⬅️ left arrow|⬆️ up arrow|⬇️ down arrow|🔄 refresh sync|🔁 repeat|▶️ play|⏸️ pause|⏹️ stop|⏩ fast forward|💬 speech chat comment|💭 thought|🗯️ anger bubble|💤 sleep zzz|💥 boom collision|💫 dizzy|🎵 music note|🔗 link|🏁 finish flag|🚩 red flag|🏳️ white flag|🏴 black flag|💜 purple heart|💙 blue heart|💚 green heart|💛 yellow heart|🧡 orange heart|🖤 black heart|💔 broken heart`, +}; + +export const emojiGroups = Object.keys(raw) as EmojiGroup[]; + +export const emojiByGroup: Record = Object.fromEntries( + emojiGroups.map((g) => [ + g, + raw[g].split("|").map((entry) => { + const [char = "", ...words] = entry.trim().split(" "); + return { char, words: words.join(" ") }; + }), + ]), +) as Record; + +/** The emoji whose words start with every word of the query, in group order. */ +export function searchEmoji(query: string): Emoji[] { + const terms = query.toLowerCase().split(/\s+/).filter(Boolean); + if (!terms.length) return []; + const seen = new Set(); + const out: Emoji[] = []; + for (const g of emojiGroups) { + for (const e of emojiByGroup[g]) { + if (seen.has(e.char)) continue; + const words = e.words.split(" "); + if (terms.every((t) => words.some((w) => w.startsWith(t)))) { + seen.add(e.char); + out.push(e); + } + } + } + return out; +} + +/** Text that is itself an icon: a few characters with no letters or digits, as the server keeps at most 32 bytes. */ +export function typedEmoji(text: string): string | null { + const t = text.trim(); + if (!t || /[\p{L}\p{N}]/u.test(t) || new TextEncoder().encode(t).length > 32) return null; + return /\p{Extended_Pictographic}/u.test(t) ? t : null; +} + +const recentKey = "docwell.recentEmoji"; + +/** The emoji this browser picked last, newest first. */ +export function recentEmoji(): string[] { + try { + const list = JSON.parse(localStorage.getItem(recentKey) ?? "[]"); + return Array.isArray(list) ? list.filter((x) => typeof x === "string").slice(0, 16) : []; + } catch { + return []; + } +} + +export function rememberEmoji(char: string) { + try { + localStorage.setItem(recentKey, JSON.stringify([char, ...recentEmoji().filter((c) => c !== char)].slice(0, 16))); + } catch { + // Private windows may refuse storage; the picker works without it. + } +} diff --git a/Packages/editor/src/emojipicker.ts b/Packages/editor/src/emojipicker.ts new file mode 100644 index 0000000..116d1dd --- /dev/null +++ b/Packages/editor/src/emojipicker.ts @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { Extension } from "@tiptap/core"; +import { PluginKey } from "@tiptap/pm/state"; +import Suggestion from "@tiptap/suggestion"; +import { emojiByGroup, recentEmoji, rememberEmoji, searchEmoji, type Emoji } from "./emoji"; +import type { EditorLabels } from "./labels"; +import { floatingList } from "./suggestion"; + +/** What ":" offers before anything is typed: recent picks, then the first smileys and hands. */ +function startingEmoji(): Emoji[] { + const recent = recentEmoji().map((char) => ({ char, words: "" })); + const seen = new Set(recent.map((e) => e.char)); + const more = [...emojiByGroup.smileys.slice(0, 8), ...emojiByGroup.people.slice(12, 16)].filter( + (e) => !seen.has(e.char), + ); + return [...recent, ...more].slice(0, 10); +} + +/** The emoji ":" + query finds, at most ten. */ +export function emojiMatches(query: string): Emoji[] { + return query.trim() ? searchEmoji(query).slice(0, 10) : startingEmoji(); +} + +/** + * Typing ":" after a space (or at the start of a line) and a word opens a + * list of emoji; picking one puts it in place of ":word". + */ +export const EmojiPicker = Extension.create<{ labels: EditorLabels | null }>({ + name: "emojiPicker", + + addOptions() { + return { labels: null }; + }, + + addProseMirrorPlugins() { + const labels = this.options.labels; + return [ + Suggestion({ + editor: this.editor, + pluginKey: new PluginKey("emojiPicker"), + char: ":", + allowSpaces: false, + allow: ({ state, range }) => !state.doc.resolve(range.from).parent.type.spec.code, + items: ({ query }) => emojiMatches(query), + render: floatingList({ + label: labels?.blocks.emoji ?? "Emoji", + empty: labels?.blocks.noEmoji ?? "No emoji found", + toItem: (e) => ({ label: e.words || e.char, glyph: e.char }), + pick: (p, e) => { + rememberEmoji(e.char); + p.editor.chain().focus().insertContentAt(p.range, e.char).run(); + }, + }), + }), + ]; + }, +}); diff --git a/Packages/editor/src/extensions.ts b/Packages/editor/src/extensions.ts index 593736b..ae12513 100644 --- a/Packages/editor/src/extensions.ts +++ b/Packages/editor/src/extensions.ts @@ -15,17 +15,24 @@ import { DocwellCodeBlock } from "./codeblock"; import { DocwellHighlight, TextColor } from "./colors"; import { CommentHighlights } from "./comments"; import { DateMention } from "./dates"; -import { SyncedPage, type SyncedPageHost } from "./syncedpage"; +import { SyncedBlockFilter, SyncedPage, type SyncedPageHost } from "./syncedpage"; import type * as Y from "yjs"; import { DrawioBlock, ExcalidrawBlock, type ExcalidrawLoader } from "./diagrams"; import { Embed, LinkCard, type LinkHost } from "./embeds"; import { DocwellImage, FileAttachment, FileDrop, type FileHost } from "./files"; +import { EmojiPicker } from "./emojipicker"; +import { Footnote } from "./footnotes"; +import { Audio, Video } from "./media"; +import { PageBreak } from "./pagebreak"; +import { Status } from "./status"; +import { Subpages } from "./subpages"; +import { Tab, Tabs } from "./tabs"; import { FindReplace } from "./find"; import { englishLabels, type EditorLabels } from "./labels"; import { docwellMath } from "./math"; import { docwellMention, type MentionHost } from "./mention"; import { MermaidBlock, type MermaidLoader } from "./mermaid"; -import { PageLinks, type PageHost } from "./pagelinks"; +import { PageLinks, type PageHost, type PageRef } from "./pagelinks"; import type { PdfLoader } from "./pdf"; import { SlashMenu, slashCommands } from "./slash"; import { Suggestions } from "./suggest"; @@ -49,6 +56,11 @@ export interface ExtensionOptions { mentions?: MentionHost; /** Finds pages for "[[" links. */ pages?: PageHost; + /** + * Lists the page's subpages for the subpages block, where the host has no + * PageHost (the mobile bridge); otherwise PageHost.children does. + */ + children?: () => Promise; /** Fetches previews for link cards; without it cards show the address only. */ links?: LinkHost; /** @@ -69,6 +81,8 @@ export interface ExtensionOptions { * without carets, undo or synced pages of its own. */ syncedDoc?: Y.Doc; + /** With syncedDoc: shows only the block with this id (a synced block). */ + syncedBlock?: string; /** Edits a database row's body (database/peek.ts): bound to this fragment of doc, without carets. */ rowBody?: { doc: Y.Doc; fragment: Y.XmlFragment }; /** The Draw.io embed address (default https://embed.diagrams.net). */ @@ -126,6 +140,15 @@ export function docwellExtensions(opts: ExtensionOptions = {}): AnyExtension[] { Placeholder.configure({ placeholder: opts.placeholder ?? "Type '/' for commands…" }), DocwellImage.configure({ host: opts.files }), FileAttachment.configure({ host: opts.files, loadPdf: opts.loadPdf, labels }), + Video.configure({ host: opts.files }), + Audio.configure({ host: opts.files }), + PageBreak.configure({ labels }), + Status.configure({ labels }), + Footnote.configure({ labels }), + Tabs.configure({ labels }), + Tab, + Subpages.configure({ children: subpagesOf(opts), labels, onNavigate: opts.onNavigate }), + EmojiPicker.configure({ labels }), DocwellCodeBlock.configure({ lineNumbers: opts.codeLineNumbers ?? false }), HeadingShortcuts, docwellAlign, @@ -141,7 +164,15 @@ export function docwellExtensions(opts: ExtensionOptions = {}): AnyExtension[] { docwellMention(labels, opts.mentions), DateMention.configure({ labels, me: () => opts.mentions?.me, onOpen: opts.onOpenDate }), SlashMenu.configure({ - commands: slashCommands(labels, opts.files, opts.onError, opts.pages, !!opts.loadExcalidraw, opts.links), + commands: slashCommands( + labels, + opts.files, + opts.onError, + opts.pages, + !!opts.loadExcalidraw, + opts.links, + !!subpagesOf(opts), + ), labels, }), CommentHighlights.configure({ onSelect: opts.onCommentSelect }), @@ -158,9 +189,10 @@ export function docwellExtensions(opts: ExtensionOptions = {}): AnyExtension[] { labels, onNavigate: opts.onNavigate, // One level deep: a synced page's own synced pages show as links. - nested: (doc) => + nested: (doc, block) => docwellExtensions({ syncedDoc: doc, + syncedBlock: block, files: opts.files, links: opts.links, onNavigate: opts.onNavigate, @@ -220,6 +252,7 @@ export function docwellExtensions(opts: ExtensionOptions = {}): AnyExtension[] { ]; // Database edits (DB_ORIGIN) are undone with the text they were made with. const yUndoOptions = { trackedOrigins: [DB_ORIGIN] }; + if (opts.syncedDoc && opts.syncedBlock) list.push(SyncedBlockFilter.configure({ block: opts.syncedBlock })); if (opts.rowBody) { list.push(Collaboration.configure({ document: opts.rowBody.doc, fragment: opts.rowBody.fragment, yUndoOptions })); } else if (opts.rowFragmentReadOnly) { @@ -235,6 +268,13 @@ export function docwellExtensions(opts: ExtensionOptions = {}): AnyExtension[] { return list; } +/** Where the subpages block reads the page's subpages, if anywhere. */ +function subpagesOf(opts: ExtensionOptions): (() => Promise) | undefined { + if (opts.children) return opts.children; + const pages = opts.pages; + return pages?.children ? () => pages.children!() : undefined; +} + /** * Another editor's caret with their name. The name is hidden from assistive * tech, which would otherwise read it as part of the text. diff --git a/Packages/editor/src/footnotes.ts b/Packages/editor/src/footnotes.ts new file mode 100644 index 0000000..9263716 --- /dev/null +++ b/Packages/editor/src/footnotes.ts @@ -0,0 +1,396 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { Editor, Extension, mergeAttributes, Node, type JSONContent } from "@tiptap/core"; +import type { Node as PMNode } from "@tiptap/pm/model"; +import { NodeSelection, Plugin, PluginKey } from "@tiptap/pm/state"; +import { Decoration, DecorationSet, type EditorView } from "@tiptap/pm/view"; +import StarterKit from "@tiptap/starter-kit"; +import { h, popover } from "./database/dom"; +import type { EditorLabels } from "./labels"; +import { svgIcon } from "./suggestion"; + +declare module "@tiptap/core" { + interface Commands { + footnote: { + /** Inserts a footnote mark at the selection and opens it for its text. */ + insertFootnote: (text?: string) => ReturnType; + }; + } +} + +/** The most text a footnote holds. */ +const MAX_NOTE = 2000; + +/** A footnote's plain text: at most 2000 characters. */ +export function cleanFootnote(s: unknown): string { + return typeof s === "string" ? s.trim().slice(0, MAX_NOTE) : ""; +} + +/** The marks a footnote's text can carry. */ +const noteMarks = new Set(["bold", "italic", "strike", "code", "underline", "link"]); + +/** Link addresses a note may hold: the web, mail, and the app's own paths. */ +const SAFE_HREF = /^(https?:\/\/|mailto:|\/(?!\/)|#)/i; + +/** + * A footnote's formatted text: text runs (with bold, italic, strikethrough, + * code, underline and links) and line breaks. Anything else is dropped, and + * the text is cut at 2000 characters. Null when nothing is left. + */ +export function cleanNoteContent(v: unknown): JSONContent[] | null { + if (!Array.isArray(v)) return null; + const out: JSONContent[] = []; + let room = MAX_NOTE; + for (const raw of v) { + if (room <= 0 || !raw || typeof raw !== "object") continue; + const n = raw as JSONContent; + if (n.type === "hardBreak") { + out.push({ type: "hardBreak" }); + continue; + } + if (n.type !== "text" || typeof n.text !== "string" || !n.text) continue; + const text = n.text.slice(0, room); + room -= text.length; + const marks = (n.marks ?? []).flatMap((m) => { + if (!m || !noteMarks.has(m.type)) return []; + if (m.type !== "link") return [{ type: m.type }]; + const href = typeof m.attrs?.href === "string" ? m.attrs.href.trim() : ""; + return SAFE_HREF.test(href) ? [{ type: "link", attrs: { href } }] : []; + }); + out.push(marks.length ? { type: "text", text, marks } : { type: "text", text }); + } + while (out.at(-1)?.type === "hardBreak") out.pop(); + return out.length ? out : null; +} + +/** The plain text of a footnote's formatted text. */ +export function noteText(content: JSONContent[] | null): string { + return cleanFootnote((content ?? []).map((n) => (n.type === "hardBreak" ? "\n" : (n.text ?? ""))).join("")); +} + +const markTags: Record = { + bold: "strong", + italic: "em", + strike: "s", + code: "code", + underline: "u", +}; + +/** A footnote's text as DOM: its formatted text, or its plain text for notes without. */ +export function noteDOM(content: JSONContent[] | null, text: string): DocumentFragment { + const frag = document.createDocumentFragment(); + if (!content) { + frag.append(text); + return frag; + } + for (const n of content) { + if (n.type === "hardBreak") { + frag.append(document.createElement("br")); + continue; + } + let el: globalThis.Node = document.createTextNode(n.text ?? ""); + for (const m of n.marks ?? []) { + let wrap: HTMLElement; + if (m.type === "link") { + const a = document.createElement("a"); + a.href = String(m.attrs?.href ?? ""); + a.rel = "noopener noreferrer"; + a.target = "_blank"; + wrap = a; + } else { + const tag = markTags[m.type]; + if (!tag) continue; + wrap = document.createElement(tag); + } + wrap.append(el); + el = wrap; + } + frag.append(el); + } + return frag; +} + +/** A footnote node's formatted text: its content, or its plain text as one run. */ +function contentOf(node: PMNode): JSONContent[] | null { + return cleanNoteContent(node.attrs.content); +} + +/** The footnotes of a document in reading order, with their positions. */ +export function footnotesOf(doc: PMNode): { pos: number; text: string; content: JSONContent[] | null }[] { + const out: { pos: number; text: string; content: JSONContent[] | null }[] = []; + doc.descendants((node, pos) => { + if (node.type.name === "footnote") + out.push({ pos, text: cleanFootnote(node.attrs.text), content: contentOf(node) }); + return true; + }); + return out; +} + +const key = new PluginKey("footnotes"); + +/** The schema of a footnote's text: one paragraph of formatted text. */ +const NoteDoc = Node.create({ name: "doc", topNode: true, content: "paragraph" }); + +/** Opens the panel that shows a footnote and, while editing, changes it. */ +function editFootnote(view: EditorView, pos: number, anchor: Element, labels: EditorLabels | null) { + const node = view.state.doc.nodeAt(pos); + if (!node || node.type.name !== "footnote") return; + const label = labels?.blocks.footnoteText ?? "Footnote text"; + let mini: Editor | null = null; + popover( + anchor, + (box, close) => { + const initial = + contentOf(node) ?? (node.attrs.text ? [{ type: "text", text: cleanFootnote(node.attrs.text) }] : []); + if (!view.editable) { + box.append( + h("div", { class: "dw-footnote-pop__read" }, noteDOM(contentOf(node), cleanFootnote(node.attrs.text))), + ); + return; + } + const save = (e: Editor) => { + const at = view.state.doc.nodeAt(pos); + if (!at || at.type.name !== "footnote") return; + const content = cleanNoteContent(e.getJSON().content?.[0]?.content ?? []); + const text = noteText(content); + if (text === at.attrs.text && JSON.stringify(content) === JSON.stringify(at.attrs.content ?? null)) return; + view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, { ...at.attrs, text, content })); + }; + const finish = () => { + close(); + view.focus(); + }; + const field = h("div", { class: "dw-footnote-pop__text" }); + const link = (e: Editor) => { + const now = String(e.getAttributes("link").href ?? ""); + const href = window.prompt(labels?.format.linkPrompt ?? "Link address", now); + if (href === null) return; + if (!href.trim()) e.chain().focus().extendMarkRange("link").unsetLink().run(); + else if (SAFE_HREF.test(href.trim())) + e.chain().focus().extendMarkRange("link").setLink({ href: href.trim() }).run(); + }; + mini = new Editor({ + element: field, + extensions: [ + NoteDoc, + StarterKit.configure({ + document: false, + heading: false, + blockquote: false, + bulletList: false, + orderedList: false, + listItem: false, + listKeymap: false, + codeBlock: false, + horizontalRule: false, + dropcursor: false, + gapcursor: false, + trailingNode: false, + link: { openOnClick: false, autolink: true }, + }), + Extension.create({ + name: "footnoteKeys", + addKeyboardShortcuts: () => ({ + // Enter closes the note; Shift+Enter breaks the line. + Enter: () => { + finish(); + return true; + }, + "Mod-k": ({ editor }) => { + link(editor); + return true; + }, + }), + }), + ], + content: { type: "doc", content: [{ type: "paragraph", content: initial }] }, + editorProps: { attributes: { class: "dw-footnote-pop__field", "aria-label": label, role: "textbox" } }, + onUpdate: ({ editor }) => save(editor), + }); + const tool = (icon: "bold" | "italic" | "code" | "link", title: string, run: (e: Editor) => void) => { + const b = h("button", { type: "button", class: "dw-footnote-pop__tool", title, "aria-label": title }); + b.append(svgIcon(icon, 15)); + b.addEventListener("mousedown", (e) => e.preventDefault()); + b.addEventListener("click", () => mini && run(mini)); + return b; + }; + const f = labels?.format; + const tools = h( + "div", + { class: "dw-footnote-pop__tools", role: "toolbar" }, + tool("bold", f?.bold ?? "Bold", (e) => e.chain().focus().toggleBold().run()), + tool("italic", f?.italic ?? "Italic", (e) => e.chain().focus().toggleItalic().run()), + tool("code", f?.code ?? "Inline code", (e) => e.chain().focus().toggleCode().run()), + tool("link", f?.link ?? "Link", link), + ); + box.append(tools, field); + // Focus now, with the caret at the end: the panel is already in the page. + mini.commands.setTextSelection(mini.state.doc.content.size - 1); + mini.view.focus(); + }, + { + class: "dw-footnote-pop", + label, + onClose: () => { + mini?.destroy(); + mini = null; + }, + }, + ); +} + +/** + * A footnote: a small number in the text that holds its note. Footnotes are + * numbered in reading order, and their notes are listed at the end of the + * page, each linking back to its number. Clicking a number opens its note. + * The note's formatted text is in content; text keeps it as plain text for + * search and for readers that only know plain notes. + */ +export const Footnote = Node.create<{ labels: EditorLabels | null }>({ + name: "footnote", + group: "inline", + inline: true, + atom: true, + selectable: true, + + addOptions() { + return { labels: null }; + }, + + addAttributes() { + return { + text: { + default: "", + parseHTML: (el) => cleanFootnote(el.getAttribute("data-text") ?? el.getAttribute("title") ?? ""), + renderHTML: (a) => ({ "data-text": a.text, title: a.text }), + }, + content: { + default: null, + parseHTML: (el) => { + try { + return cleanNoteContent(JSON.parse(el.getAttribute("data-content") ?? "null")); + } catch { + return null; + } + }, + renderHTML: (a) => { + const c = cleanNoteContent(a.content); + return c ? { "data-content": JSON.stringify(c) } : {}; + }, + }, + }; + }, + + parseHTML() { + return [{ tag: "sup[data-type=footnote]" }]; + }, + + renderHTML({ HTMLAttributes }) { + return ["sup", mergeAttributes(HTMLAttributes, { "data-type": "footnote", class: "dw-footnote" })]; + }, + + renderText({ node }) { + return ` (${cleanFootnote(node.attrs.text)})`; + }, + + addCommands() { + return { + insertFootnote: + (text = "") => + ({ editor, tr, dispatch }) => { + const type = editor.schema.nodes.footnote!; + if (!dispatch) return true; + const from = tr.selection.from; + tr.replaceSelectionWith(type.create({ text: cleanFootnote(text) }), false); + // The new footnote opens for its text once it is drawn. + const labels = this.options.labels; + setTimeout(() => { + if (editor.isDestroyed) return; + const el = editor.view.nodeDOM(from); + if (el instanceof Element) editFootnote(editor.view, from, el, labels); + }); + return true; + }, + }; + }, + + addProseMirrorPlugins() { + const labels = this.options.labels; + const decorate = (doc: PMNode) => { + const notes = footnotesOf(doc); + if (!notes.length) return DecorationSet.empty; + const marks = notes.map((n, i) => + Decoration.node(n.pos, n.pos + 1, { + "data-n": String(i + 1), + id: `fnref-${i + 1}`, + "aria-label": (labels?.blocks.footnote ?? "Footnote {n}").replace("{n}", String(i + 1)), + }), + ); + // The list at the end; its key changes with the notes so it is drawn again. + const sig = JSON.stringify(notes.map((n) => n.content ?? n.text)); + const list = Decoration.widget( + doc.content.size, + (view) => { + const ol = h("ol", {}); + notes.forEach((n, i) => { + const back = h( + "a", + { + href: `#fnref-${i + 1}`, + class: "dw-footnotes__back", + title: labels?.blocks.footnoteBack ?? "Back to the text", + "aria-label": labels?.blocks.footnoteBack ?? "Back to the text", + }, + "↩", + ); + back.addEventListener("click", (e) => { + e.preventDefault(); + const target = view.dom.querySelector(`[id="fnref-${i + 1}"]`); + target?.scrollIntoView({ block: "center" }); + }); + const text = h("span", { class: "dw-footnotes__text" }); + text.append(n.text || n.content ? noteDOM(n.content, n.text) : "…"); + if (view.editable) { + text.addEventListener("click", (e) => { + // Links in the note open; a click elsewhere edits it. + if ((e.target as Element | null)?.closest?.("a")) return; + const at = footnotesOf(view.state.doc)[i]; + const ref = view.dom.querySelector(`[id="fnref-${i + 1}"]`); + if (at && ref) editFootnote(view, at.pos, ref, labels); + }); + } + ol.append(h("li", { id: `fn-${i + 1}` }, text, " ", back)); + }); + return h( + "section", + { class: "dw-footnotes", contenteditable: "false", "aria-label": labels?.blocks.footnotes ?? "Footnotes" }, + ol, + ); + }, + { side: 1, key: `footnotes:${sig}`, ignoreSelection: true, stopEvent: () => true }, + ); + return DecorationSet.create(doc, [...marks, list]); + }; + return [ + new Plugin({ + key, + state: { + init: (_c, state) => decorate(state.doc), + apply: (tr, old) => (tr.docChanged ? decorate(tr.doc) : old), + }, + props: { + decorations: (state) => key.getState(state), + handleClickOn: (view, _pos, node, nodePos, event) => { + if (node.type.name !== "footnote") return false; + const el = view.nodeDOM(nodePos); + if (!(el instanceof Element)) return false; + event.preventDefault(); + view.dispatch(view.state.tr.setSelection(NodeSelection.create(view.state.doc, nodePos))); + editFootnote(view, nodePos, el, labels); + return true; + }, + }, + }), + ]; + }, +}); diff --git a/Packages/editor/src/labels.ts b/Packages/editor/src/labels.ts index 78b0ea3..7195cbe 100644 --- a/Packages/editor/src/labels.ts +++ b/Packages/editor/src/labels.ts @@ -129,6 +129,35 @@ export interface EditorLabels { syncedLoading: string; syncedDenied: string; syncedSelf: string; + /** Synced blocks: a syncedPage that shows one block of another page. */ + syncedBlock: string; + syncedBlockUrl: string; + syncedBlockInvalid: string; + syncedBlockMissing: string; + /** The dashed line where printing starts a new page. */ + pageBreak: string; + /** An inline status badge and the panel that changes it. */ + status: string; + statusDefault: string; + statusText: string; + statusColor: string; + /** Footnotes: the list at the end of the page and the panel that edits one. */ + footnotes: string; + footnote: string; + footnoteText: string; + footnoteBack: string; + /** The tabs block. {n} in tabName is the tab's number. */ + tabName: string; + addTab: string; + renameTab: string; + deleteTab: string; + /** The list of the page's subpages. */ + subpages: string; + subpagesEmpty: string; + subpagesLoading: string; + /** ":" emoji. */ + emoji: string; + noEmoji: string; }; /** Suggesting mode (suggest.ts): the bar above the page and the card on a suggestion. count has {n} in it. */ suggest: { @@ -218,6 +247,7 @@ export const englishLabels: EditorLabels = { columns2: { label: "2 columns", description: "Two blocks side by side" }, columns3: { label: "3 columns", description: "Three blocks side by side" }, columns4: { label: "4 columns", description: "Four blocks side by side" }, + columns5: { label: "5 columns", description: "Five blocks side by side" }, table: { label: "Table", description: "Rows and columns" }, quote: { label: "Quote", description: "Set text apart as a quote" }, code: { label: "Code block", description: "Monospaced code" }, @@ -241,6 +271,15 @@ export const englishLabels: EditorLabels = { tomorrow: { label: "Tomorrow", description: "Insert tomorrow's date" }, yesterday: { label: "Yesterday", description: "Insert yesterday's date" }, now: { label: "Now", description: "Insert the date and time" }, + video: { label: "Video", description: "Upload a video that plays on the page" }, + audio: { label: "Audio", description: "Upload a recording that plays on the page" }, + pageBreak: { label: "Page break", description: "Start a new page when printing" }, + footnote: { label: "Footnote", description: "A numbered note at the end of the page" }, + tabs: { label: "Tabs", description: "Content on several tabs" }, + status: { label: "Status", description: "A coloured badge in the text" }, + emoji: { label: "Emoji", description: "Pick an emoji (or type :)" }, + subpages: { label: "Subpages", description: "List this page's subpages" }, + syncedBlock: { label: "Synced block", description: "Show a block of another page, always up to date" }, }, format: { bold: "Bold", @@ -348,6 +387,28 @@ export const englishLabels: EditorLabels = { transcribeHint: "Add a summary and the transcript below, with AI", transcribing: "Transcribing…", transcribeFailed: "The recording could not be transcribed.", + syncedBlock: "Synced block", + syncedBlockUrl: "Link to the block (copy it from the block's ⋮⋮ menu)", + syncedBlockInvalid: "That isn't a link to a block of a page.", + syncedBlockMissing: "This block is no longer on its page.", + pageBreak: "Page break", + status: "Status", + statusDefault: "To do", + statusText: "Status text", + statusColor: "Status colour", + footnotes: "Footnotes", + footnote: "Footnote {n}", + footnoteText: "Footnote text", + footnoteBack: "Back to the text", + tabName: "Tab {n}", + addTab: "Add a tab", + renameTab: "Tab name", + deleteTab: "Delete tab", + subpages: "Subpages", + subpagesEmpty: "This page has no subpages yet.", + subpagesLoading: "Loading subpages…", + emoji: "Emoji", + noEmoji: "No emoji found", }, suggest: { mode: "Suggesting", diff --git a/Packages/editor/src/media.ts b/Packages/editor/src/media.ts new file mode 100644 index 0000000..431f42d --- /dev/null +++ b/Packages/editor/src/media.ts @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { mergeAttributes, Node } from "@tiptap/core"; +import type { FileHost } from "./files"; + +type Kind = "video" | "audio"; + +/** Whether an uploaded file plays as video or audio, or neither. */ +export function mediaKind(mime: string, name: string): Kind | null { + if (mime.startsWith("video/") || /\.(mp4|webm|mov|m4v|ogv)$/i.test(name)) return "video"; + if (mime.startsWith("audio/") || /\.(mp3|m4a|wav|ogg|oga|flac|aac|opus)$/i.test(name)) return "audio"; + return null; +} + +/** + * A video or a recording that plays on the page. Like images, the node + * stores the file's API path and draws it through FileHost.resolve. + */ +function mediaNode(kind: Kind) { + return Node.create<{ host?: FileHost }>({ + name: kind, + group: "block", + atom: true, + draggable: true, + + addOptions() { + return { host: undefined }; + }, + + addAttributes() { + return { + src: { default: "" }, + name: { default: "" }, + mime: { default: "" }, + }; + }, + + parseHTML() { + return [ + { + tag: `${kind}[src]`, + getAttrs: (el) => ({ + src: el.getAttribute("src") ?? "", + name: el.getAttribute("data-name") ?? el.getAttribute("title") ?? "", + mime: el.getAttribute("data-mime") ?? "", + }), + }, + ]; + }, + + renderHTML({ node, HTMLAttributes }) { + return [ + kind, + mergeAttributes(HTMLAttributes, { + src: node.attrs.src, + controls: "", + preload: "metadata", + "data-name": node.attrs.name || null, + "data-mime": node.attrs.mime || null, + title: node.attrs.name || null, + }), + ]; + }, + + addNodeView() { + return ({ node }) => { + const host = this.options.host; + const dom = document.createElement("div"); + dom.className = `dw-media dw-media--${kind}`; + dom.setAttribute("data-type", kind); + const player = document.createElement(kind); + player.controls = true; + player.preload = "metadata"; + dom.append(player); + let shown = ""; + const draw = (n: typeof node) => { + const src = String(n.attrs.src ?? ""); + const url = host ? host.resolve(src) : src; + if (url !== shown) { + player.src = url; + shown = url; + } + const name = String(n.attrs.name ?? ""); + player.title = name; + player.setAttribute("aria-label", name || kind); + }; + draw(node); + return { + dom, + update: (n) => { + if (n.type !== node.type) return false; + draw(n); + return true; + }, + // Playing, seeking and the volume are not edits. + stopEvent: (e) => e.target === player && e.type !== "dragstart", + ignoreMutation: () => true, + }; + }; + }, + }); +} + +export const Video = mediaNode("video"); +export const Audio = mediaNode("audio"); diff --git a/Packages/editor/src/pagebreak.ts b/Packages/editor/src/pagebreak.ts new file mode 100644 index 0000000..501e266 --- /dev/null +++ b/Packages/editor/src/pagebreak.ts @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { mergeAttributes, Node } from "@tiptap/core"; +import type { EditorLabels } from "./labels"; + +declare module "@tiptap/core" { + interface Commands { + pageBreak: { + /** Puts a page break where the selection is. */ + setPageBreak: () => ReturnType; + }; + } +} + +/** + * Where printing starts a new page. On screen it is a dashed line with a + * label; in print it takes no room and only breaks the page. + */ +export const PageBreak = Node.create<{ labels: EditorLabels | null }>({ + name: "pageBreak", + group: "block", + atom: true, + selectable: true, + draggable: true, + + addOptions() { + return { labels: null }; + }, + + parseHTML() { + return [{ tag: "div[data-type=pageBreak]" }]; + }, + + renderHTML({ HTMLAttributes }) { + return [ + "div", + mergeAttributes(HTMLAttributes, { + "data-type": "pageBreak", + class: "dw-page-break", + style: "break-after: page", + "data-label": this.options.labels?.blocks.pageBreak ?? "Page break", + }), + ]; + }, + + addCommands() { + return { + setPageBreak: + () => + ({ commands }) => + commands.insertContent([{ type: this.name }, { type: "paragraph" }]), + }; + }, +}); diff --git a/Packages/editor/src/pagelinks.ts b/Packages/editor/src/pagelinks.ts index e5fb45b..1101632 100644 --- a/Packages/editor/src/pagelinks.ts +++ b/Packages/editor/src/pagelinks.ts @@ -23,6 +23,8 @@ export interface PageHost { * where the host allows). Without it the editor cannot make linked pages. */ create?(title: string): Promise; + /** The subpages of the page being edited, in the sidebar's order (for the subpages block). */ + children?(): Promise; } /** The app path of a page; page links are ordinary links to it. */ diff --git a/Packages/editor/src/slash.ts b/Packages/editor/src/slash.ts index d7a0d98..a46d45c 100644 --- a/Packages/editor/src/slash.ts +++ b/Packages/editor/src/slash.ts @@ -7,7 +7,9 @@ import type { IconName } from "@docwell/ui/icons"; import { insertDate, isoDate } from "./dates"; import { promptEmbed, promptLinkCard, type LinkHost } from "./embeds"; import { insertFiles, type FileHost } from "./files"; +import { mediaKind } from "./media"; import { createLinkedPage, type PageHost } from "./pagelinks"; +import { parseBlockLink } from "./syncedpage"; import type { EditorLabels } from "./labels"; import { floatingList } from "./suggestion"; @@ -44,6 +46,7 @@ export function slashCommands( pages?: PageHost, excalidraw = false, links?: LinkHost, + subpages = !!pages?.children, ): SlashCommand[] { const block = ( id: string, @@ -89,7 +92,7 @@ export function slashCommands( ), { ...block("columns", "columns", ["layout", "side by side", "split", "grid", "multi-column"], () => {}), - children: ([2, 3, 4] as const).map((n) => + children: ([2, 3, 4, 5] as const).map((n) => block(`columns${n}`, "columns", ["columns", "layout", "side by side", String(n)], (e, r) => e.chain().focus().deleteRange(r).insertColumns(n).run(), ), @@ -105,12 +108,27 @@ export function slashCommands( block("code", "code", ["codeblock", "```", "snippet"], (e, r) => e.chain().focus().deleteRange(r).toggleCodeBlock().run(), ), + block("tabs", "tabs", ["tab", "tabbed", "switch", "panes"], (e, r) => + e.chain().focus().deleteRange(r).insertTabs().run(), + ), block("toggle", "chevron-right", ["details", "collapse", "expand", "fold", ">"], (e, r) => e.chain().focus().deleteRange(r).setDetails().run(), ), block("divider", "divider", ["hr", "rule", "line", "---"], (e, r) => e.chain().focus().deleteRange(r).setHorizontalRule().run(), ), + block("pageBreak", "page-break", ["print", "new page", "break", "pdf"], (e, r) => + e.chain().focus().deleteRange(r).setPageBreak().run(), + ), + block("footnote", "footnote", ["note", "reference", "citation", "source", "fn"], (e, r) => + e.chain().focus().deleteRange(r).insertFootnote().run(), + ), + block("status", "status", ["badge", "label", "state", "progress", "tag"], (e, r) => + e.chain().focus().deleteRange(r).insertStatus().run(), + ), + block("emoji", "smile", ["emoticon", "smiley", ":"], (e, r) => + e.chain().focus().deleteRange(r).insertContent(":").run(), + ), block("toc", "list", ["contents", "outline", "headings", "index"], (e, r) => e.chain().focus().deleteRange(r).insertTableOfContents().run(), ), @@ -157,6 +175,19 @@ export function slashCommands( e.chain().focus().deleteRange(r).insertContent("![[").run(), ), ); + list.push( + block("syncedBlock", "copy", ["sync", "transclude", "mirror", "reuse", "block"], (e, r) => { + e.chain().focus().deleteRange(r).run(); + const text = window.prompt(l.blocks.syncedBlockUrl, ""); + if (text === null || !text.trim()) return; + const at = parseBlockLink(text); + if (!at) { + onError?.(new Error(l.blocks.syncedBlockInvalid)); + return; + } + e.chain().focus().insertSyncedPage({ id: at.page, title: "", block: at.block }).run(); + }), + ); if (pages.create) { list.push( block("newPage", "page-plus", ["page", "doc", "subpage", "create"], (e, r) => { @@ -166,13 +197,36 @@ export function slashCommands( ); } } + if (subpages) { + list.push( + block("subpages", "layers", ["children", "child pages", "sub pages", "index", "contents"], (e, r) => + e.chain().focus().deleteRange(r).insertSubpages().run(), + ), + ); + } if (files?.upload) { const upload = (accept: string) => (e: Editor, r: Range) => { e.chain().focus().deleteRange(r).run(); void pickFiles(accept).then((picked) => insertFiles(e, files, picked).catch(onError)); }; + // Video and audio play on the page; files that are neither are attached as files. + const uploadMedia = (accept: string) => (e: Editor, r: Range) => { + e.chain().focus().deleteRange(r).run(); + void pickFiles(accept).then(async (picked) => { + for (const file of picked) { + const up = await files.upload!(file); + const kind = mediaKind(up.mime, up.name); + const node = kind + ? { type: kind, attrs: { src: up.url, name: up.name, mime: up.mime } } + : { type: "fileAttachment", attrs: { url: up.url, name: up.name, size: up.size, mime: up.mime } }; + e.chain().focus().insertContentAt(e.state.selection.to, node).run(); + } + }).catch(onError); + }; list.push( block("image", "image", ["picture", "photo", "img"], upload("image/*")), + block("video", "video", ["movie", "clip", "mp4", "player"], uploadMedia("video/*")), + block("audio", "music", ["sound", "recording", "podcast", "mp3", "voice"], uploadMedia("audio/*")), block("file", "paperclip", ["attachment", "upload", "pdf"], upload("")), block("drawio", "diagram", ["diagram", "diagrams.net", "draw", "chart", "uml"], (e, r) => e.chain().focus().deleteRange(r).insertDiagram("drawio").run(), diff --git a/Packages/editor/src/status.ts b/Packages/editor/src/status.ts new file mode 100644 index 0000000..e78f228 --- /dev/null +++ b/Packages/editor/src/status.ts @@ -0,0 +1,173 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { mergeAttributes, Node } from "@tiptap/core"; +import { isPaletteColor, palette, type PaletteColor } from "./colors"; +import { h, popover } from "./database/dom"; +import type { EditorLabels } from "./labels"; + +declare module "@tiptap/core" { + interface Commands { + status: { + /** Inserts a status badge at the selection. */ + insertStatus: (attrs?: { text?: string; color?: PaletteColor }) => ReturnType; + }; + } +} + +/** Badge text: one line, at most 40 characters. */ +export function cleanStatus(s: unknown): string { + return typeof s === "string" ? s.replace(/\s+/g, " ").trim().slice(0, 40) : ""; +} + +/** + * A coloured badge in the text ("In review"). Clicking it while editing + * opens a panel to change its words and colour. + */ +export const Status = Node.create<{ labels: EditorLabels | null }>({ + name: "status", + group: "inline", + inline: true, + atom: true, + selectable: true, + + addOptions() { + return { labels: null }; + }, + + addAttributes() { + return { + text: { + default: "", + parseHTML: (el) => cleanStatus(el.textContent), + renderHTML: () => ({}), + }, + color: { + default: "gray", + parseHTML: (el) => { + const c = el.getAttribute("data-color"); + return isPaletteColor(c) ? c : "gray"; + }, + renderHTML: (a) => ({ "data-color": a.color }), + }, + }; + }, + + parseHTML() { + // Before the colour marks, which also read span[data-color]. + return [{ tag: "span[data-type=status]", priority: 100 }]; + }, + + renderHTML({ node, HTMLAttributes }) { + return [ + "span", + mergeAttributes(HTMLAttributes, { "data-type": "status", class: "dw-status" }), + cleanStatus(node.attrs.text) || this.options.labels?.blocks.statusDefault || "Status", + ]; + }, + + renderText({ node }) { + return cleanStatus(node.attrs.text); + }, + + addCommands() { + return { + insertStatus: + (attrs) => + ({ commands }) => + commands.insertContent([ + { + type: this.name, + attrs: { + text: cleanStatus(attrs?.text) || this.options.labels?.blocks.statusDefault || "To do", + color: attrs?.color ?? "gray", + }, + }, + { type: "text", text: " " }, + ]), + }; + }, + + addNodeView() { + return ({ node, getPos, editor }) => { + const labels = this.options.labels; + let current = node; + const dom = document.createElement("span"); + dom.className = "dw-status"; + dom.setAttribute("data-type", "status"); + dom.contentEditable = "false"; + const draw = () => { + dom.setAttribute("data-color", String(current.attrs.color)); + dom.textContent = cleanStatus(current.attrs.text) || labels?.blocks.statusDefault || "Status"; + }; + draw(); + const set = (patch: Record) => { + const pos = getPos(); + if (typeof pos !== "number" || !editor.isEditable) return; + editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, ...patch })); + }; + const open = () => { + if (!editor.isEditable) return; + popover( + dom, + (box, close) => { + const input = h("input", { + class: "dw-db-input", + "aria-label": labels?.blocks.statusText ?? "Status text", + maxlength: "40", + }); + input.value = cleanStatus(current.attrs.text); + input.addEventListener("input", () => set({ text: cleanStatus(input.value) })); + input.addEventListener("keydown", (e) => { + if (e.key === "Enter") { + e.preventDefault(); + close(); + editor.commands.focus(); + } + }); + const swatches = h("div", { + class: "dw-status-pop__colors", + role: "radiogroup", + "aria-label": labels?.blocks.statusColor ?? "Status colour", + }); + for (const c of palette) { + const b = h("button", { + type: "button", + class: "dw-status-pop__swatch", + "data-color": c, + role: "radio", + "aria-checked": String(current.attrs.color === c), + "aria-label": labels?.colors[c] ?? c, + title: labels?.colors[c] ?? c, + }); + b.addEventListener("click", () => { + set({ color: c }); + swatches.querySelectorAll("button").forEach((x) => x.setAttribute("aria-checked", String(x === b))); + }); + swatches.append(b); + } + box.append(input, swatches); + // The panel is already in the page, so the field can take focus now. + input.focus(); + input.select(); + }, + { class: "dw-status-pop", label: labels?.blocks.status ?? "Status" }, + ); + }; + dom.addEventListener("mousedown", (e) => { + if (!editor.isEditable) return; + e.preventDefault(); + open(); + }); + return { + dom, + update: (n) => { + if (n.type !== node.type) return false; + current = n; + draw(); + return true; + }, + ignoreMutation: () => true, + }; + }; + }, +}); diff --git a/Packages/editor/src/subpages.ts b/Packages/editor/src/subpages.ts new file mode 100644 index 0000000..d377c67 --- /dev/null +++ b/Packages/editor/src/subpages.ts @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { mergeAttributes, Node } from "@tiptap/core"; +import type { EditorLabels } from "./labels"; +import { pagePath, type PageRef } from "./pagelinks"; +import { svgIcon } from "./suggestion"; + +declare module "@tiptap/core" { + interface Commands { + subpages: { + /** Puts a list of the page's subpages where the selection is. */ + insertSubpages: () => ReturnType; + }; + } +} + +export interface SubpagesOptions { + /** Lists the page's subpages (PageHost.children); without it the block shows its name only. */ + children?: () => Promise; + labels: EditorLabels | null; + onNavigate?: (path: string) => void; +} + +/** + * The page's subpages, listed as links and read afresh each time the page + * is opened. The document stores only the block, not the list, so exports + * and readers without a host leave it out. + */ +export const Subpages = Node.create({ + name: "subpages", + group: "block", + atom: true, + draggable: true, + + addOptions() { + return { children: undefined, labels: null, onNavigate: undefined }; + }, + + parseHTML() { + return [{ tag: "div[data-type=subpages]" }]; + }, + + renderHTML({ HTMLAttributes }) { + return ["div", mergeAttributes(HTMLAttributes, { "data-type": "subpages" })]; + }, + + addCommands() { + return { + insertSubpages: + () => + ({ commands }) => + commands.insertContent([{ type: this.name }, { type: "paragraph" }]), + }; + }, + + addNodeView() { + const { children, labels, onNavigate } = this.options; + return () => { + const dom = document.createElement("nav"); + dom.className = "dw-subpages"; + dom.setAttribute("data-type", "subpages"); + dom.contentEditable = "false"; + dom.setAttribute("aria-label", labels?.blocks.subpages ?? "Subpages"); + const note = (text: string) => { + const p = document.createElement("p"); + p.className = "dw-subpages__note"; + p.textContent = text; + dom.replaceChildren(p); + }; + const list = (items: PageRef[]) => { + if (!items.length) return note(labels?.blocks.subpagesEmpty ?? "This page has no subpages yet."); + const ul = document.createElement("ul"); + for (const p of items) { + const li = document.createElement("li"); + const a = document.createElement("a"); + a.className = "dw-subpages__link"; + a.href = pagePath(p.id); + if (p.icon) { + const icon = document.createElement("span"); + icon.className = "dw-subpages__icon"; + icon.textContent = p.icon; + a.append(icon); + } else a.append(svgIcon("page", 16)); + const title = document.createElement("span"); + title.textContent = p.title || "…"; + a.append(title); + a.addEventListener("click", (e) => { + if (!onNavigate || e.ctrlKey || e.metaKey || e.shiftKey) return; + e.preventDefault(); + onNavigate(pagePath(p.id)); + }); + li.append(a); + ul.append(li); + } + dom.replaceChildren(ul); + }; + if (!children) { + note(labels?.blocks.subpages ?? "Subpages"); + } else { + note(labels?.blocks.subpagesLoading ?? "Loading subpages…"); + children() + .then(list) + .catch(() => note(labels?.blocks.subpagesEmpty ?? "This page has no subpages yet.")); + } + return { + dom, + stopEvent: (e) => e.type === "click" && !!(e.target as Element | null)?.closest?.("a"), + ignoreMutation: () => true, + }; + }; + }, +}); diff --git a/Packages/editor/src/suggestion.ts b/Packages/editor/src/suggestion.ts index fe13214..71ffba9 100644 --- a/Packages/editor/src/suggestion.ts +++ b/Packages/editor/src/suggestion.ts @@ -9,6 +9,8 @@ export interface ListItem { label: string; description?: string; icon?: IconName; + /** A character drawn instead of the icon, e.g. an emoji. */ + glyph?: string; } const svgNS = "http://www.w3.org/2000/svg"; @@ -113,7 +115,10 @@ export function floatingList(opts: { }); const glyph = document.createElement("span"); glyph.className = "dw-suggest__icon"; - glyph.append(svgIcon(it.icon ?? "text")); + if (it.glyph) { + glyph.classList.add("dw-suggest__icon--glyph"); + glyph.textContent = it.glyph; + } else glyph.append(svgIcon(it.icon ?? "text")); const text = document.createElement("span"); text.className = "dw-suggest__text"; const label = document.createElement("span"); diff --git a/Packages/editor/src/syncedpage.ts b/Packages/editor/src/syncedpage.ts index 2948483..0d101c1 100644 --- a/Packages/editor/src/syncedpage.ts +++ b/Packages/editor/src/syncedpage.ts @@ -1,7 +1,9 @@ // SPDX-License-Identifier: AGPL-3.0-or-later -import { Editor, mergeAttributes, Node, type AnyExtension, type Range } from "@tiptap/core"; -import { PluginKey } from "@tiptap/pm/state"; +import { Editor, Extension, mergeAttributes, Node, type AnyExtension, type Range } from "@tiptap/core"; +import type { Node as PMNode } from "@tiptap/pm/model"; +import { Plugin, PluginKey } from "@tiptap/pm/state"; +import { Decoration, DecorationSet } from "@tiptap/pm/view"; import Suggestion from "@tiptap/suggestion"; import type * as Y from "yjs"; import type { EditorLabels } from "./labels"; @@ -28,18 +30,87 @@ export interface SyncedPageOptions { pages?: PageHost; labels: EditorLabels | null; onNavigate?: (path: string) => void; - /** The extensions of the read-only editor that draws a synced page's document. */ - nested?: (doc: Y.Doc) => AnyExtension[]; + /** The extensions of the read-only editor that draws a synced page's document (or one block of it). */ + nested?: (doc: Y.Doc, block?: string) => AnyExtension[]; } declare module "@tiptap/core" { interface Commands { syncedPage: { - insertSyncedPage: (page: PageRef) => ReturnType; + /** Inserts a synced page; with block, only that block of it (a synced block). */ + insertSyncedPage: (page: PageRef & { block?: string }) => ReturnType; }; } } +const BLOCK_ID = /^[a-z0-9]{6,16}$/; + +/** The app path a synced page links to: the page, or the block on it. */ +export const syncedPath = (page: string, block: string) => (block ? `${pagePath(page)}#b-${block}` : pagePath(page)); + +/** Whether doc has a block with id. */ +function hasBlock(doc: PMNode, id: string): boolean { + let found = false; + doc.descendants((n) => { + if (n.attrs.blockId === id) found = true; + return !found; + }); + return found; +} + +/** + * The page and block a link to a block points at ("…/p/#b-", + * as the block menu copies it), or null for any other text. + */ +export function parseBlockLink(text: string): { page: string; block: string } | null { + const m = /\/p\/([A-Za-z0-9_-]+)\/?(?:\?[^#\s]*)?#b-([a-z0-9]{6,16})$/.exec(text.trim()); + return m ? { page: m[1]!, block: m[2]! } : null; +} + +/** + * Hides every block of a synced page's document but the one with id (and, + * of the blocks that hold it, their other children), for a synced block. + */ +export const SyncedBlockFilter = Extension.create<{ block: string }>({ + name: "syncedBlockFilter", + addOptions() { + return { block: "" }; + }, + addProseMirrorPlugins() { + const id = this.options.block; + return [ + new Plugin({ + key: new PluginKey("syncedBlockFilter"), + props: { + decorations: (state) => { + let target = -1; + state.doc.descendants((n, pos) => { + if (n.attrs.blockId === id) target = pos; + return target < 0; + }); + const hide: Decoration[] = []; + const hidden = { class: "dw-synced-hidden" }; + if (target < 0) { + state.doc.forEach((n, off) => hide.push(Decoration.node(off, off + n.nodeSize, hidden))); + return DecorationSet.create(state.doc, hide); + } + const $t = state.doc.resolve(target); + for (let d = 0; d <= $t.depth; d++) { + const keep = $t.index(d); + let at = d === 0 ? 0 : $t.start(d); + $t.node(d).forEach((c, _o, i) => { + if (i !== keep) hide.push(Decoration.node(at, at + c.nodeSize, hidden)); + at += c.nodeSize; + }); + } + return DecorationSet.create(state.doc, hide); + }, + }, + }), + ]; + }, +}); + /** Replaces range with a synced page. */ export function insertSyncedPage(editor: Editor, range: Range, page: PageRef) { editor.chain().focus().deleteRange(range).insertSyncedPage(page).run(); @@ -77,6 +148,14 @@ export const SyncedPage = Node.create({ parseHTML: (el) => el.getAttribute("data-icon") ?? "", renderHTML: (a) => (a.icon ? { "data-icon": a.icon } : {}), }, + block: { + default: "", + parseHTML: (el) => { + const b = el.getAttribute("data-block") ?? ""; + return BLOCK_ID.test(b) ? b : ""; + }, + renderHTML: (a) => (a.block ? { "data-block": a.block } : {}), + }, folded: { default: false, parseHTML: (el) => el.hasAttribute("data-folded"), @@ -94,7 +173,7 @@ export const SyncedPage = Node.create({ return [ "div", mergeAttributes(HTMLAttributes, { "data-type": "syncedPage" }), - ["a", { href: pagePath(String(node.attrs.page)) }, title], + ["a", { href: syncedPath(String(node.attrs.page), String(node.attrs.block ?? "")) }, title], ]; }, @@ -104,7 +183,10 @@ export const SyncedPage = Node.create({ (page) => ({ commands }) => commands.insertContent([ - { type: this.name, attrs: { page: page.id, title: page.title, icon: page.icon ?? "" } }, + { + type: this.name, + attrs: { page: page.id, title: page.title, icon: page.icon ?? "", block: page.block ?? "" }, + }, { type: "paragraph" }, ]), }; @@ -142,16 +224,19 @@ export const SyncedPage = Node.create({ return ({ node: initial, editor, getPos }) => { let node = initial; const page = String(node.attrs.page); + const block = BLOCK_ID.test(String(node.attrs.block ?? "")) ? String(node.attrs.block) : ""; + const path = syncedPath(page, block); const dom = document.createElement("div"); dom.className = "dw-synced"; dom.dataset.type = "syncedPage"; + if (block) dom.classList.add("dw-synced--block"); dom.contentEditable = "false"; const head = document.createElement("div"); head.className = "dw-synced__head"; const title = document.createElement("a"); title.className = "dw-synced__title"; - title.href = pagePath(page); + title.href = path; const badge = svgIcon("copy", 14); badge.classList.add("dw-synced__badge"); const fold = document.createElement("button"); @@ -168,8 +253,8 @@ export const SyncedPage = Node.create({ const go = (e: Event) => { e.preventDefault(); - if (onNavigate) onNavigate(pagePath(page)); - else window.location.assign(pagePath(page)); + if (onNavigate) onNavigate(path); + else window.location.assign(path); }; title.addEventListener("click", go); open.addEventListener("click", go); @@ -220,12 +305,26 @@ export const SyncedPage = Node.create({ note(labels.syncedDenied); } else if (p.synced && !view) { body.replaceChildren(); - view = new Editor({ + const v = new Editor({ element: body, editable: false, - extensions: nested(p.doc), + extensions: nested(p.doc, block || undefined), editorProps: { attributes: { class: "dw-prose" } }, }); + view = v; + if (block) { + // A synced block whose block was deleted says so instead of showing nothing. + const missing = document.createElement("p"); + missing.className = "dw-synced__note"; + missing.textContent = labels.syncedBlockMissing; + const check = () => { + const gone = !hasBlock(v.state.doc, block); + if (gone && !missing.isConnected) body.append(missing); + else if (!gone) missing.remove(); + }; + v.on("update", check); + check(); + } } }; stopWatch = p.onChange(refresh); @@ -234,7 +333,8 @@ export const SyncedPage = Node.create({ function draw() { const t = node.attrs.title as string; - title.textContent = `${node.attrs.icon ? `${node.attrs.icon} ` : ""}${t || labels.syncedPage}`; + const fallback = block ? labels.syncedBlock : labels.syncedPage; + title.textContent = `${node.attrs.icon ? `${node.attrs.icon} ` : ""}${t || fallback}`; const isFolded = folded(); dom.classList.toggle("is-folded", isFolded); fold.textContent = isFolded ? labels.syncedUnfold : labels.syncedFold; @@ -259,14 +359,16 @@ export const SyncedPage = Node.create({ if (editor.isEditable && (m.title !== node.attrs.title || m.icon !== node.attrs.icon)) { set({ title: m.title, icon: m.icon }); } else { - title.textContent = `${m.icon ? `${m.icon} ` : ""}${m.title || labels.syncedPage}`; + const fallback = block ? labels.syncedBlock : labels.syncedPage; + title.textContent = `${m.icon ? `${m.icon} ` : ""}${m.title || fallback}`; } }); return { dom, update(next) { - if (next.type !== node.type || String(next.attrs.page) !== page) return false; + if (next.type !== node.type || String(next.attrs.page) !== page || String(next.attrs.block ?? "") !== block) + return false; node = next; draw(); return true; diff --git a/Packages/editor/src/tabs.ts b/Packages/editor/src/tabs.ts new file mode 100644 index 0000000..4f5d0f3 --- /dev/null +++ b/Packages/editor/src/tabs.ts @@ -0,0 +1,275 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +import { mergeAttributes, Node, type Editor } from "@tiptap/core"; +import type { Node as PMNode } from "@tiptap/pm/model"; +import { TextSelection } from "@tiptap/pm/state"; +import type { EditorLabels } from "./labels"; + +declare module "@tiptap/core" { + interface Commands { + tabs: { + /** Puts a tabs block with two empty tabs where the selection is. */ + insertTabs: () => ReturnType; + }; + } +} + +/** A tab's name: one line, at most 60 characters. */ +export function cleanTabTitle(s: unknown): string { + return typeof s === "string" ? s.replace(/\s+/g, " ").trim().slice(0, 60) : ""; +} + +const tabName = (labels: EditorLabels | null, i: number) => + (labels?.blocks.tabName ?? "Tab {n}").replace("{n}", String(i + 1)); + +function emptyTab(editor: Editor, title: string): PMNode { + const { schema } = editor.state; + return schema.nodes.tab!.create({ title }, schema.nodes.paragraph!.create()); +} + +/** + * Content on tabs: a row of tab names over the content of the chosen one. + * Which tab shows is each reader's own choice and is not saved. Editors + * add tabs with "+", rename one by double-clicking it, and delete the + * shown one with "×". Exports show every tab, one after another. + */ +export const Tabs = Node.create<{ labels: EditorLabels | null }>({ + name: "tabs", + group: "block", + content: "tab+", + defining: true, + isolating: true, + draggable: true, + + addOptions() { + return { labels: null }; + }, + + parseHTML() { + return [{ tag: "div[data-type=tabs]" }]; + }, + + renderHTML({ HTMLAttributes }) { + return ["div", mergeAttributes(HTMLAttributes, { "data-type": "tabs", class: "dw-tabs" }), 0]; + }, + + addCommands() { + return { + insertTabs: + () => + ({ editor, tr, dispatch }) => { + const labels = this.options.labels; + const node = editor.schema.nodes.tabs!.create(null, [ + emptyTab(editor, tabName(labels, 0)), + emptyTab(editor, tabName(labels, 1)), + ]); + if (!dispatch) return true; + const from = tr.selection.from; + tr.replaceSelectionWith(node); + let start = -1; + tr.doc.nodesBetween(from, Math.min(from + node.nodeSize + 2, tr.doc.content.size), (n, pos) => { + if (start < 0 && n.type.name === "tabs") start = pos; + return start < 0; + }); + if (start >= 0) tr.setSelection(TextSelection.create(tr.doc, start + 3)); + tr.scrollIntoView(); + return true; + }, + }; + }, + + addNodeView() { + return ({ node, getPos, editor }) => { + const labels = this.options.labels; + let current = node; + let active = 0; + const dom = document.createElement("div"); + dom.className = "dw-tabs"; + dom.setAttribute("data-type", "tabs"); + const strip = document.createElement("div"); + strip.className = "dw-tabs__strip"; + strip.contentEditable = "false"; + strip.setAttribute("role", "tablist"); + const body = document.createElement("div"); + body.className = "dw-tabs__body"; + dom.append(strip, body); + + const pos = () => { + const p = getPos(); + return typeof p === "number" ? p : null; + }; + /** The position of tab i's node. */ + const tabPos = (i: number) => { + const p = pos(); + if (p === null) return null; + let at = p + 1; + for (let k = 0; k < i; k++) at += current.child(k).nodeSize; + return at; + }; + const show = () => { + [...body.children].forEach((el, i) => { + const hide = i !== active; + if ((el as HTMLElement).hidden !== hide) (el as HTMLElement).hidden = hide; + if (el.getAttribute("role") !== "tabpanel") el.setAttribute("role", "tabpanel"); + }); + }; + // ProseMirror draws the tabs' content after this view and redraws a tab + // when it changes, so the panels are hidden again whenever they appear. + const panels = new MutationObserver(show); + panels.observe(body, { childList: true }); + const rename = (i: number) => { + const at = tabPos(i); + if (at === null || !editor.isEditable) return; + const now = String(current.child(i).attrs.title ?? ""); + const next = window.prompt(labels?.blocks.renameTab ?? "Tab name", now); + if (next === null) return; + const title = cleanTabTitle(next) || tabName(labels, i); + editor.view.dispatch(editor.state.tr.setNodeAttribute(at, "title", title)); + }; + const add = () => { + const p = pos(); + if (p === null || !editor.isEditable) return; + const end = p + current.nodeSize - 1; + const tr = editor.state.tr.insert(end, emptyTab(editor, tabName(labels, current.childCount))); + active = current.childCount; + tr.setSelection(TextSelection.create(tr.doc, end + 2)); + editor.view.dispatch(tr); + editor.view.focus(); + }; + const remove = (i: number) => { + const at = tabPos(i); + if (at === null || !editor.isEditable) return; + const tr = editor.state.tr; + if (current.childCount <= 1) { + const p = pos()!; + tr.delete(p, p + current.nodeSize); + } else { + tr.delete(at, at + current.child(i).nodeSize); + active = Math.max(0, Math.min(active, current.childCount - 2)); + } + editor.view.dispatch(tr); + }; + const choose = (i: number, focus = false) => { + active = i; + draw(); + if (focus) (strip.children[i] as HTMLElement | undefined)?.focus(); + }; + + function draw() { + active = Math.min(active, current.childCount - 1); + strip.replaceChildren(); + current.forEach((tab, _o, i) => { + const b = document.createElement("button"); + b.type = "button"; + b.className = i === active ? "dw-tabs__tab is-active" : "dw-tabs__tab"; + b.setAttribute("role", "tab"); + b.setAttribute("aria-selected", String(i === active)); + b.tabIndex = i === active ? 0 : -1; + b.textContent = cleanTabTitle(tab.attrs.title) || tabName(labels, i); + b.addEventListener("mousedown", (e) => e.preventDefault()); + b.addEventListener("click", () => choose(i)); + b.addEventListener("dblclick", () => rename(i)); + b.addEventListener("keydown", (e) => { + if (e.key === "ArrowRight" || e.key === "ArrowLeft") { + e.preventDefault(); + const n = current.childCount; + choose((i + (e.key === "ArrowRight" ? 1 : -1) + n) % n, true); + } else if (e.key === "F2") { + e.preventDefault(); + rename(i); + } + }); + strip.append(b); + }); + if (editor.isEditable) { + const plus = document.createElement("button"); + plus.type = "button"; + plus.className = "dw-tabs__action"; + plus.textContent = "+"; + const addLabel = labels?.blocks.addTab ?? "Add a tab"; + plus.title = addLabel; + plus.setAttribute("aria-label", addLabel); + plus.addEventListener("mousedown", (e) => e.preventDefault()); + plus.addEventListener("click", add); + const del = document.createElement("button"); + del.type = "button"; + del.className = "dw-tabs__action dw-tabs__delete"; + del.textContent = "×"; + const delLabel = labels?.blocks.deleteTab ?? "Delete tab"; + del.title = delLabel; + del.setAttribute("aria-label", delLabel); + del.addEventListener("mousedown", (e) => e.preventDefault()); + del.addEventListener("click", () => remove(active)); + strip.append(plus, del); + } + show(); + } + draw(); + + return { + dom, + contentDOM: body, + update: (n) => { + if (n.type !== node.type) return false; + current = n; + // The caret moved into another tab (find, undo): show that one. + const p = pos(); + const { from } = editor.state.selection; + if (p !== null && from > p && from < p + n.nodeSize) { + let at = p + 1; + n.forEach((c, _o, i) => { + if (from > at && from < at + c.nodeSize) active = i; + at += c.nodeSize; + }); + } + draw(); + return true; + }, + stopEvent: (e) => strip.contains(e.target as globalThis.Node), + destroy: () => panels.disconnect(), + ignoreMutation: (m) => strip.contains(m.target) || (m.type === "attributes" && m.target.parentElement === body), + }; + }; + }, +}); + +/** One tab: its name and its blocks. */ +export const Tab = Node.create({ + name: "tab", + content: "block+", + isolating: true, + defining: true, + + addAttributes() { + return { + title: { + default: "", + parseHTML: (el) => cleanTabTitle(el.getAttribute("data-title")), + renderHTML: (a) => ({ "data-title": cleanTabTitle(a.title) }), + }, + }; + }, + + parseHTML() { + return [{ tag: "div[data-type=tab]" }]; + }, + + renderHTML({ HTMLAttributes }) { + return ["div", mergeAttributes(HTMLAttributes, { "data-type": "tab", class: "dw-tab" }), 0]; + }, + + addNodeView() { + return ({ node }) => { + const dom = document.createElement("div"); + dom.className = "dw-tab"; + dom.setAttribute("data-type", "tab"); + return { + dom, + contentDOM: dom, + update: (n) => n.type === node.type, + // The tabs block shows and hides its tabs; that is not an edit to read back. + ignoreMutation: (m) => m.type === "attributes" && m.target === dom, + }; + }; + }, +}); diff --git a/Packages/ui/src/icons.ts b/Packages/ui/src/icons.ts index f2504de..fda017a 100644 --- a/Packages/ui/src/icons.ts +++ b/Packages/ui/src/icons.ts @@ -196,6 +196,11 @@ export const iconPaths = { "M19 8v6", "M16 11h6", ], + music: ["M9 18V5l11-2v13", "M6 15a3 3 0 1 0 0 6a3 3 0 1 0 0-6z", "M17 13a3 3 0 1 0 0 6a3 3 0 1 0 0-6z"], + tabs: ["M3 9h18v11H3z", "M3 9V5h6v4", "M9 5h6v4"], + "page-break": ["M6 3v5h12V3", "M6 21v-5h12v5", "M3 12h2", "M8 12h2", "M14 12h2", "M19 12h2"], + footnote: ["M4 7h10", "M9 7v12", "M17 4h2v5", "M16 9h4"], + status: ["M7 8h10a4 4 0 0 1 0 8H7a4 4 0 0 1 0-8z", "M8 12h.01"], } as const; export type IconName = keyof typeof iconPaths; diff --git a/Phone-App/lib/editor/bridge.dart b/Phone-App/lib/editor/bridge.dart index ab8d5fa..0a6ed89 100644 --- a/Phone-App/lib/editor/bridge.dart +++ b/Phone-App/lib/editor/bridge.dart @@ -9,7 +9,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; /// Protocol version this app speaks. The page reports its own in "ready". -const editorProtocolVersion = 4; +const editorProtocolVersion = 5; /// Formatting the native toolbar can apply. enum EditorCommand { @@ -28,10 +28,19 @@ enum EditorCommand { taskList, callout, table, + footnote, + status, + tabs, + pageBreak, + emoji, + subpages, undo, redo, } +/// A child page a subpages block lists. +typedef Subpage = ({String id, String title, String icon}); + /// Toolbar state reported by the page. @immutable class EditorState { @@ -110,6 +119,10 @@ class EditorBridge extends ChangeNotifier { /// out the result and pass it to [answerTranscript] with the same id. void Function(int id, String src, String name)? onTranscribe; + /// Looks up the page's child pages, in order, when a subpages block is + /// shown; without it the block lists none. + Future> Function()? onSubpages; + Completer<({String text, String before})>? _selection; /// Whether media files get a Transcribe button, with its words. @@ -251,12 +264,29 @@ class EditorBridge extends ChangeNotifier { } else { handler(id, msg['src'] as String, msg['name'] as String); } + case 'subpages': + unawaited(_answerSubpages(msg['id'] as int)); case 'error': _error = msg['message'] as String; notifyListeners(); } } + /// Answers a "subpages" request; a failed lookup lists none. + Future _answerSubpages(int id) async { + var pages = const []; + try { + pages = await onSubpages?.call() ?? const []; + } catch (_) {} + await _post({ + 'type': 'subpageList', + 'id': id, + 'pages': [ + for (final p in pages) {'id': p.id, 'title': p.title, 'icon': p.icon}, + ], + }); + } + Future _post(Map msg) => evaluate('window.docwell.receive(${jsonEncode(jsonEncode(msg))})'); diff --git a/Phone-App/lib/editor/editor_screen.dart b/Phone-App/lib/editor/editor_screen.dart index a4f98da..a36b279 100644 --- a/Phone-App/lib/editor/editor_screen.dart +++ b/Phone-App/lib/editor/editor_screen.dart @@ -198,6 +198,16 @@ class EditorToolbar extends StatelessWidget { (EditorCommand.table, Icons.table_chart_outlined, tr('table')), (EditorCommand.blockquote, Icons.format_quote, tr('quote')), (EditorCommand.codeBlock, Icons.code, tr('codeBlock')), + (EditorCommand.tabs, Icons.tab_outlined, tr('toolTabs')), + (EditorCommand.footnote, Icons.superscript, tr('toolFootnote')), + (EditorCommand.status, Icons.label_outline, tr('toolStatus')), + (EditorCommand.emoji, Icons.emoji_emotions_outlined, tr('toolEmoji')), + (EditorCommand.subpages, Icons.account_tree_outlined, tr('toolSubpages')), + ( + EditorCommand.pageBreak, + Icons.insert_page_break_outlined, + tr('toolPageBreak'), + ), ]; @override diff --git a/Phone-App/lib/l10n.dart b/Phone-App/lib/l10n.dart index 3fd9d99..d4c53d1 100644 --- a/Phone-App/lib/l10n.dart +++ b/Phone-App/lib/l10n.dart @@ -196,6 +196,12 @@ const appStrings = >{ 'table': 'Table', 'quote': 'Quote', 'codeBlock': 'Code block', + 'toolTabs': 'Tabs', + 'toolFootnote': 'Footnote', + 'toolStatus': 'Status', + 'toolEmoji': 'Emoji', + 'toolSubpages': 'Subpages', + 'toolPageBreak': 'Page break', 'undo': 'Undo', 'redo': 'Redo', }, @@ -359,6 +365,12 @@ const appStrings = >{ 'table': 'Tabela', 'quote': 'Cytat', 'codeBlock': 'Blok kodu', + 'toolTabs': 'Karty', + 'toolFootnote': 'Przypis', + 'toolStatus': 'Status', + 'toolEmoji': 'Emoji', + 'toolSubpages': 'Podstrony', + 'toolPageBreak': 'Podział strony', 'undo': 'Cofnij', 'redo': 'Ponów', }, @@ -525,6 +537,12 @@ const appStrings = >{ 'table': 'Tabelle', 'quote': 'Zitat', 'codeBlock': 'Codeblock', + 'toolTabs': 'Tabs', + 'toolFootnote': 'Fußnote', + 'toolStatus': 'Status', + 'toolEmoji': 'Emoji', + 'toolSubpages': 'Unterseiten', + 'toolPageBreak': 'Seitenumbruch', 'undo': 'Rückgängig', 'redo': 'Wiederholen', }, @@ -692,6 +710,12 @@ const appStrings = >{ 'table': 'Tableau', 'quote': 'Citation', 'codeBlock': 'Bloc de code', + 'toolTabs': 'Onglets', + 'toolFootnote': 'Note de bas de page', + 'toolStatus': 'Statut', + 'toolEmoji': 'Emoji', + 'toolSubpages': 'Sous-pages', + 'toolPageBreak': 'Saut de page', 'undo': 'Annuler', 'redo': 'Rétablir', }, @@ -857,6 +881,12 @@ const appStrings = >{ 'table': 'Tabla', 'quote': 'Cita', 'codeBlock': 'Bloque de código', + 'toolTabs': 'Pestañas', + 'toolFootnote': 'Nota al pie', + 'toolStatus': 'Estado', + 'toolEmoji': 'Emoji', + 'toolSubpages': 'Subpáginas', + 'toolPageBreak': 'Salto de página', 'undo': 'Deshacer', 'redo': 'Rehacer', }, diff --git a/Phone-App/lib/screens/page_screen.dart b/Phone-App/lib/screens/page_screen.dart index f94e4d1..281861c 100644 --- a/Phone-App/lib/screens/page_screen.dart +++ b/Phone-App/lib/screens/page_screen.dart @@ -107,6 +107,15 @@ class _PageScreenState extends State { unawaited(loadEditorPage(_web, server: _api.baseUrl)); _bridge.onTranscribe = (id, src, _) => transcribeForEditor(_api, _bridge, id, src); + // Subpages blocks list the page's children, from the space's page tree. + _bridge.onSubpages = () async { + final page = _page ?? await _api.page(widget.pageId); + final nodes = await _api.pages(page.space); + return [ + for (final n in nodes) + if (n.parent == page.id) (id: n.id, title: n.title, icon: n.icon), + ]; + }; _load(); } diff --git a/Phone-App/test/editor_bridge_test.dart b/Phone-App/test/editor_bridge_test.dart index 4a02045..5f2ed94 100644 --- a/Phone-App/test/editor_bridge_test.dart +++ b/Phone-App/test/editor_bridge_test.dart @@ -100,4 +100,30 @@ void main() { }); expect(sent.last['content']['text'], "it's \"quoted\" \u2028"); }); + + test("answers a subpages request with the page's children", () async { + bridge.onSubpages = () async => [(id: 'c1', title: 'Setup', icon: '🛠')]; + bridge.handleMessage('{"type":"subpages","id":3}'); + await pumpEventQueue(); + expect(sent.last, { + 'type': 'subpageList', + 'id': 3, + 'pages': [ + {'id': 'c1', 'title': 'Setup', 'icon': '🛠'}, + ], + }); + }); + + test('answers a subpages request with none when the lookup fails', () async { + bridge.onSubpages = () async => throw StateError('offline'); + bridge.handleMessage('{"type":"subpages","id":4}'); + await pumpEventQueue(); + expect(sent.last, {'type': 'subpageList', 'id': 4, 'pages': []}); + }); + + test('sends the new block commands by name', () async { + await bridge.run(EditorCommand.footnote); + await bridge.run(EditorCommand.pageBreak); + expect(sent.map((m) => m['command']), ['footnote', 'pageBreak']); + }); } diff --git a/Server/internal/convert/columns.go b/Server/internal/convert/columns.go index ba3fd34..e679cf1 100644 --- a/Server/internal/convert/columns.go +++ b/Server/internal/convert/columns.go @@ -16,7 +16,7 @@ import ( // equal share. Exports to Markdown, Word and PDF put the columns one after // another; HTML keeps them side by side. -const maxColumns = 4 +const maxColumns = 5 // newColumns is a row of columns around these bodies. Empty bodies are left // out; fewer than two left are returned as plain blocks, and anything past diff --git a/Server/internal/convert/columns_test.go b/Server/internal/convert/columns_test.go index 0069445..3d40258 100644 --- a/Server/internal/convert/columns_test.go +++ b/Server/internal/convert/columns_test.go @@ -68,10 +68,10 @@ func TestNotionAndConfluenceColumns(t *testing.T) { } } -func TestColumnsPastFourJoinTheFourth(t *testing.T) { - bodies := [][]Node{{cpara("1")}, {cpara("2")}, {cpara("3")}, {cpara("4")}, {cpara("5")}} +func TestColumnsPastFiveJoinTheFifth(t *testing.T) { + bodies := [][]Node{{cpara("1")}, {cpara("2")}, {cpara("3")}, {cpara("4")}, {cpara("5")}, {cpara("6")}} row := newColumns(bodies, nil)[0] - if len(row.Content) != 4 || len(row.Content[3].Content) != 2 { + if len(row.Content) != 5 || len(row.Content[4].Content) != 2 { t.Fatalf("row: %+v", row) } } diff --git a/Server/internal/convert/docx_export.go b/Server/internal/convert/docx_export.go index 4b84aed..35a67e2 100644 --- a/Server/internal/convert/docx_export.go +++ b/Server/internal/convert/docx_export.go @@ -26,12 +26,22 @@ type DOCXOptions struct { // highlights, links and images are kept in a form FromDOCX reads back. // Diagrams and embeds become links, formulas their LaTeX. func DOCX(title string, doc Node, o DOCXOptions) ([]byte, error) { - doc = withoutSuggestions(expandDatabases(doc)) + doc, notes := numberFootnotes(withoutSuggestions(expandDatabases(doc))) w := &docxWriter{o: o} if strings.TrimSpace(title) != "" { w.para(paraProps{style: "Title"}, func() { w.text(title, runProps{}) }) } w.blocks(doc.Content, blockCtx{}) + // Footnotes are listed at the end, numbered like their marks in the text. + if len(notes) > 0 { + w.para(paraProps{rule: true}, nil) + for i, note := range notes { + w.para(paraProps{}, func() { + w.text(strconv.Itoa(i+1)+". ", runProps{bold: true}) + w.inline(note, runProps{}) + }) + } + } return w.pack(title) } @@ -376,6 +386,25 @@ func (w *docxWriter) block(n Node, ctx blockCtx) { w.para(paraProps{align: "center"}, func() { w.text(n.attr("latex"), runProps{code: true}) }) case "horizontalRule": w.para(paraProps{rule: true}, nil) + case "pageBreak": + w.b.WriteString(``) + case "tabs": + for i, tab := range n.Content { + w.para(w.textPara(ctx), func() { w.text(tabTitle(tab, i), runProps{bold: true}) }) + w.blocks(tab.Content, ctx) + } + case "video", "audio": + name := n.attr("name") + if name == "" { + name = n.Type + } + w.para(paraProps{}, func() { w.text(name, runProps{href: w.link(n.attr("src"))}) }) + case "subpages": + for _, p := range w.o.Subpages { + w.para(paraProps{style: "ListParagraph", indent: 360 + ctx.depth*360}, func() { + w.text(p.label(), runProps{href: w.link("/p/" + p.ID)}) + }) + } case "image": w.image(n.attr("src"), n.attr("alt")) case "drawio", "excalidraw": @@ -547,6 +576,10 @@ func (w *docxWriter) inline(nodes []Node, base runProps) { w.text("@"+mentionLabel(n), runProps{bold: true}) case "dateMention": w.text(n.attr("date"), runProps{bold: true}) + case "status": + w.text(statusText(n), runProps{bold: true, shade: strings.TrimPrefix(paletteBackground[statusColor(n)], "#")}) + case "footnote": + w.text("["+footnoteNumber(n)+"]", runProps{color: "787878"}) default: w.inline(n.Content, base) } diff --git a/Server/internal/convert/export.go b/Server/internal/convert/export.go index 2036bc4..8e4a183 100644 --- a/Server/internal/convert/export.go +++ b/Server/internal/convert/export.go @@ -19,6 +19,28 @@ type Options struct { // PageURL rewrites links to pages (/p/, with an optional #fragment // for a block), e.g. to files in a space export; nil keeps them. PageURL func(id, fragment string) string + // Subpages are the exported page's child pages, in order, for its + // subpages blocks; without them those blocks are left out. + Subpages []PageLink +} + +// PageLink is a page a subpages block lists. +type PageLink struct { + ID string + Title string + Icon string +} + +// label is the page's icon and title as a link shows them. +func (p PageLink) label() string { + t := p.Title + if t == "" { + t = "Untitled" + } + if p.Icon != "" { + return p.Icon + " " + t + } + return t } var pageLink = regexp.MustCompile(`^/p/([A-Za-z0-9_-]+)/?(#[\w-]*)?$`) @@ -45,11 +67,22 @@ var safeURL = regexp.MustCompile(`^(?i)(https?://|mailto:|/|#|\.{0,2}/|[^:/?#]+( // HTML renders the document's body as HTML. func HTML(doc Node, o Options) string { - doc = expandDatabases(doc) + doc, notes := numberFootnotes(expandDatabases(doc)) var b strings.Builder for _, n := range doc.Content { writeHTML(&b, n, o) } + if len(notes) > 0 { + b.WriteString("
    \n
    \n
      \n") + for i, note := range notes { + fmt.Fprintf(&b, "
    1. ", i+1) + for _, n := range note { + writeHTML(&b, n, o) + } + fmt.Fprintf(&b, " ↩
    2. \n", i+1) + } + b.WriteString("
    \n
    \n") + } return b.String() } @@ -145,6 +178,47 @@ func writeHTML(b *strings.Builder, n Node, o Options) { b.WriteString("\n") case "horizontalRule": b.WriteString("
    \n") + case "pageBreak": + b.WriteString("
    \n") + case "status": + c := n.attr("color") + if !isPaletteColor(c) { + c = "gray" + } + fmt.Fprintf(b, "%s", + c, paletteBackground[c], paletteText[c], html.EscapeString(statusText(n))) + case "footnote": + num := footnoteNumber(n) + fmt.Fprintf(b, "[%s]", + html.EscapeString(n.attr("text")), num, num, num) + case "tabs": + // Every tab is shown, its name as a heading over its content. + b.WriteString("
    \n") + for i, tab := range n.Content { + fmt.Fprintf(b, "
    \n

    %s

    \n", + html.EscapeString(tab.attr("title")), html.EscapeString(tabTitle(tab, i))) + for _, c := range tab.Content { + writeHTML(b, c, o) + } + b.WriteString("
    \n") + } + b.WriteString("
    \n") + case "video", "audio": + src := o.file(n.attr("src")) + if !safeURL.MatchString(src) { + return + } + fmt.Fprintf(b, "<%s src=\"%s\" controls preload=\"metadata\" data-name=\"%s\">\n", + n.Type, html.EscapeString(src), html.EscapeString(n.attr("name")), n.Type) + case "subpages": + if len(o.Subpages) == 0 { + return + } + b.WriteString("
      \n") + for _, p := range o.Subpages { + fmt.Fprintf(b, "
    • %s
    • \n", html.EscapeString(o.file("/p/"+p.ID)), html.EscapeString(p.label())) + } + b.WriteString("
    \n") case "hardBreak": b.WriteString("
    ") case "image": @@ -262,10 +336,18 @@ func writeHTMLText(b *strings.Builder, n Node, o Options) { // Markdown renders the document as CommonMark (with ~~strikethrough~~). func Markdown(doc Node, o Options) string { - doc = withoutSuggestions(expandDatabases(doc)) + doc, notes := numberFootnotes(withoutSuggestions(expandDatabases(doc))) w := &mdWriter{o: o} w.blocks(doc.Content, "", "") - return strings.TrimRight(w.b.String(), "\n") + "\n" + out := strings.TrimRight(w.b.String(), "\n") + "\n" + if len(notes) > 0 { + // Footnote definitions, as GitHub and most Markdown tools read them. + out += "\n" + for i, note := range notes { + out += "[^" + strconv.Itoa(i+1) + "]: " + strings.ReplaceAll(w.inline(oneLine(note)), "\n", " ") + "\n" + } + } + return out } // MarkdownPage is Markdown with the title as a leading heading. @@ -375,6 +457,41 @@ func (w *mdWriter) block(n Node, first, rest string) { w.lines(fence+n.attr("language")+"\n"+text+"\n"+fence, first, rest) case "horizontalRule": w.lines("---", first, rest) + case "pageBreak": + // Markdown has no page break; tools that print Markdown read this HTML. + w.lines("
    ", first, rest) + case "tabs": + for i, tab := range n.Content { + p := rest + if i == 0 { + p = first + } else { + w.b.WriteString(strings.TrimRight(rest, " ") + "\n") + } + w.lines("**"+escapeMD(tabTitle(tab, i))+"**", p, rest) + if len(tab.Content) > 0 { + w.b.WriteString(strings.TrimRight(rest, " ") + "\n") + w.blocks(tab.Content, rest, rest) + } + } + case "video", "audio": + src := w.o.file(n.attr("src")) + if !safeURL.MatchString(src) { + return + } + name := n.attr("name") + if name == "" { + name = n.Type + } + w.lines("["+escapeMD(name)+"]("+mdURL(src)+")", first, rest) + case "subpages": + for i, p := range w.o.Subpages { + pre := rest + if i == 0 { + pre = first + } + w.lines("- ["+escapeMD(p.label())+"]("+mdURL(w.o.file("/p/"+p.ID))+")", pre, rest) + } case "image": w.lines("!["+escapeMD(n.attr("alt"))+"]("+mdURL(w.o.file(n.attr("src")))+")", first, rest) case "fileAttachment": @@ -475,6 +592,10 @@ func (w *mdWriter) inline(nodes []Node) string { b.WriteString("@" + escapeMD(mentionLabel(n))) case "dateMention": b.WriteString(escapeMD(n.attr("date"))) + case "status": + b.WriteString("`" + strings.ReplaceAll(statusText(n), "`", "'") + "`") + case "footnote": + b.WriteString("[^" + footnoteNumber(n) + "]") default: b.WriteString(w.inline(n.Content)) } diff --git a/Server/internal/convert/footnotes.go b/Server/internal/convert/footnotes.go new file mode 100644 index 0000000..5a4bd30 --- /dev/null +++ b/Server/internal/convert/footnotes.go @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +package convert + +import ( + "encoding/json" + "strconv" +) + +// numberFootnotes returns a copy of doc in which each footnote carries its +// number (attr "n") in reading order, and the footnotes' texts (see +// footnoteContent) in that order. Exports show the number in the text and +// list the notes at the end, as the editor does. +func numberFootnotes(doc Node) (Node, [][]Node) { + var notes [][]Node + var walk func(n Node) Node + walk = func(n Node) Node { + if n.Type == "footnote" { + notes = append(notes, footnoteContent(n)) + attrs := make(map[string]any, len(n.Attrs)+1) + for k, v := range n.Attrs { + attrs[k] = v + } + attrs["n"] = float64(len(notes)) + n.Attrs = attrs + return n + } + if len(n.Content) > 0 { + content := make([]Node, len(n.Content)) + for i, c := range n.Content { + content[i] = walk(c) + } + n.Content = content + } + return n + } + return walk(doc), notes +} + +// footnoteContent is a footnote's text as inline nodes: its formatted text +// (attr "content": text runs with marks, and line breaks), or its plain text +// (attr "text") as one run for notes without. +func footnoteContent(n Node) []Node { + if raw, ok := n.Attrs["content"].([]any); ok && len(raw) > 0 { + var nodes []Node + if b, err := json.Marshal(raw); err == nil && json.Unmarshal(b, &nodes) == nil { + kept := nodes[:0] + for _, c := range nodes { + if (c.Type == "text" && c.Text != "") || c.Type == "hardBreak" { + c.Content = nil + kept = append(kept, c) + } + } + if len(kept) > 0 { + return kept + } + } + } + if t := n.attr("text"); t != "" { + return []Node{{Type: "text", Text: t}} + } + return nil +} + +// oneLine turns a note's line breaks into spaces, for formats where a note +// must stay on one line. +func oneLine(nodes []Node) []Node { + out := make([]Node, len(nodes)) + for i, n := range nodes { + if n.Type == "hardBreak" { + n = Node{Type: "text", Text: " "} + } + out[i] = n + } + return out +} + +// footnoteNumber is a numbered footnote's number as text ("1"), or "*". +func footnoteNumber(n Node) string { + if v := n.intAttr("n", 0); v > 0 { + return strconv.Itoa(v) + } + return "*" +} + +// statusText is a status badge's words. +func statusText(n Node) string { + if t := n.attr("text"); t != "" { + return t + } + return "Status" +} + +// statusColor is a status badge's palette colour, grey when it has none. +func statusColor(n Node) string { + if c := n.attr("color"); isPaletteColor(c) { + return c + } + return "gray" +} + +// tabTitle is a tab's name, or "Tab " for one without. +func tabTitle(n Node, i int) string { + if t := n.attr("title"); t != "" { + return t + } + return "Tab " + strconv.Itoa(i+1) +} diff --git a/Server/internal/convert/footnotes_test.go b/Server/internal/convert/footnotes_test.go new file mode 100644 index 0000000..f3cdcfe --- /dev/null +++ b/Server/internal/convert/footnotes_test.go @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +package convert + +import ( + "bytes" + "strings" + "testing" +) + +const docmostBlocks = `{"type":"doc","content":[ + {"type":"paragraph","content":[{"type":"text","text":"Plan "}, + {"type":"status","attrs":{"text":"In review","color":"green"}}, + {"type":"text","text":" see"},{"type":"footnote","attrs":{"text":"First note"}}, + {"type":"text","text":" and"},{"type":"footnote","attrs":{"text":"Second note"}}]}, + {"type":"pageBreak"}, + {"type":"tabs","content":[ + {"type":"tab","attrs":{"title":"Mac"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Cmd"}]}]}, + {"type":"tab","attrs":{"title":""},"content":[{"type":"paragraph","content":[{"type":"text","text":"Ctrl"}]}]}]}, + {"type":"video","attrs":{"src":"/api/v1/files/v1","name":"demo.mp4"}}, + {"type":"audio","attrs":{"src":"javascript:alert(1)","name":"x"}}, + {"type":"subpages"}, + {"type":"syncedPage","attrs":{"page":"P1","block":"k3j9x2a1"}}]}` + +func TestDocmostBlocksExport(t *testing.T) { + doc, err := Parse([]byte(docmostBlocks)) + if err != nil { + t.Fatal(err) + } + h := HTML(doc, Options{}) + for _, want := range []string{ + `data-type="status" data-color="green"`, `>In review`, + `[1]`, `[2]`, + `
  • Second note ↩
  • `, + `break-after:page`, + `

    Mac

    `, `

    Tab 2

    `, `

    Ctrl

    `, + `