4 lines
143 KiB
JavaScript
4 lines
143 KiB
JavaScript
"use strict";var e=require("obsidian"),t=require("@codemirror/view"),n=require("@codemirror/state"),r=require("@codemirror/language");class i{static get version(){return"1.4.0"}static toString(){return"JavaScript Expression Parser (JSEP) v"+i.version}static addUnaryOp(e){return i.max_unop_len=Math.max(e.length,i.max_unop_len),i.unary_ops[e]=1,i}static addBinaryOp(e,t,n){return i.max_binop_len=Math.max(e.length,i.max_binop_len),i.binary_ops[e]=t,n?i.right_associative.add(e):i.right_associative.delete(e),i}static addIdentifierChar(e){return i.additional_identifier_chars.add(e),i}static addLiteral(e,t){return i.literals[e]=t,i}static removeUnaryOp(e){return delete i.unary_ops[e],e.length===i.max_unop_len&&(i.max_unop_len=i.getMaxKeyLen(i.unary_ops)),i}static removeAllUnaryOps(){return i.unary_ops={},i.max_unop_len=0,i}static removeIdentifierChar(e){return i.additional_identifier_chars.delete(e),i}static removeBinaryOp(e){return delete i.binary_ops[e],e.length===i.max_binop_len&&(i.max_binop_len=i.getMaxKeyLen(i.binary_ops)),i.right_associative.delete(e),i}static removeAllBinaryOps(){return i.binary_ops={},i.max_binop_len=0,i}static removeLiteral(e){return delete i.literals[e],i}static removeAllLiterals(){return i.literals={},i}get char(){return this.expr.charAt(this.index)}get code(){return this.expr.charCodeAt(this.index)}constructor(e){this.expr=e,this.index=0}static parse(e){return new i(e).parse()}static getMaxKeyLen(e){return Math.max(0,...Object.keys(e).map((e=>e.length)))}static isDecimalDigit(e){return e>=48&&e<=57}static binaryPrecedence(e){return i.binary_ops[e]||0}static isIdentifierStart(e){return e>=65&&e<=90||e>=97&&e<=122||e>=128&&!i.binary_ops[String.fromCharCode(e)]||i.additional_identifier_chars.has(String.fromCharCode(e))}static isIdentifierPart(e){return i.isIdentifierStart(e)||i.isDecimalDigit(e)}throwError(e){const t=new Error(e+" at character "+this.index);throw t.index=this.index,t.description=e,t}runHook(e,t){if(i.hooks[e]){const n={context:this,node:t};return i.hooks.run(e,n),n.node}return t}searchHook(e){if(i.hooks[e]){const t={context:this};return i.hooks[e].find((function(e){return e.call(t.context,t),t.node})),t.node}}gobbleSpaces(){let e=this.code;for(;e===i.SPACE_CODE||e===i.TAB_CODE||e===i.LF_CODE||e===i.CR_CODE;)e=this.expr.charCodeAt(++this.index);this.runHook("gobble-spaces")}parse(){this.runHook("before-all");const e=this.gobbleExpressions(),t=1===e.length?e[0]:{type:i.COMPOUND,body:e};return this.runHook("after-all",t)}gobbleExpressions(e){let t,n,r=[];for(;this.index<this.expr.length;)if(t=this.code,t===i.SEMCOL_CODE||t===i.COMMA_CODE)this.index++;else if(n=this.gobbleExpression())r.push(n);else if(this.index<this.expr.length){if(t===e)break;this.throwError('Unexpected "'+this.char+'"')}return r}gobbleExpression(){const e=this.searchHook("gobble-expression")||this.gobbleBinaryExpression();return this.gobbleSpaces(),this.runHook("after-expression",e)}gobbleBinaryOp(){this.gobbleSpaces();let e=this.expr.substr(this.index,i.max_binop_len),t=e.length;for(;t>0;){if(i.binary_ops.hasOwnProperty(e)&&(!i.isIdentifierStart(this.code)||this.index+e.length<this.expr.length&&!i.isIdentifierPart(this.expr.charCodeAt(this.index+e.length))))return this.index+=t,e;e=e.substr(0,--t)}return!1}gobbleBinaryExpression(){let e,t,n,r,o,s,a,c,l;if(s=this.gobbleToken(),!s)return s;if(t=this.gobbleBinaryOp(),!t)return s;for(o={value:t,prec:i.binaryPrecedence(t),right_a:i.right_associative.has(t)},a=this.gobbleToken(),a||this.throwError("Expected expression after "+t),r=[s,o,a];t=this.gobbleBinaryOp();){if(n=i.binaryPrecedence(t),0===n){this.index-=t.length;break}o={value:t,prec:n,right_a:i.right_associative.has(t)},l=t;const c=e=>o.right_a&&e.right_a?n>e.prec:n<=e.prec;for(;r.length>2&&c(r[r.length-2]);)a=r.pop(),t=r.pop().value,s=r.pop(),e={type:i.BINARY_EXP,operator:t,left:s,right:a},r.push(e);e=this.gobbleToken(),e||this.throwError("Expected expression after "+l),r.push(o,e)}for(c=r.length-1,e=r[c];c>1;)e={type:i.BINARY_EXP,operator:r[c-1].value,left:r[c-2],right:e},c-=2;return e}gobbleToken(){let e,t,n,r;if(this.gobbleSpaces(),r=this.searchHook("gobble-token"),r)return this.runHook("after-token",r);if(e=this.code,i.isDecimalDigit(e)||e===i.PERIOD_CODE)return this.gobbleNumericLiteral();if(e===i.SQUOTE_CODE||e===i.DQUOTE_CODE)r=this.gobbleStringLiteral();else if(e===i.OBRACK_CODE)r=this.gobbleArray();else{for(t=this.expr.substr(this.index,i.max_unop_len),n=t.length;n>0;){if(i.unary_ops.hasOwnProperty(t)&&(!i.isIdentifierStart(this.code)||this.index+t.length<this.expr.length&&!i.isIdentifierPart(this.expr.charCodeAt(this.index+t.length)))){this.index+=n;const e=this.gobbleToken();return e||this.throwError("missing unaryOp argument"),this.runHook("after-token",{type:i.UNARY_EXP,operator:t,argument:e,prefix:!0})}t=t.substr(0,--n)}i.isIdentifierStart(e)?(r=this.gobbleIdentifier(),i.literals.hasOwnProperty(r.name)?r={type:i.LITERAL,value:i.literals[r.name],raw:r.name}:r.name===i.this_str&&(r={type:i.THIS_EXP})):e===i.OPAREN_CODE&&(r=this.gobbleGroup())}return r?(r=this.gobbleTokenProperty(r),this.runHook("after-token",r)):this.runHook("after-token",!1)}gobbleTokenProperty(e){this.gobbleSpaces();let t=this.code;for(;t===i.PERIOD_CODE||t===i.OBRACK_CODE||t===i.OPAREN_CODE||t===i.QUMARK_CODE;){let n;if(t===i.QUMARK_CODE){if(this.expr.charCodeAt(this.index+1)!==i.PERIOD_CODE)break;n=!0,this.index+=2,this.gobbleSpaces(),t=this.code}this.index++,t===i.OBRACK_CODE?((e={type:i.MEMBER_EXP,computed:!0,object:e,property:this.gobbleExpression()}).property||this.throwError('Unexpected "'+this.char+'"'),this.gobbleSpaces(),t=this.code,t!==i.CBRACK_CODE&&this.throwError("Unclosed ["),this.index++):t===i.OPAREN_CODE?e={type:i.CALL_EXP,arguments:this.gobbleArguments(i.CPAREN_CODE),callee:e}:(t===i.PERIOD_CODE||n)&&(n&&this.index--,this.gobbleSpaces(),e={type:i.MEMBER_EXP,computed:!1,object:e,property:this.gobbleIdentifier()}),n&&(e.optional=!0),this.gobbleSpaces(),t=this.code}return e}gobbleNumericLiteral(){let e,t,n="";for(;i.isDecimalDigit(this.code);)n+=this.expr.charAt(this.index++);if(this.code===i.PERIOD_CODE)for(n+=this.expr.charAt(this.index++);i.isDecimalDigit(this.code);)n+=this.expr.charAt(this.index++);if(e=this.char,"e"===e||"E"===e){for(n+=this.expr.charAt(this.index++),e=this.char,"+"!==e&&"-"!==e||(n+=this.expr.charAt(this.index++));i.isDecimalDigit(this.code);)n+=this.expr.charAt(this.index++);i.isDecimalDigit(this.expr.charCodeAt(this.index-1))||this.throwError("Expected exponent ("+n+this.char+")")}return t=this.code,i.isIdentifierStart(t)?this.throwError("Variable names cannot start with a number ("+n+this.char+")"):(t===i.PERIOD_CODE||1===n.length&&n.charCodeAt(0)===i.PERIOD_CODE)&&this.throwError("Unexpected period"),{type:i.LITERAL,value:parseFloat(n),raw:n}}gobbleStringLiteral(){let e="";const t=this.index,n=this.expr.charAt(this.index++);let r=!1;for(;this.index<this.expr.length;){let t=this.expr.charAt(this.index++);if(t===n){r=!0;break}if("\\"===t)switch(t=this.expr.charAt(this.index++),t){case"n":e+="\n";break;case"r":e+="\r";break;case"t":e+="\t";break;case"b":e+="\b";break;case"f":e+="\f";break;case"v":e+="\v";break;default:e+=t}else e+=t}return r||this.throwError('Unclosed quote after "'+e+'"'),{type:i.LITERAL,value:e,raw:this.expr.substring(t,this.index)}}gobbleIdentifier(){let e=this.code,t=this.index;for(i.isIdentifierStart(e)?this.index++:this.throwError("Unexpected "+this.char);this.index<this.expr.length&&(e=this.code,i.isIdentifierPart(e));)this.index++;return{type:i.IDENTIFIER,name:this.expr.slice(t,this.index)}}gobbleArguments(e){const t=[];let n=!1,r=0;for(;this.index<this.expr.length;){this.gobbleSpaces();let o=this.code;if(o===e){n=!0,this.index++,e===i.CPAREN_CODE&&r&&r>=t.length&&this.throwError("Unexpected token "+String.fromCharCode(e));break}if(o===i.COMMA_CODE){if(this.index++,r++,r!==t.length)if(e===i.CPAREN_CODE)this.throwError("Unexpected token ,");else if(e===i.CBRACK_CODE)for(let e=t.length;e<r;e++)t.push(null)}else if(t.length!==r&&0!==r)this.throwError("Expected comma");else{const e=this.gobbleExpression();e&&e.type!==i.COMPOUND||this.throwError("Expected comma"),t.push(e)}}return n||this.throwError("Expected "+String.fromCharCode(e)),t}gobbleGroup(){this.index++;let e=this.gobbleExpressions(i.CPAREN_CODE);if(this.code===i.CPAREN_CODE)return this.index++,1===e.length?e[0]:!!e.length&&{type:i.SEQUENCE_EXP,expressions:e};this.throwError("Unclosed (")}gobbleArray(){return this.index++,{type:i.ARRAY_EXP,elements:this.gobbleArguments(i.CBRACK_CODE)}}}const o=new class{add(e,t,n){if("string"!=typeof arguments[0])for(let e in arguments[0])this.add(e,arguments[0][e],arguments[1]);else(Array.isArray(e)?e:[e]).forEach((function(e){this[e]=this[e]||[],t&&this[e][n?"unshift":"push"](t)}),this)}run(e,t){this[e]=this[e]||[],this[e].forEach((function(e){e.call(t&&t.context?t.context:t,t)}))}};Object.assign(i,{hooks:o,plugins:new class{constructor(e){this.jsep=e,this.registered={}}register(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];t.forEach((e=>{if("object"!=typeof e||!e.name||!e.init)throw new Error("Invalid JSEP plugin format");this.registered[e.name]||(e.init(this.jsep),this.registered[e.name]=e)}))}}(i),COMPOUND:"Compound",SEQUENCE_EXP:"SequenceExpression",IDENTIFIER:"Identifier",MEMBER_EXP:"MemberExpression",LITERAL:"Literal",THIS_EXP:"ThisExpression",CALL_EXP:"CallExpression",UNARY_EXP:"UnaryExpression",BINARY_EXP:"BinaryExpression",ARRAY_EXP:"ArrayExpression",TAB_CODE:9,LF_CODE:10,CR_CODE:13,SPACE_CODE:32,PERIOD_CODE:46,COMMA_CODE:44,SQUOTE_CODE:39,DQUOTE_CODE:34,OPAREN_CODE:40,CPAREN_CODE:41,OBRACK_CODE:91,CBRACK_CODE:93,QUMARK_CODE:63,SEMCOL_CODE:59,COLON_CODE:58,unary_ops:{"-":1,"!":1,"~":1,"+":1},binary_ops:{"||":1,"??":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10,"**":11},right_associative:new Set(["**"]),additional_identifier_chars:new Set(["$","_"]),literals:{true:!0,false:!1,null:null},this_str:"this"}),i.max_unop_len=i.getMaxKeyLen(i.unary_ops),i.max_binop_len=i.getMaxKeyLen(i.binary_ops);const s=e=>new i(e).parse(),a=Object.getOwnPropertyNames(class{});Object.getOwnPropertyNames(i).filter((e=>!a.includes(e)&&void 0===s[e])).forEach((e=>{s[e]=i[e]})),s.Jsep=i;var c={name:"ternary",init(e){e.hooks.add("after-expression",(function(t){if(t.node&&this.code===e.QUMARK_CODE){this.index++;const n=t.node,r=this.gobbleExpression();if(r||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;const i=this.gobbleExpression();if(i||this.throwError("Expected expression"),t.node={type:"ConditionalExpression",test:n,consequent:r,alternate:i},n.operator&&e.binary_ops[n.operator]<=.9){let r=n;for(;r.right.operator&&e.binary_ops[r.right.operator]<=.9;)r=r.right;t.node.test=r.right,r.right=t.node,t.node=n}}else this.throwError("Expected :")}}))}};s.plugins.register(c);var l={name:"regex",init(e){e.hooks.add("gobble-token",(function(t){if(47===this.code){const n=++this.index;let r=!1;for(;this.index<this.expr.length;){if(47===this.code&&!r){const r=this.expr.slice(n,this.index);let i,o="";for(;++this.index<this.expr.length;){const e=this.code;if(!(e>=97&&e<=122||e>=65&&e<=90||e>=48&&e<=57))break;o+=this.char}try{i=new RegExp(r,o)}catch(e){this.throwError(e.message)}return t.node={type:e.LITERAL,value:i,raw:this.expr.slice(n-1,this.index)},t.node=this.gobbleTokenProperty(t.node),t.node}this.code===e.OBRACK_CODE?r=!0:r&&this.code===e.CBRACK_CODE&&(r=!1),this.index+=92===this.code?2:1}this.throwError("Unclosed Regex")}}))}};const u={name:"assignment",assignmentOperators:new Set(["=","*=","**=","/=","%=","+=","-=","<<=",">>=",">>>=","&=","^=","|=","||=","&&=","??="]),updateOperators:[43,45],assignmentPrecedence:.9,init(e){const t=[e.IDENTIFIER,e.MEMBER_EXP];function n(e){u.assignmentOperators.has(e.operator)?(e.type="AssignmentExpression",n(e.left),n(e.right)):e.operator||Object.values(e).forEach((e=>{e&&"object"==typeof e&&n(e)}))}u.assignmentOperators.forEach((t=>e.addBinaryOp(t,u.assignmentPrecedence,!0))),e.hooks.add("gobble-token",(function(e){const n=this.code;u.updateOperators.some((e=>e===n&&e===this.expr.charCodeAt(this.index+1)))&&(this.index+=2,e.node={type:"UpdateExpression",operator:43===n?"++":"--",argument:this.gobbleTokenProperty(this.gobbleIdentifier()),prefix:!0},e.node.argument&&t.includes(e.node.argument.type)||this.throwError(`Unexpected ${e.node.operator}`))})),e.hooks.add("after-token",(function(e){if(e.node){const n=this.code;u.updateOperators.some((e=>e===n&&e===this.expr.charCodeAt(this.index+1)))&&(t.includes(e.node.type)||this.throwError(`Unexpected ${e.node.operator}`),this.index+=2,e.node={type:"UpdateExpression",operator:43===n?"++":"--",argument:e.node,prefix:!1})}})),e.hooks.add("after-expression",(function(e){e.node&&n(e.node)}))}};s.plugins.register(l,u),s.addUnaryOp("typeof"),s.addLiteral("null",null),s.addLiteral("undefined",void 0);const h=new Set(["constructor","__proto__","__defineGetter__","__defineSetter__"]),f={evalAst(e,t){switch(e.type){case"BinaryExpression":case"LogicalExpression":return f.evalBinaryExpression(e,t);case"Compound":return f.evalCompound(e,t);case"ConditionalExpression":return f.evalConditionalExpression(e,t);case"Identifier":return f.evalIdentifier(e,t);case"Literal":return f.evalLiteral(e,t);case"MemberExpression":return f.evalMemberExpression(e,t);case"UnaryExpression":return f.evalUnaryExpression(e,t);case"ArrayExpression":return f.evalArrayExpression(e,t);case"CallExpression":return f.evalCallExpression(e,t);case"AssignmentExpression":return f.evalAssignmentExpression(e,t);default:throw SyntaxError("Unexpected expression",e)}},evalBinaryExpression:(e,t)=>({"||":(e,t)=>e||t(),"&&":(e,t)=>e&&t(),"|":(e,t)=>e|t(),"^":(e,t)=>e^t(),"&":(e,t)=>e&t(),"==":(e,t)=>e==t(),"!=":(e,t)=>e!=t(),"===":(e,t)=>e===t(),"!==":(e,t)=>e!==t(),"<":(e,t)=>e<t(),">":(e,t)=>e>t(),"<=":(e,t)=>e<=t(),">=":(e,t)=>e>=t(),"<<":(e,t)=>e<<t(),">>":(e,t)=>e>>t(),">>>":(e,t)=>e>>>t(),"+":(e,t)=>e+t(),"-":(e,t)=>e-t(),"*":(e,t)=>e*t(),"/":(e,t)=>e/t(),"%":(e,t)=>e%t()}[e.operator](f.evalAst(e.left,t),(()=>f.evalAst(e.right,t)))),evalCompound(e,t){let n;for(let r=0;r<e.body.length;r++){"Identifier"===e.body[r].type&&["var","let","const"].includes(e.body[r].name)&&e.body[r+1]&&"AssignmentExpression"===e.body[r+1].type&&(r+=1);const i=e.body[r];n=f.evalAst(i,t)}return n},evalConditionalExpression:(e,t)=>f.evalAst(e.test,t)?f.evalAst(e.consequent,t):f.evalAst(e.alternate,t),evalIdentifier(e,t){if(Object.hasOwn(t,e.name))return t[e.name];throw ReferenceError(`${e.name} is not defined`)},evalLiteral:e=>e.value,evalMemberExpression(e,t){const n=String(e.computed?f.evalAst(e.property):e.property.name),r=f.evalAst(e.object,t);if(null==r)throw TypeError(`Cannot read properties of ${r} (reading '${n}')`);if(!Object.hasOwn(r,n)&&h.has(n))throw TypeError(`Cannot read properties of ${r} (reading '${n}')`);const i=r[n];return"function"==typeof i?i.bind(r):i},evalUnaryExpression:(e,t)=>({"-":e=>-f.evalAst(e,t),"!":e=>!f.evalAst(e,t),"~":e=>~f.evalAst(e,t),"+":e=>+f.evalAst(e,t),typeof:e=>typeof f.evalAst(e,t)}[e.operator](e.argument)),evalArrayExpression:(e,t)=>e.elements.map((e=>f.evalAst(e,t))),evalCallExpression(e,t){const n=e.arguments.map((e=>f.evalAst(e,t)));return f.evalAst(e.callee,t)(...n)},evalAssignmentExpression(e,t){if("Identifier"!==e.left.type)throw SyntaxError("Invalid left-hand side in assignment");const n=e.left.name,r=f.evalAst(e.right,t);return t[n]=r,t[n]}};function d(e,t){return(e=e.slice()).push(t),e}function p(e,t){return(t=t.slice()).unshift(e),t}class g extends Error{constructor(e){super('JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'),this.avoidNew=!0,this.value=e,this.name="NewError"}}function m(e,t,n,r,i){if(!(this instanceof m))try{return new m(e,t,n,r,i)}catch(e){if(!e.avoidNew)throw e;return e.value}"string"==typeof e&&(i=r,r=n,n=t,t=e,e=null);const o=e&&"object"==typeof e;if(e=e||{},this.json=e.json||n,this.path=e.path||t,this.resultType=e.resultType||"value",this.flatten=e.flatten||!1,this.wrap=!Object.hasOwn(e,"wrap")||e.wrap,this.sandbox=e.sandbox||{},this.eval=void 0===e.eval?"safe":e.eval,this.ignoreEvalErrors=void 0!==e.ignoreEvalErrors&&e.ignoreEvalErrors,this.parent=e.parent||null,this.parentProperty=e.parentProperty||null,this.callback=e.callback||r||null,this.otherTypeCallback=e.otherTypeCallback||i||function(){throw new TypeError("You must supply an otherTypeCallback callback option with the @other() operator.")},!1!==e.autostart){const r={path:o?e.path:t};o?"json"in e&&(r.json=e.json):r.json=n;const i=this.evaluate(r);if(!i||"object"!=typeof i)throw new g(i);return i}}m.prototype.evaluate=function(e,t,n,r){let i=this.parent,o=this.parentProperty,{flatten:s,wrap:a}=this;if(this.currResultType=this.resultType,this.currEval=this.eval,this.currSandbox=this.sandbox,n=n||this.callback,this.currOtherTypeCallback=r||this.otherTypeCallback,t=t||this.json,(e=e||this.path)&&"object"==typeof e&&!Array.isArray(e)){if(!e.path&&""!==e.path)throw new TypeError('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');if(!Object.hasOwn(e,"json"))throw new TypeError('You must supply a "json" property when providing an object argument to JSONPath.evaluate().');({json:t}=e),s=Object.hasOwn(e,"flatten")?e.flatten:s,this.currResultType=Object.hasOwn(e,"resultType")?e.resultType:this.currResultType,this.currSandbox=Object.hasOwn(e,"sandbox")?e.sandbox:this.currSandbox,a=Object.hasOwn(e,"wrap")?e.wrap:a,this.currEval=Object.hasOwn(e,"eval")?e.eval:this.currEval,n=Object.hasOwn(e,"callback")?e.callback:n,this.currOtherTypeCallback=Object.hasOwn(e,"otherTypeCallback")?e.otherTypeCallback:this.currOtherTypeCallback,i=Object.hasOwn(e,"parent")?e.parent:i,o=Object.hasOwn(e,"parentProperty")?e.parentProperty:o,e=e.path}if(i=i||null,o=o||null,Array.isArray(e)&&(e=m.toPathString(e)),!e&&""!==e||!t)return;const c=m.toPathArray(e);"$"===c[0]&&c.length>1&&c.shift(),this._hasParentSelector=null;const l=this._trace(c,t,["$"],i,o,n).filter((function(e){return e&&!e.isParentSelector}));return l.length?a||1!==l.length||l[0].hasArrExpr?l.reduce(((e,t)=>{const n=this._getPreferredOutput(t);return s&&Array.isArray(n)?e=e.concat(n):e.push(n),e}),[]):this._getPreferredOutput(l[0]):a?[]:void 0},m.prototype._getPreferredOutput=function(e){const t=this.currResultType;switch(t){case"all":{const t=Array.isArray(e.path)?e.path:m.toPathArray(e.path);return e.pointer=m.toPointer(t),e.path="string"==typeof e.path?e.path:m.toPathString(e.path),e}case"value":case"parent":case"parentProperty":return e[t];case"path":return m.toPathString(e[t]);case"pointer":return m.toPointer(e.path);default:throw new TypeError("Unknown result type")}},m.prototype._handleCallback=function(e,t,n){if(t){const r=this._getPreferredOutput(e);e.path="string"==typeof e.path?e.path:m.toPathString(e.path),t(r,n,e)}},m.prototype._trace=function(e,t,n,r,i,o,s,a){let c;if(!e.length)return c={path:n,value:t,parent:r,parentProperty:i,hasArrExpr:s},this._handleCallback(c,o,"value"),c;const l=e[0],u=e.slice(1),h=[];function f(e){Array.isArray(e)?e.forEach((e=>{h.push(e)})):h.push(e)}if(("string"!=typeof l||a)&&t&&Object.hasOwn(t,l))f(this._trace(u,t[l],d(n,l),t,l,o,s));else if("*"===l)this._walk(t,(e=>{f(this._trace(u,t[e],d(n,e),t,e,o,!0,!0))}));else if(".."===l)f(this._trace(u,t,n,r,i,o,s)),this._walk(t,(r=>{"object"==typeof t[r]&&f(this._trace(e.slice(),t[r],d(n,r),t,r,o,!0))}));else{if("^"===l)return this._hasParentSelector=!0,{path:n.slice(0,-1),expr:u,isParentSelector:!0};if("~"===l)return c={path:d(n,l),value:i,parent:r,parentProperty:null},this._handleCallback(c,o,"property"),c;if("$"===l)f(this._trace(u,t,n,null,null,o,s));else if(/^(-?\d*):(-?\d*):?(\d*)$/u.test(l))f(this._slice(l,u,t,n,r,i,o));else if(0===l.indexOf("?(")){if(!1===this.currEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");const e=l.replace(/^\?\((.*?)\)$/u,"$1"),s=/@.?([^?]*)[['](\??\(.*?\))(?!.\)\])[\]']/gu.exec(e);s?this._walk(t,(e=>{const a=[s[2]],c=s[1]?t[e][s[1]]:t[e];this._trace(a,c,n,r,i,o,!0).length>0&&f(this._trace(u,t[e],d(n,e),t,e,o,!0))})):this._walk(t,(s=>{this._eval(e,t[s],s,n,r,i)&&f(this._trace(u,t[s],d(n,s),t,s,o,!0))}))}else if("("===l[0]){if(!1===this.currEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");f(this._trace(p(this._eval(l,t,n.at(-1),n.slice(0,-1),r,i),u),t,n,r,i,o,s))}else if("@"===l[0]){let e=!1;const s=l.slice(1,-2);switch(s){case"scalar":t&&["object","function"].includes(typeof t)||(e=!0);break;case"boolean":case"string":case"undefined":case"function":typeof t===s&&(e=!0);break;case"integer":!Number.isFinite(t)||t%1||(e=!0);break;case"number":Number.isFinite(t)&&(e=!0);break;case"nonFinite":"number"!=typeof t||Number.isFinite(t)||(e=!0);break;case"object":t&&typeof t===s&&(e=!0);break;case"array":Array.isArray(t)&&(e=!0);break;case"other":e=this.currOtherTypeCallback(t,n,r,i);break;case"null":null===t&&(e=!0);break;default:throw new TypeError("Unknown value type "+s)}if(e)return c={path:n,value:t,parent:r,parentProperty:i},this._handleCallback(c,o,"value"),c}else if("`"===l[0]&&t&&Object.hasOwn(t,l.slice(1))){const e=l.slice(1);f(this._trace(u,t[e],d(n,e),t,e,o,s,!0))}else if(l.includes(",")){const e=l.split(",");for(const s of e)f(this._trace(p(s,u),t,n,r,i,o,!0))}else!a&&t&&Object.hasOwn(t,l)&&f(this._trace(u,t[l],d(n,l),t,l,o,s,!0))}if(this._hasParentSelector)for(let e=0;e<h.length;e++){const n=h[e];if(n&&n.isParentSelector){const a=this._trace(n.expr,t,n.path,r,i,o,s);if(Array.isArray(a)){h[e]=a[0];const t=a.length;for(let n=1;n<t;n++)e++,h.splice(e,0,a[n])}else h[e]=a}}return h},m.prototype._walk=function(e,t){if(Array.isArray(e)){const n=e.length;for(let e=0;e<n;e++)t(e)}else e&&"object"==typeof e&&Object.keys(e).forEach((e=>{t(e)}))},m.prototype._slice=function(e,t,n,r,i,o,s){if(!Array.isArray(n))return;const a=n.length,c=e.split(":"),l=c[2]&&Number.parseInt(c[2])||1;let u=c[0]&&Number.parseInt(c[0])||0,h=c[1]&&Number.parseInt(c[1])||a;u=u<0?Math.max(0,u+a):Math.min(a,u),h=h<0?Math.max(0,h+a):Math.min(a,h);const f=[];for(let e=u;e<h;e+=l){this._trace(p(e,t),n,r,i,o,s,!0).forEach((e=>{f.push(e)}))}return f},m.prototype._eval=function(e,t,n,r,i,o){this.currSandbox._$_parentProperty=o,this.currSandbox._$_parent=i,this.currSandbox._$_property=n,this.currSandbox._$_root=this.json,this.currSandbox._$_v=t;const s=e.includes("@path");s&&(this.currSandbox._$_path=m.toPathString(r.concat([n])));const a=this.currEval+"Script:"+e;if(!m.cache[a]){let t=e.replaceAll("@parentProperty","_$_parentProperty").replaceAll("@parent","_$_parent").replaceAll("@property","_$_property").replaceAll("@root","_$_root").replaceAll(/@([.\s)[])/gu,"_$_v$1");if(s&&(t=t.replaceAll("@path","_$_path")),"safe"===this.currEval||!0===this.currEval||void 0===this.currEval)m.cache[a]=new this.safeVm.Script(t);else if("native"===this.currEval)m.cache[a]=new this.vm.Script(t);else if("function"==typeof this.currEval&&this.currEval.prototype&&Object.hasOwn(this.currEval.prototype,"runInNewContext")){const e=this.currEval;m.cache[a]=new e(t)}else{if("function"!=typeof this.currEval)throw new TypeError(`Unknown "eval" property "${this.currEval}"`);m.cache[a]={runInNewContext:e=>this.currEval(t,e)}}}try{return m.cache[a].runInNewContext(this.currSandbox)}catch(t){if(this.ignoreEvalErrors)return!1;throw new Error("jsonPath: "+t.message+": "+e)}},m.cache={},m.toPathString=function(e){const t=e,n=t.length;let r="$";for(let e=1;e<n;e++)/^(~|\^|@.*?\(\))$/u.test(t[e])||(r+=/^[0-9*]+$/u.test(t[e])?"["+t[e]+"]":"['"+t[e]+"']");return r},m.toPointer=function(e){const t=e,n=t.length;let r="";for(let e=1;e<n;e++)/^(~|\^|@.*?\(\))$/u.test(t[e])||(r+="/"+t[e].toString().replaceAll("~","~0").replaceAll("/","~1"));return r},m.toPathArray=function(e){const{cache:t}=m;if(t[e])return t[e].concat();const n=[],r=e.replaceAll(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/gu,";$&;").replaceAll(/[['](\??\(.*?\))[\]'](?!.\])/gu,(function(e,t){return"[#"+(n.push(t)-1)+"]"})).replaceAll(/\[['"]([^'\]]*)['"]\]/gu,(function(e,t){return"['"+t.replaceAll(".","%@%").replaceAll("~","%%@@%%")+"']"})).replaceAll("~",";~;").replaceAll(/['"]?\.['"]?(?![^[]*\])|\[['"]?/gu,";").replaceAll("%@%",".").replaceAll("%%@@%%","~").replaceAll(/(?:;)?(\^+)(?:;)?/gu,(function(e,t){return";"+t.split("").join(";")+";"})).replaceAll(/;;;|;;/gu,";..;").replaceAll(/;$|'?\]|'$/gu,"").split(";").map((function(e){const t=e.match(/#(\d+)/u);return t&&t[1]?n[t[1]]:e}));return t[e]=r,t[e].concat()},m.prototype.safeVm={Script:class{constructor(e){this.code=e,this.ast=s(this.code)}runInNewContext(e){const t=Object.assign(Object.create(null),e);return f.evalAst(this.ast,t)}}};async function y(e,t){if(null==e.username||null==e.apikey)throw Error("Syncing words is only supported for premium users");try{return v("$.added@boolean()",(await b({url:E(`${e.serverUrl}/v2/words/add`,{username:e.username,apiKey:e.apikey,word:t}).href,method:"POST"})).json)}catch(e){throw new Error(`Adding words failed\n${e}`)}}async function k(e,t){if(null==e.username||null==e.apikey)throw Error("Syncing words is only supported for premium users");try{return v("$.deleted@boolean()",(await b({url:E(`${e.serverUrl}/v2/words/delete`,{username:e.username,apiKey:e.apikey,word:t}).href,method:"POST"})).json)}catch(e){throw new Error(`Deleting words failed\n${e}`)}}m.prototype.vm={Script:class{constructor(e){this.code=e}runInNewContext(e){let t=this.code;const n=Object.keys(e),r=[];!function(e,t,n){const r=e.length;for(let i=0;i<r;i++)n(e[i])&&t.push(e.splice(i--,1)[0])}(n,r,(t=>"function"==typeof e[t]));const i=n.map((t=>e[t]));t=r.reduce(((t,n)=>{let r=e[n].toString();return/function/u.test(r)||(r="function "+r),"var "+n+"="+r+";"+t}),"")+t,/(['"])use strict\1/u.test(t)||n.includes("arguments")||(t="var arguments = undefined;"+t),t=t.replace(/;\s*$/u,"");const o=t.lastIndexOf(";"),s=-1!==o?t.slice(0,o+1)+" return "+t.slice(o+1):" return "+t;return new Function(...n,s)(...i)}}};const x={en:new class{url="https://qb-grammar-en.languagetool.org/phrasal-paraphraser/subscribe";async query(e,t){const n={message:{indices:[e.slice(0,t.from).split(/\s+/).length],mode:0,phrases:[e.slice(t.from,t.to)],text:e},meta:{clientStatus:"string",product:"string",traceID:"string",userID:"string"},response_queue:"string"};try{return w("$.data.suggestions[*][*]@string()",(await b({url:this.url,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})).json)}catch(e){throw new Error(`Requesting synonyms failed\n${e}`)}}},de:new class{url="https://synonyms.languagetool.org/synonyms/de";async query(e,t){const n=e.slice(t.from,t.to).trim(),r=e.slice(0,t.from).split(/\s+/).join("+"),i=e.slice(t.to).split(/\s+/).join("+");try{return w("$.synsets[*].terms[*].term@string()",(await b({url:E(`${this.url}/${n}`,{before:r,after:i}).href,method:"GET"})).json)}catch(e){throw new Error(`Requesting synonyms failed\n${e}`)}}}};async function b(t){let n;try{n=await e.requestUrl({...t,throw:!1})}catch(e){throw new Error(`Request to LanguageTool failed: Please check your connection and server URL.\n${e}`)}if(504===n.status||503===n.status)throw new Error("Request to LanguageTool timed out. Please try again later.");if(200!==n.status){let e=n.text;throw e.length>310&&(e=e.substring(0,300)+"..."),new Error(`Request to LanguageTool failed ${n.status}:\n${e}`)}return n}function v(e,t){const n=m({path:e,json:t,wrap:!1,eval:!1});if(null==n)throw new Error("Error parsing response.");return n}function w(e,t){const n=m({path:e,json:t,wrap:!0,eval:!1});if(null==n||!(n instanceof Array))throw new Error("Error parsing response.");return n}function E(e,t){const n=new URL(e);return n.search=new URLSearchParams(t).toString(),n}function S(e){switch(e){case"COLLOQUIALISMS":case"REDUNDANCY":case"STYLE":case"SYNONYMS":return"lt-style";case"TYPOS":return"lt-major";default:return"lt-minor"}}function C(e,t){const n=new Set(e);for(const e of t)n.delete(e);return n}function _(e,t){return(e=e.toLowerCase())>(t=t.toLowerCase())?1:e<t?-1:0}class A{url;requestsPerSec;maxSize;constructor(e,t,n){this.url=e,this.requestsPerSec=t,this.maxSize=n}get minDelay(){return 60/this.requestsPerSec*1e3}}const I={standard:new A("https://api.languagetool.org",20,2e4),premium:new A("https://api.languagetoolplus.com",80,75e3),custom:new A("",120,1e6)};function T(e){for(const[t,n]of Object.entries(I))if(n.url===e)return t;return"custom"}const O={serverUrl:I.standard.url,autoCheckDelay:I.standard.minDelay,shouldAutoCheck:!1,languageVariety:{en:"en-US",de:"de-DE",pt:"pt-PT",ca:"ca-ES"},dictionary:[],syncDictionary:!1,remoteDictionary:[],pickyMode:!1};function D(e,t){return e=e.filter((e=>e.code===t)).filter((e=>e.longCode!==e.code)),Object.fromEntries(e.map((e=>[e.longCode,e.name])))}class L extends e.PluginSettingTab{plugin;endpointListeners=[];languageListeners=[];languages=[];constructor(e,t){super(e,t),this.plugin=t}configureCheckDelay(e,t){const n=I[t].minDelay;this.plugin.settings.autoCheckDelay=Math.clamp(this.plugin.settings.autoCheckDelay,n,5e3),e.setLimits(n,5e3,250)}async notifyEndpointChange(e){for(const t of this.endpointListeners)await t(e.serverUrl)}async configureLanguageVariants(e,t){const n=this.plugin.settings.languageVariety,r=D(this.languages,t);n[t]=n[t]??Object.keys(r)[0],e.addOptions(r).setValue(n[t]).onChange((async e=>{n[t]=e,await this.plugin.saveSettings()})),this.languageListeners.push((async r=>{for(;e.selectEl.options.length>0;)e.selectEl.remove(0);const i=D(r,t);n[t]=n[t]??Object.keys(i)[0],e.addOptions(i).setValue(n[t])}))}async display(){const{containerEl:t}=this;t.empty();const n=this.plugin.settings;this.endpointListeners=[],this.endpointListeners.push((async t=>{let n=[];t&&(n=await async function(t){const n=await e.requestUrl({url:`${t}/v2/languages`}).json;if(null==n||!(n instanceof Array))throw new Error("Error processing response from LanguageTool.");return n}(t)),this.languages=n;for(const e of this.languageListeners)await e(n)})),this.endpointListeners.push((async e=>{await this.plugin.syncDictionary()})),this.languageListeners=[],new e.Setting(t).setName("Error logs").setDesc(`${this.plugin.logs.length} messages`).addButton((t=>{t.setButtonText("Copy to clipboard").onClick((async()=>{await window.navigator.clipboard.writeText(this.plugin.logs.join("\n")),new e.Notice("Logs copied to clipboard")}))}));let r=T(n.serverUrl),i=null;function o(e){if(e.appendText("Enables the context menu for synonyms fetched from"),e.createEl("br"),null!=n.synonyms){const t=x[n.synonyms];if(!t)return void e.appendText(" (unknown API)");e.createEl("a",{text:t.url,href:t.url,attr:{target:"_blank"}})}else e.appendText("(none)")}new e.Setting(t).setName("Endpoint").setDesc("Choose the LanguageTool server url").then((e=>{e.controlEl.classList.add("lt-settings-grid");let t=null,o=null;e.addDropdown((e=>{t=e,e.addOptions({standard:"(Standard) api.languagetool.org",premium:"(Premium) api.languagetoolplus.com",custom:"Custom URL"}).setValue(r).onChange((async e=>{r=e,n.serverUrl=I[r].url,o&&o.setValue(n.serverUrl).setDisabled("custom"!==e),i&&this.configureCheckDelay(i,r),await this.notifyEndpointChange(n),await this.plugin.saveSettings()}))})),e.addText((e=>{o=e,e.setPlaceholder("https://your-custom-url.com").setValue(n.serverUrl).setDisabled("custom"!==r).onChange((async e=>{n.serverUrl=e.replace(/\/v2\/check\/$/,"").replace(/\/$/,""),r=T(n.serverUrl),"custom"!==r&&(t?.setValue(r),o?.setDisabled(!0)),await this.notifyEndpointChange(n),await this.plugin.saveSettings()}))}))})),new e.Setting(t).setName("API username").setDesc("Enter a username/mail for API access").addText((e=>e.setPlaceholder("peterlustig@example.com").setValue(n.username||"").onChange((async e=>{n.username=e.replace(/\s+/g,""),await this.plugin.saveSettings()})))),new e.Setting(t).setName("API key").setDesc(createFragment((e=>{e.createEl("a",{text:"Click here for information about Premium Access",href:"https://github.com/wrenger/obsidian-languagetool#premium-accounts",attr:{target:"_blank"}})}))).addText((t=>t.setValue(n.apikey||"").onChange((async t=>{n.apikey=t.replace(/\s+/g,""),n.apikey&&"premium"!==r&&new e.Notice("You have entered an API Key but you are not using the Premium Endpoint"),await this.plugin.saveSettings()})))),new e.Setting(t).setName("Auto check text").setDesc("Check text as you type").addToggle((e=>{e.setValue(n.shouldAutoCheck).onChange((async e=>{n.shouldAutoCheck=e,await this.plugin.saveSettings()}))})),new e.Setting(t).setName("Auto check delay (ms)").setDesc("Time to wait for autocheck after the last key press").addSlider((e=>{i=e,this.configureCheckDelay(e,r),e.setValue(n.autoCheckDelay).onChange((async e=>{n.autoCheckDelay=e,await this.plugin.saveSettings()})).setDynamicTooltip()}));const s=new e.Setting(t).setName("Find synonyms").setDesc(createFragment(o));s.addDropdown((e=>{e.addOption("none","---");for(const t of Object.keys(x))e.addOption(t,t);e.setValue(n.synonyms??"none").onChange((async e=>{n.synonyms="none"!==e?e:void 0,await this.plugin.saveSettings(),s.setDesc(createFragment(o))}))})),new e.Setting(t).setName("Language settings").setHeading(),new e.Setting(t).setName("Mother tongue").setDesc("Set mother tongue if you want to be warned about false friends when writing in other languages. This setting will also be used for automatic language detection.").addDropdown((e=>{this.languageListeners.push((async t=>{for(;e.selectEl.options.length>0;)e.selectEl.remove(0);e.addOption("none","---").addOptions(Object.fromEntries(t.filter((e=>e.longCode==e.code)).map((e=>[e.longCode,e.name])))).setValue(n.motherTongue??"none").onChange((async e=>{n.motherTongue="none"!==e?e:void 0,await this.plugin.saveSettings()}))}))})),new e.Setting(t).setName("Static language").setDesc("Set a static language that will always be used (LanguageTool tries to auto detect the language, this is usually not necessary)").addDropdown((e=>{this.languageListeners.push((async t=>{const r=t.filter((e=>e.longCode.length>2||e.longCode!==e.code||t.filter((t=>t.code==e.code)).length<=1));for(;e.selectEl.options.length>0;)e.selectEl.remove(0);e.addOption("auto","Auto Detect").addOptions(Object.fromEntries(r.map((e=>[e.longCode,e.name])))).setValue(n.staticLanguage??"auto").onChange((async e=>{n.staticLanguage="auto"!==e?e:void 0,await this.plugin.saveSettings()}))}))})),new e.Setting(t).setName("Language varieties").setHeading().setDesc("Some languages have varieties depending on the country they are spoken in.");const a={en:"English",de:"German",pt:"Portuguese",ca:"Catalan"};for(const[n,r]of Object.entries(a))new e.Setting(t).setName(`Interpret ${r} as`).addDropdown((async e=>{this.configureLanguageVariants(e,n)}));new e.Setting(t).setName("Spellcheck Dictionary").setHeading(),new e.Setting(t).setName("Ignored Words").setDesc("Words that should not be highlighted as spelling mistakes.").addButton((e=>{e.setIcon("settings").setTooltip("Edit dictionary").onClick((()=>{new P(this.app,this.plugin).open()}))})),new e.Setting(t).setName("Sync with LanguageTool").setDesc("This is only supported for premium users.").addToggle((e=>{e.setDisabled("premium"!==r).setValue(n.syncDictionary).onChange((async e=>{n.syncDictionary=e,await this.plugin.syncDictionary()})),this.endpointListeners.push((async t=>{e.setDisabled("premium"!==T(t))}))})),new e.Setting(t).setName("Rule categories").setHeading().setDesc(createFragment((e=>{e.appendText("The picky mode enables a lot of extra categories and rules. Additionally, you can enable or disable specific rules down below."),e.createEl("br"),e.createEl("a",{text:"Click here for a list of rules and categories",href:"https://community.languagetool.org/rule/list",attr:{target:"_blank"}})}))),new e.Setting(t).setName("Picky mode").setDesc("Provides more style and tonality suggestions, detects long or complex sentences, recognizes colloquialism and redundancies, proactively suggests synonyms for commonly overused words").addToggle((e=>{e.setValue(n.pickyMode).onChange((async e=>{n.pickyMode=e,await this.plugin.saveSettings()}))})),new e.Setting(t).setName("Enabled categories").setDesc("Comma-separated list of categories").addText((e=>e.setPlaceholder("CATEGORY_1,CATEGORY_2").setValue(n.enabledCategories??"").onChange((async e=>{n.enabledCategories=e.replace(/\s+/g,""),await this.plugin.saveSettings()})))),new e.Setting(t).setName("Disabled categories").setDesc("Comma-separated list of categories").addText((e=>e.setPlaceholder("CATEGORY_1,CATEGORY_2").setValue(n.disabledCategories??"").onChange((async e=>{n.disabledCategories=e.replace(/\s+/g,""),await this.plugin.saveSettings()})))),new e.Setting(t).setName("Enabled rules").setDesc("Comma-separated list of rules").addText((e=>e.setPlaceholder("RULE_1,RULE_2").setValue(n.enabledRules??"").onChange((async e=>{n.enabledRules=e.replace(/\s+/g,""),await this.plugin.saveSettings()})))),new e.Setting(t).setName("Disabled rules").setDesc("Comma-separated list of rules").addText((e=>e.setPlaceholder("RULE_1,RULE_2").setValue(n.disabledRules??"").onChange((async e=>{n.disabledRules=e.replace(/\s+/g,""),await this.plugin.saveSettings()})))),await this.notifyEndpointChange(n)}}class P extends e.Modal{plugin;words;constructor(e,t){super(e),this.setTitle("Spellcheck dictionary"),this.plugin=t,this.words=t.settings.dictionary}async onOpen(){this.words=this.plugin.settings.dictionary;const{contentEl:t}=this,n=t=>{t.replaceChildren(...this.words.map((r=>t.createDiv({cls:"multi-select-pill"},(i=>{i.createDiv({cls:"multi-select-pill-content"},(e=>e.createSpan({text:r}))),i.createDiv({cls:"multi-select-pill-remove-button"},(i=>{i.appendChild(e.getIcon("x")),i.onClickEvent((()=>{this.words.remove(r),n(t)}))}))})))))};let r=null;t.createDiv({cls:"multi-select-container"},(e=>{r=e,n(e)})),this.plugin.syncDictionary().then((e=>{e&&(this.words=this.plugin.settings.dictionary,r&&n(r))}));let i="",o=null;const s=()=>{i&&(this.words=[...new Set([...this.words,i])].sort(_),r&&n(r),o&&o.setValue(""),i="")};new e.Setting(t).setName("Add").addText((e=>{o=e.setValue(i).onChange((e=>i=e.trim())),e.inputEl.addEventListener("keypress",(e=>{"Enter"===e.key&&s()}))})).addExtraButton((e=>{e.setIcon("plus").setTooltip("Add").onClick((()=>{s()}))}))}async onClose(){this.contentEl.empty(),this.plugin.settings.dictionary=this.words,await this.plugin.syncDictionary()}}function M(e){let n=-1,r=1/0,i=-1/0;return t.EditorView.updateListener.of((t=>{let o=e.getActiveFileSettings();if(!t.docChanged||!o.shouldAutoCheck)return;t.changes.iterChangedRanges(((e,t,n,o)=>{r=Math.min(r,n,o),i=Math.max(i,n,o)}));const s=t.view;clearTimeout(n),n=window.setTimeout((()=>{e.runDetection(s,{from:r,to:i}).catch((e=>{console.error(e)})),r=1/0,i=-1/0}),e.settings.autoCheckDelay)}))}const R=/(frontmatter|code|math|templater|blockid|hashtag)/,F=n.StateEffect.define(),N=n.StateEffect.define(),z=n.StateEffect.define(),j=n.StateEffect.define();function B(e,t){return e.from<=t.from&&t.from<=e.to||e.from<=t.to&&t.to<=e.to||t.from<=e.from&&e.from<=t.to||t.from<=e.to&&e.to<=t.to}const $=n.StateField.define({create:()=>t.Decoration.none,update(e,n){e=e.map(n.changes);const i=new Set,o={};let s=null;const a=e=>{if(null==o[e]){s||(s=r.syntaxTree(n.state));const t=s.resolveInner(e,1).type.prop(r.tokenClassNodeProp);o[e]=!(t&&R.test(t))}return o[e]},c=(e,t)=>{s||(s=r.syntaxTree(n.state));const i=s.resolve(n.newDoc.lineAt(t.from).from,1).type.prop(r.tokenClassNodeProp);return!i?.includes("table")||"WHITESPACE_RULE"!==e.ruleId};n.docChanged&&n.selection&&e.size&&(e=e.update({filter:(e,t)=>!B({from:e,to:t},n.selection.main)}));for(const r of n.effects)if(r.is(F)){const n=r.value,o=n.range,s=`${o.from},${o.to}`;!i.has(s)&&a(o.from)&&a(o.to)&&c(n,o)&&(i.add(s),e=e.update({add:[t.Decoration.mark({class:`lt-underline ${S(n.categoryId)}`,underline:n}).range(o.from,o.to)]}))}else r.is(N)?e=t.Decoration.none:r.is(z)?e=e.update({filterFrom:r.value.from,filterTo:r.value.to,filter:(e,t)=>!B({from:e,to:t},r.value)}):r.is(j)&&(e=e.update({filter:(e,t,n)=>!r.value(n.spec.underline)}));return e},provide:e=>t.EditorView.decorations.from(e)});function U(t,n,r,i){const o=r.replacements.slice(0,4),s=r.categoryId,a=r.ruleId;return createDiv({cls:["lt-tooltip",S(s)]},(c=>{r.title&&c.createSpan({cls:"lt-title",text:r.title}),r.message&&c.createSpan({cls:"lt-message",text:r.message}),c.createDiv({cls:"lt-bottom"},(t=>{t.createDiv({cls:"lt-buttoncontainer"},(t=>{for(const r of o){const o=new e.ButtonComponent(t);o.setButtonText(r||"(delete)"),o.onClick((()=>{n.dispatch({changes:[{...i,insert:r}],effects:[z.of(i)]})}))}}))})),c.createDiv({cls:"lt-ignore-container"},(o=>{"TYPOS"===s?o.createEl("button",{cls:"lt-ignore-btn"},(i=>{e.setIcon(i.createSpan(),"plus-with-circle"),i.createSpan({text:"Add to dictionary"}),i.onclick=async()=>{t.settings.dictionary.push(r.text),await t.syncDictionary(),n.dispatch({effects:[j.of((e=>e.text==e.text))]})}})):(o.createDiv({cls:"lt-ignore-btn"},(t=>{e.setIcon(t.createSpan(),"cross"),t.createSpan({text:"Ignore"}),t.onclick=()=>n.dispatch({effects:[z.of(i)]})})),"SYNONYMS"!==s&&o.createDiv({cls:"lt-ignore-btn"},(r=>{e.setIcon(r.createSpan(),"circle-off"),r.createSpan({text:"Disable rule"}),r.onclick=()=>{t.settings.disabledRules?t.settings.disabledRules+=","+a:t.settings.disabledRules=a,t.saveSettings(),n.dispatch({effects:[j.of((e=>e.ruleId===a))]})}}))),o.createDiv({cls:"lt-info-container"},(t=>{t.createDiv({cls:"lt-info-button clickable-icon"},(t=>{e.setIcon(t,"info"),t.onclick=()=>{const e=document.getElementsByClassName("lt-info-box").item(0);e&&e.toggleAttribute("hidden")}}))}))})),c.createDiv({cls:"lt-info-box",attr:{hidden:!0}},(e=>{e.createDiv({cls:"lt-info",text:`Category: ${s}`}),e.createDiv({cls:"lt-info",text:`Rule: ${a}`}),e.createDiv({cls:"lt-info",text:`Text: ${r.text} (${i.from}-${i.to})`})}))}))}function V(e,t,n,r){const i=t.state,o=i.field($);if(0===o.size||i.selection.ranges.length>1)return null;let s=o.iter(n);if(null!=s.value&&s.from<=n&&s.to>=n){let t=s.value.spec.underline;return console.log(s),{pos:s.from,end:s.to,above:!0,strictSide:!1,arrow:!1,clip:!1,create:n=>({dom:U(e,n,t,s)})}}return null}function H(e){return t.hoverTooltip(V.bind(null,e),{hideOnChange:!0})}const q=t.EditorView.baseTheme({".cm-tooltip.cm-tooltip-hover":{padding:"var(--size-2-3)",border:"1px solid var(--background-modifier-border-hover)",backgroundColor:"var(--background-secondary)",borderRadius:"var(--radius-m)",boxShadow:"var(--shadow-s)",zIndex:"var(--layer-menu)",userSelect:"none",overflow:"hidden","& > .lt-tooltip":{fontFamily:"var(--default-font)",fontSize:"var(--font-ui-small)",width:"300px",lineHeight:1.5,"& > .lt-title":{display:"block",fontWeight:600,marginBottom:"6px",padding:"0 12px",textDecoration:"underline 2px var(--lt-highlight)","-webkit-text-decoration":"underline 2px var(--lt-highlight)"},"& > .lt-message":{display:"block",padding:"0 12px"},"& > .lt-bottom":{minHeight:"10px",padding:"0 12px",position:"relative","& > .lt-buttoncontainer":{"&:not(:empty)":{paddingTop:"10px"},"& > button":{marginRight:"4px",marginBottom:"4px",padding:"4px 6px"}}},"& > .lt-ignore-container":{display:"flex","& > .lt-ignore-btn":{fontSize:"var(--font-ui-small)",padding:"4px",display:"flex",flex:1,width:"100%",textAlign:"left",alignItems:"center",lineHeight:1,color:"var(--text-muted)","& > span":{display:"flex","&:last-child":{marginLeft:"5px"}},"&:hover":{color:"var(--text-normal)"}},"& > .lt-info-container":{display:"flex",flex:0,"& > .lt-info-button":{color:"var(--text-faint)",height:"100%"}}},"& > .lt-info-box":{padding:"5px 0px 0px 0px",overflowX:"scroll",color:"var(--text-muted)"}}},".lt-underline":{cursor:"pointer",transition:"background-color 100ms ease-out",textDecoration:"wavy underline var(--lt-highlight)","-webkit-text-decoration":"wavy underline var(--lt-highlight)","&:hover":{backgroundColor:"color-mix(in srgb, var(--lt-highlight), transparent 80%)"}}});const Y={};function Q(e,t,n){if(function(e){return Boolean(e&&"object"==typeof e)}(e)){if("value"in e)return"html"!==e.type||n?e.value:"";if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return K(e.children,t,n)}return Array.isArray(e)?K(e,t,n):""}function K(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=Q(e[i],t,n);return r.join("")}const W=document.createElement("i");function X(e){const t="&"+e+";";W.innerHTML=t;const n=W.textContent;return(59!==n.charCodeAt(n.length-1)||"semi"===e)&&(n!==t&&n)}function J(e,t,n,r){const i=e.length;let o,s=0;if(t=t<0?-t>i?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);s<r.length;)o=r.slice(s,s+1e4),o.unshift(t,0),e.splice(...o),s+=1e4,t+=1e4}function G(e,t){return e.length>0?(J(e,e.length,0,t),e):t}const Z={}.hasOwnProperty;function ee(e){const t={};let n=-1;for(;++n<e.length;)te(t,e[n]);return t}function te(e,t){let n;for(n in t){const r=(Z.call(e,n)?e[n]:void 0)||(e[n]={}),i=t[n];let o;if(i)for(o in i){Z.call(r,o)||(r[o]=[]);const e=i[o];ne(r[o],Array.isArray(e)?e:e?[e]:[])}}}function ne(e,t){let n=-1;const r=[];for(;++n<t.length;)("after"===t[n].add?e:r).push(t[n]);J(e,0,0,r)}function re(e,t){const n=Number.parseInt(e,t);return n<9||11===n||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||!(65535&~n)||65534==(65535&n)||n>1114111?"<22>":String.fromCodePoint(n)}function ie(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const oe=ye(/[A-Za-z]/),se=ye(/[\dA-Za-z]/),ae=ye(/[#-'*+\--9=?A-Z^-~]/);function ce(e){return null!==e&&(e<32||127===e)}const le=ye(/\d/),ue=ye(/[\dA-Fa-f]/),he=ye(/[!-/:-@[-`{-~]/);function fe(e){return null!==e&&e<-2}function de(e){return null!==e&&(e<0||32===e)}function pe(e){return-2===e||-1===e||32===e}const ge=ye(/\p{P}|\p{S}/u),me=ye(/\s/);function ye(e){return function(t){return null!==t&&t>-1&&e.test(String.fromCharCode(t))}}function ke(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let o=0;return function(r){if(pe(r))return e.enter(n),s(r);return t(r)};function s(r){return pe(r)&&o++<i?(e.consume(r),s):(e.exit(n),t(r))}}const xe={tokenize:function(e){const t=e.attempt(this.parser.constructs.contentInitial,(function(n){if(null===n)return void e.consume(n);return e.enter("lineEnding"),e.consume(n),e.exit("lineEnding"),ke(e,t,"linePrefix")}),(function(t){return e.enter("paragraph"),r(t)}));let n;return t;function r(t){const r=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=r),n=r,i(t)}function i(t){return null===t?(e.exit("chunkText"),e.exit("paragraph"),void e.consume(t)):fe(t)?(e.consume(t),e.exit("chunkText"),r):(e.consume(t),i)}}};const be={tokenize:function(e){const t=this,n=[];let r,i,o,s=0;return a;function a(r){if(s<n.length){const i=n[s];return t.containerState=i[1],e.attempt(i[0].continuation,c,l)(r)}return l(r)}function c(e){if(s++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,r&&k();const n=t.events.length;let i,o=n;for(;o--;)if("exit"===t.events[o][0]&&"chunkFlow"===t.events[o][1].type){i=t.events[o][1].end;break}y(s);let a=n;for(;a<t.events.length;)t.events[a][1].end={...i},a++;return J(t.events,o+1,0,t.events.slice(n)),t.events.length=a,l(e)}return a(e)}function l(i){if(s===n.length){if(!r)return f(i);if(r.currentConstruct&&r.currentConstruct.concrete)return p(i);t.interrupt=Boolean(r.currentConstruct&&!r._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(ve,u,h)(i)}function u(e){return r&&k(),y(s),f(e)}function h(e){return t.parser.lazy[t.now().line]=s!==n.length,o=t.now().offset,p(e)}function f(n){return t.containerState={},e.attempt(ve,d,p)(n)}function d(e){return s++,n.push([t.currentConstruct,t.containerState]),f(e)}function p(n){return null===n?(r&&k(),y(0),void e.consume(n)):(r=r||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:r,contentType:"flow",previous:i}),g(n))}function g(n){return null===n?(m(e.exit("chunkFlow"),!0),y(0),void e.consume(n)):fe(n)?(e.consume(n),m(e.exit("chunkFlow")),s=0,t.interrupt=void 0,a):(e.consume(n),g)}function m(e,n){const a=t.sliceStream(e);if(n&&a.push(null),e.previous=i,i&&(i.next=e),i=e,r.defineSkip(e.start),r.write(a),t.parser.lazy[e.start.line]){let e=r.events.length;for(;e--;)if(r.events[e][1].start.offset<o&&(!r.events[e][1].end||r.events[e][1].end.offset>o))return;const n=t.events.length;let i,a,c=n;for(;c--;)if("exit"===t.events[c][0]&&"chunkFlow"===t.events[c][1].type){if(i){a=t.events[c][1].end;break}i=!0}for(y(s),e=n;e<t.events.length;)t.events[e][1].end={...a},e++;J(t.events,c+1,0,t.events.slice(n)),t.events.length=e}}function y(r){let i=n.length;for(;i-- >r;){const r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function k(){r.write([null]),i=void 0,r=void 0,t.containerState._closeFlow=void 0}}},ve={tokenize:function(e,t,n){return ke(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}};function we(e){return null===e||de(e)||me(e)?1:ge(e)?2:void 0}function Ee(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const o=e[i].resolveAll;o&&!r.includes(o)&&(t=o(t,n),r.push(o))}return t}const Se={name:"attention",resolveAll:function(e,t){let n,r,i,o,s,a,c,l,u=-1;for(;++u<e.length;)if("enter"===e[u][0]&&"attentionSequence"===e[u][1].type&&e[u][1]._close)for(n=u;n--;)if("exit"===e[n][0]&&"attentionSequence"===e[n][1].type&&e[n][1]._open&&t.sliceSerialize(e[n][1]).charCodeAt(0)===t.sliceSerialize(e[u][1]).charCodeAt(0)){if((e[n][1]._close||e[u][1]._open)&&(e[u][1].end.offset-e[u][1].start.offset)%3&&!((e[n][1].end.offset-e[n][1].start.offset+e[u][1].end.offset-e[u][1].start.offset)%3))continue;a=e[n][1].end.offset-e[n][1].start.offset>1&&e[u][1].end.offset-e[u][1].start.offset>1?2:1;const h={...e[n][1].end},f={...e[u][1].start};Ce(h,-a),Ce(f,a),o={type:a>1?"strongSequence":"emphasisSequence",start:h,end:{...e[n][1].end}},s={type:a>1?"strongSequence":"emphasisSequence",start:{...e[u][1].start},end:f},i={type:a>1?"strongText":"emphasisText",start:{...e[n][1].end},end:{...e[u][1].start}},r={type:a>1?"strong":"emphasis",start:{...o.start},end:{...s.end}},e[n][1].end={...o.start},e[u][1].start={...s.end},c=[],e[n][1].end.offset-e[n][1].start.offset&&(c=G(c,[["enter",e[n][1],t],["exit",e[n][1],t]])),c=G(c,[["enter",r,t],["enter",o,t],["exit",o,t],["enter",i,t]]),c=G(c,Ee(t.parser.constructs.insideSpan.null,e.slice(n+1,u),t)),c=G(c,[["exit",i,t],["enter",s,t],["exit",s,t],["exit",r,t]]),e[u][1].end.offset-e[u][1].start.offset?(l=2,c=G(c,[["enter",e[u][1],t],["exit",e[u][1],t]])):l=0,J(e,n-1,u-n+3,c),u=n+c.length-l-2;break}u=-1;for(;++u<e.length;)"attentionSequence"===e[u][1].type&&(e[u][1].type="data");return e},tokenize:function(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=we(r);let o;return function(t){return o=t,e.enter("attentionSequence"),s(t)};function s(a){if(a===o)return e.consume(a),s;const c=e.exit("attentionSequence"),l=we(a),u=!l||2===l&&i||n.includes(a),h=!i||2===i&&l||n.includes(r);return c._open=Boolean(42===o?u:u&&(i||!h)),c._close=Boolean(42===o?h:h&&(l||!u)),t(a)}}};function Ce(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const _e={name:"autolink",tokenize:function(e,t,n){let r=0;return function(t){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(t),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),i};function i(t){return oe(t)?(e.consume(t),o):64===t?n(t):c(t)}function o(e){return 43===e||45===e||46===e||se(e)?(r=1,s(e)):c(e)}function s(t){return 58===t?(e.consume(t),r=0,a):(43===t||45===t||46===t||se(t))&&r++<32?(e.consume(t),s):(r=0,c(t))}function a(r){return 62===r?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(r),e.exit("autolinkMarker"),e.exit("autolink"),t):null===r||32===r||60===r||ce(r)?n(r):(e.consume(r),a)}function c(t){return 64===t?(e.consume(t),l):ae(t)?(e.consume(t),c):n(t)}function l(e){return se(e)?u(e):n(e)}function u(n){return 46===n?(e.consume(n),r=0,l):62===n?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(n),e.exit("autolinkMarker"),e.exit("autolink"),t):h(n)}function h(t){if((45===t||se(t))&&r++<63){const n=45===t?h:u;return e.consume(t),n}return n(t)}}};const Ae={partial:!0,tokenize:function(e,t,n){return function(t){return pe(t)?ke(e,r,"linePrefix")(t):r(t)};function r(e){return null===e||fe(e)?t(e):n(e)}}};const Ie={continuation:{tokenize:function(e,t,n){const r=this;return function(t){if(pe(t))return ke(e,i,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(t);return i(t)};function i(r){return e.attempt(Ie,t,n)(r)}}},exit:function(e){e.exit("blockQuote")},name:"blockQuote",tokenize:function(e,t,n){const r=this;return function(t){if(62===t){const n=r.containerState;return n.open||(e.enter("blockQuote",{_container:!0}),n.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(t),e.exit("blockQuoteMarker"),i}return n(t)};function i(n){return pe(n)?(e.enter("blockQuotePrefixWhitespace"),e.consume(n),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(n))}}};const Te={name:"characterEscape",tokenize:function(e,t,n){return function(t){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(t),e.exit("escapeMarker"),r};function r(r){return he(r)?(e.enter("characterEscapeValue"),e.consume(r),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(r)}}};const Oe={name:"characterReference",tokenize:function(e,t,n){const r=this;let i,o,s=0;return function(t){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(t),e.exit("characterReferenceMarker"),a};function a(t){return 35===t?(e.enter("characterReferenceMarkerNumeric"),e.consume(t),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),i=31,o=se,l(t))}function c(t){return 88===t||120===t?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(t),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),i=6,o=ue,l):(e.enter("characterReferenceValue"),i=7,o=le,l(t))}function l(a){if(59===a&&s){const i=e.exit("characterReferenceValue");return o!==se||X(r.sliceSerialize(i))?(e.enter("characterReferenceMarker"),e.consume(a),e.exit("characterReferenceMarker"),e.exit("characterReference"),t):n(a)}return o(a)&&s++<i?(e.consume(a),l):n(a)}}};const De={partial:!0,tokenize:function(e,t,n){const r=this;return function(t){if(null===t)return n(t);return e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),i};function i(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}},Le={concrete:!0,name:"codeFenced",tokenize:function(e,t,n){const r=this,i={partial:!0,tokenize:function(e,t,n){let i=0;return s;function s(t){return e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),c}function c(t){return e.enter("codeFencedFence"),pe(t)?ke(e,l,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(t):l(t)}function l(t){return t===o?(e.enter("codeFencedFenceSequence"),u(t)):n(t)}function u(t){return t===o?(i++,e.consume(t),u):i>=a?(e.exit("codeFencedFenceSequence"),pe(t)?ke(e,h,"whitespace")(t):h(t)):n(t)}function h(r){return null===r||fe(r)?(e.exit("codeFencedFence"),t(r)):n(r)}}};let o,s=0,a=0;return function(t){return function(t){const n=r.events[r.events.length-1];return s=n&&"linePrefix"===n[1].type?n[2].sliceSerialize(n[1],!0).length:0,o=t,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),c(t)}(t)};function c(t){return t===o?(a++,e.consume(t),c):a<3?n(t):(e.exit("codeFencedFenceSequence"),pe(t)?ke(e,l,"whitespace")(t):l(t))}function l(n){return null===n||fe(n)?(e.exit("codeFencedFence"),r.interrupt?t(n):e.check(De,d,k)(n)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),u(n))}function u(t){return null===t||fe(t)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),l(t)):pe(t)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),ke(e,h,"whitespace")(t)):96===t&&t===o?n(t):(e.consume(t),u)}function h(t){return null===t||fe(t)?l(t):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),f(t))}function f(t){return null===t||fe(t)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),l(t)):96===t&&t===o?n(t):(e.consume(t),f)}function d(t){return e.attempt(i,k,p)(t)}function p(t){return e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),g}function g(t){return s>0&&pe(t)?ke(e,m,"linePrefix",s+1)(t):m(t)}function m(t){return null===t||fe(t)?e.check(De,d,k)(t):(e.enter("codeFlowValue"),y(t))}function y(t){return null===t||fe(t)?(e.exit("codeFlowValue"),m(t)):(e.consume(t),y)}function k(n){return e.exit("codeFenced"),t(n)}}};const Pe={name:"codeIndented",tokenize:function(e,t,n){const r=this;return function(t){return e.enter("codeIndented"),ke(e,i,"linePrefix",5)(t)};function i(e){const t=r.events[r.events.length-1];return t&&"linePrefix"===t[1].type&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return null===t?a(t):fe(t)?e.attempt(Me,o,a)(t):(e.enter("codeFlowValue"),s(t))}function s(t){return null===t||fe(t)?(e.exit("codeFlowValue"),o(t)):(e.consume(t),s)}function a(n){return e.exit("codeIndented"),t(n)}}},Me={partial:!0,tokenize:function(e,t,n){const r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):fe(t)?(e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),i):ke(e,o,"linePrefix",5)(t)}function o(e){const o=r.events[r.events.length-1];return o&&"linePrefix"===o[1].type&&o[2].sliceSerialize(o[1],!0).length>=4?t(e):fe(e)?i(e):n(e)}}};const Re={name:"codeText",previous:function(e){return 96!==e||"characterEscape"===this.events[this.events.length-1][1].type},resolve:function(e){let t,n,r=e.length-4,i=3;if(!("lineEnding"!==e[i][1].type&&"space"!==e[i][1].type||"lineEnding"!==e[r][1].type&&"space"!==e[r][1].type))for(t=i;++t<r;)if("codeTextData"===e[t][1].type){e[i][1].type="codeTextPadding",e[r][1].type="codeTextPadding",i+=2,r-=2;break}t=i-1,r++;for(;++t<=r;)void 0===n?t!==r&&"lineEnding"!==e[t][1].type&&(n=t):t!==r&&"lineEnding"!==e[t][1].type||(e[n][1].type="codeTextData",t!==n+2&&(e[n][1].end=e[t-1][1].end,e.splice(n+2,t-n-2),r-=t-n-2,t=n+2),n=void 0);return e},tokenize:function(e,t,n){let r,i,o=0;return function(t){return e.enter("codeText"),e.enter("codeTextSequence"),s(t)};function s(t){return 96===t?(e.consume(t),o++,s):(e.exit("codeTextSequence"),a(t))}function a(t){return null===t?n(t):32===t?(e.enter("space"),e.consume(t),e.exit("space"),a):96===t?(i=e.enter("codeTextSequence"),r=0,l(t)):fe(t)?(e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),a):(e.enter("codeTextData"),c(t))}function c(t){return null===t||32===t||96===t||fe(t)?(e.exit("codeTextData"),a(t)):(e.consume(t),c)}function l(n){return 96===n?(e.consume(n),r++,l):r===o?(e.exit("codeTextSequence"),e.exit("codeText"),t(n)):(i.type="codeTextData",c(n))}}};class Fe{constructor(e){this.left=e?[...e]:[],this.right=[]}get(e){if(e<0||e>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return e<this.left.length?this.left[e]:this.right[this.right.length-e+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(e,t){const n=null==t?Number.POSITIVE_INFINITY:t;return n<this.left.length?this.left.slice(e,n):e>this.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){const r=t||0;this.setCursor(Math.trunc(e));const i=this.right.splice(this.right.length-r,Number.POSITIVE_INFINITY);return n&&Ne(this.left,n),i.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(e){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(e)}pushMany(e){this.setCursor(Number.POSITIVE_INFINITY),Ne(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),Ne(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&0===this.right.length||e<0&&0===this.left.length))if(e<this.left.length){const t=this.left.splice(e,Number.POSITIVE_INFINITY);Ne(this.right,t.reverse())}else{const t=this.right.splice(this.left.length+this.right.length-e,Number.POSITIVE_INFINITY);Ne(this.left,t.reverse())}}}function Ne(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function ze(e){const t={};let n,r,i,o,s,a,c,l=-1;const u=new Fe(e);for(;++l<u.length;){for(;l in t;)l=t[l];if(n=u.get(l),l&&"chunkFlow"===n[1].type&&"listItemPrefix"===u.get(l-1)[1].type&&(a=n[1]._tokenizer.events,i=0,i<a.length&&"lineEndingBlank"===a[i][1].type&&(i+=2),i<a.length&&"content"===a[i][1].type))for(;++i<a.length&&"content"!==a[i][1].type;)"chunkText"===a[i][1].type&&(a[i][1]._isInFirstContentOfListItem=!0,i++);if("enter"===n[0])n[1].contentType&&(Object.assign(t,je(u,l)),l=t[l],c=!0);else if(n[1]._container){for(i=l,r=void 0;i--;)if(o=u.get(i),"lineEnding"===o[1].type||"lineEndingBlank"===o[1].type)"enter"===o[0]&&(r&&(u.get(r)[1].type="lineEndingBlank"),o[1].type="lineEnding",r=i);else if("linePrefix"!==o[1].type&&"listItemIndent"!==o[1].type)break;r&&(n[1].end={...u.get(r)[1].start},s=u.slice(r,l),s.unshift(n),u.splice(r,l-r+1,s))}}return J(e,0,Number.POSITIVE_INFINITY,u.slice(0)),!c}function je(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const o=[];let s=n._tokenizer;s||(s=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(s._contentTypeTextTrailing=!0));const a=s.events,c=[],l={};let u,h,f=-1,d=n,p=0,g=0;const m=[g];for(;d;){for(;e.get(++i)[1]!==d;);o.push(i),d._tokenizer||(u=r.sliceStream(d),d.next||u.push(null),h&&s.defineSkip(d.start),d._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=!0),s.write(u),d._isInFirstContentOfListItem&&(s._gfmTasklistFirstContentOfListItem=void 0)),h=d,d=d.next}for(d=n;++f<a.length;)"exit"===a[f][0]&&"enter"===a[f-1][0]&&a[f][1].type===a[f-1][1].type&&a[f][1].start.line!==a[f][1].end.line&&(g=f+1,m.push(g),d._tokenizer=void 0,d.previous=void 0,d=d.next);for(s.events=[],d?(d._tokenizer=void 0,d.previous=void 0):m.pop(),f=m.length;f--;){const t=a.slice(m[f],m[f+1]),n=o.pop();c.push([n,n+t.length-1]),e.splice(n,2,t)}for(c.reverse(),f=-1;++f<c.length;)l[p+c[f][0]]=p+c[f][1],p+=c[f][1]-c[f][0]-1;return l}const Be={resolve:function(e){return ze(e),e},tokenize:function(e,t){let n;return function(t){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),r(t)};function r(t){return null===t?i(t):fe(t)?e.check($e,o,i)(t):(e.consume(t),r)}function i(n){return e.exit("chunkContent"),e.exit("content"),t(n)}function o(t){return e.consume(t),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,r}}},$e={partial:!0,tokenize:function(e,t,n){const r=this;return function(t){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),ke(e,i,"linePrefix")};function i(i){if(null===i||fe(i))return n(i);const o=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&o&&"linePrefix"===o[1].type&&o[2].sliceSerialize(o[1],!0).length>=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}};function Ue(e,t,n,r,i,o,s,a,c){const l=c||Number.POSITIVE_INFINITY;let u=0;return function(t){if(60===t)return e.enter(r),e.enter(i),e.enter(o),e.consume(t),e.exit(o),h;if(null===t||32===t||41===t||ce(t))return n(t);return e.enter(r),e.enter(s),e.enter(a),e.enter("chunkString",{contentType:"string"}),p(t)};function h(n){return 62===n?(e.enter(o),e.consume(n),e.exit(o),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),f(n))}function f(t){return 62===t?(e.exit("chunkString"),e.exit(a),h(t)):null===t||60===t||fe(t)?n(t):(e.consume(t),92===t?d:f)}function d(t){return 60===t||62===t||92===t?(e.consume(t),f):f(t)}function p(i){return u||null!==i&&41!==i&&!de(i)?u<l&&40===i?(e.consume(i),u++,p):41===i?(e.consume(i),u--,p):null===i||32===i||40===i||ce(i)?n(i):(e.consume(i),92===i?g:p):(e.exit("chunkString"),e.exit(a),e.exit(s),e.exit(r),t(i))}function g(t){return 40===t||41===t||92===t?(e.consume(t),p):p(t)}}function Ve(e,t,n,r,i,o){const s=this;let a,c=0;return function(t){return e.enter(r),e.enter(i),e.consume(t),e.exit(i),e.enter(o),l};function l(h){return c>999||null===h||91===h||93===h&&!a||94===h&&!c&&"_hiddenFootnoteSupport"in s.parser.constructs?n(h):93===h?(e.exit(o),e.enter(i),e.consume(h),e.exit(i),e.exit(r),t):fe(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),l):(e.enter("chunkString",{contentType:"string"}),u(h))}function u(t){return null===t||91===t||93===t||fe(t)||c++>999?(e.exit("chunkString"),l(t)):(e.consume(t),a||(a=!pe(t)),92===t?h:u)}function h(t){return 91===t||92===t||93===t?(e.consume(t),c++,u):u(t)}}function He(e,t,n,r,i,o){let s;return function(t){if(34===t||39===t||40===t)return e.enter(r),e.enter(i),e.consume(t),e.exit(i),s=40===t?41:t,a;return n(t)};function a(n){return n===s?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(o),c(n))}function c(t){return t===s?(e.exit(o),a(s)):null===t?n(t):fe(t)?(e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),ke(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),l(t))}function l(t){return t===s||null===t||fe(t)?(e.exit("chunkString"),c(t)):(e.consume(t),92===t?u:l)}function u(t){return t===s||92===t?(e.consume(t),l):l(t)}}function qe(e,t){let n;return function r(i){if(fe(i))return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r;if(pe(i))return ke(e,r,n?"linePrefix":"lineSuffix")(i);return t(i)}}const Ye={name:"definition",tokenize:function(e,t,n){const r=this;let i;return function(t){return e.enter("definition"),function(t){return Ve.call(r,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(t)}(t)};function o(t){return i=ie(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),58===t?(e.enter("definitionMarker"),e.consume(t),e.exit("definitionMarker"),s):n(t)}function s(t){return de(t)?qe(e,a)(t):a(t)}function a(t){return Ue(e,c,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(t)}function c(t){return e.attempt(Qe,l,l)(t)}function l(t){return pe(t)?ke(e,u,"whitespace")(t):u(t)}function u(o){return null===o||fe(o)?(e.exit("definition"),r.parser.defined.push(i),t(o)):n(o)}}},Qe={partial:!0,tokenize:function(e,t,n){return function(t){return de(t)?qe(e,r)(t):n(t)};function r(t){return He(e,i,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(t)}function i(t){return pe(t)?ke(e,o,"whitespace")(t):o(t)}function o(e){return null===e||fe(e)?t(e):n(e)}}};const Ke={name:"hardBreakEscape",tokenize:function(e,t,n){return function(t){return e.enter("hardBreakEscape"),e.consume(t),r};function r(r){return fe(r)?(e.exit("hardBreakEscape"),t(r)):n(r)}}};const We={name:"headingAtx",resolve:function(e,t){let n,r,i=e.length-2,o=3;"whitespace"===e[o][1].type&&(o+=2);i-2>o&&"whitespace"===e[i][1].type&&(i-=2);"atxHeadingSequence"===e[i][1].type&&(o===i-1||i-4>o&&"whitespace"===e[i-2][1].type)&&(i-=o+1===i?2:4);i>o&&(n={type:"atxHeadingText",start:e[o][1].start,end:e[i][1].end},r={type:"chunkText",start:e[o][1].start,end:e[i][1].end,contentType:"text"},J(e,o,i-o+1,[["enter",n,t],["enter",r,t],["exit",r,t],["exit",n,t]]));return e},tokenize:function(e,t,n){let r=0;return function(t){return e.enter("atxHeading"),function(t){return e.enter("atxHeadingSequence"),i(t)}(t)};function i(t){return 35===t&&r++<6?(e.consume(t),i):null===t||de(t)?(e.exit("atxHeadingSequence"),o(t)):n(t)}function o(n){return 35===n?(e.enter("atxHeadingSequence"),s(n)):null===n||fe(n)?(e.exit("atxHeading"),t(n)):pe(n)?ke(e,o,"whitespace")(n):(e.enter("atxHeadingText"),a(n))}function s(t){return 35===t?(e.consume(t),s):(e.exit("atxHeadingSequence"),o(t))}function a(t){return null===t||35===t||de(t)?(e.exit("atxHeadingText"),o(t)):(e.consume(t),a)}}};const Xe=["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","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Je=["pre","script","style","textarea"],Ge={concrete:!0,name:"htmlFlow",resolveTo:function(e){let t=e.length;for(;t--&&("enter"!==e[t][0]||"htmlFlow"!==e[t][1].type););t>1&&"linePrefix"===e[t-2][1].type&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2));return e},tokenize:function(e,t,n){const r=this;let i,o,s,a,c;return function(t){return function(t){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(t),l}(t)};function l(a){return 33===a?(e.consume(a),u):47===a?(e.consume(a),o=!0,d):63===a?(e.consume(a),i=3,r.interrupt?t:M):oe(a)?(e.consume(a),s=String.fromCharCode(a),p):n(a)}function u(o){return 45===o?(e.consume(o),i=2,h):91===o?(e.consume(o),i=5,a=0,f):oe(o)?(e.consume(o),i=4,r.interrupt?t:M):n(o)}function h(i){return 45===i?(e.consume(i),r.interrupt?t:M):n(i)}function f(i){const o="CDATA[";return i===o.charCodeAt(a++)?(e.consume(i),6===a?r.interrupt?t:_:f):n(i)}function d(t){return oe(t)?(e.consume(t),s=String.fromCharCode(t),p):n(t)}function p(a){if(null===a||47===a||62===a||de(a)){const c=47===a,l=s.toLowerCase();return c||o||!Je.includes(l)?Xe.includes(s.toLowerCase())?(i=6,c?(e.consume(a),g):r.interrupt?t(a):_(a)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(a):o?m(a):y(a)):(i=1,r.interrupt?t(a):_(a))}return 45===a||se(a)?(e.consume(a),s+=String.fromCharCode(a),p):n(a)}function g(i){return 62===i?(e.consume(i),r.interrupt?t:_):n(i)}function m(t){return pe(t)?(e.consume(t),m):S(t)}function y(t){return 47===t?(e.consume(t),S):58===t||95===t||oe(t)?(e.consume(t),k):pe(t)?(e.consume(t),y):S(t)}function k(t){return 45===t||46===t||58===t||95===t||se(t)?(e.consume(t),k):x(t)}function x(t){return 61===t?(e.consume(t),b):pe(t)?(e.consume(t),x):y(t)}function b(t){return null===t||60===t||61===t||62===t||96===t?n(t):34===t||39===t?(e.consume(t),c=t,v):pe(t)?(e.consume(t),b):w(t)}function v(t){return t===c?(e.consume(t),c=null,E):null===t||fe(t)?n(t):(e.consume(t),v)}function w(t){return null===t||34===t||39===t||47===t||60===t||61===t||62===t||96===t||de(t)?x(t):(e.consume(t),w)}function E(e){return 47===e||62===e||pe(e)?y(e):n(e)}function S(t){return 62===t?(e.consume(t),C):n(t)}function C(t){return null===t||fe(t)?_(t):pe(t)?(e.consume(t),C):n(t)}function _(t){return 45===t&&2===i?(e.consume(t),O):60===t&&1===i?(e.consume(t),D):62===t&&4===i?(e.consume(t),R):63===t&&3===i?(e.consume(t),M):93===t&&5===i?(e.consume(t),P):!fe(t)||6!==i&&7!==i?null===t||fe(t)?(e.exit("htmlFlowData"),A(t)):(e.consume(t),_):(e.exit("htmlFlowData"),e.check(Ze,F,A)(t))}function A(t){return e.check(et,I,F)(t)}function I(t){return e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),T}function T(t){return null===t||fe(t)?A(t):(e.enter("htmlFlowData"),_(t))}function O(t){return 45===t?(e.consume(t),M):_(t)}function D(t){return 47===t?(e.consume(t),s="",L):_(t)}function L(t){if(62===t){const n=s.toLowerCase();return Je.includes(n)?(e.consume(t),R):_(t)}return oe(t)&&s.length<8?(e.consume(t),s+=String.fromCharCode(t),L):_(t)}function P(t){return 93===t?(e.consume(t),M):_(t)}function M(t){return 62===t?(e.consume(t),R):45===t&&2===i?(e.consume(t),M):_(t)}function R(t){return null===t||fe(t)?(e.exit("htmlFlowData"),F(t)):(e.consume(t),R)}function F(n){return e.exit("htmlFlow"),t(n)}}},Ze={partial:!0,tokenize:function(e,t,n){return function(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),e.attempt(Ae,t,n)}}},et={partial:!0,tokenize:function(e,t,n){const r=this;return function(t){if(fe(t))return e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),i;return n(t)};function i(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}};const tt={name:"htmlText",tokenize:function(e,t,n){const r=this;let i,o,s;return function(t){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(t),a};function a(t){return 33===t?(e.consume(t),c):47===t?(e.consume(t),b):63===t?(e.consume(t),k):oe(t)?(e.consume(t),E):n(t)}function c(t){return 45===t?(e.consume(t),l):91===t?(e.consume(t),o=0,d):oe(t)?(e.consume(t),y):n(t)}function l(t){return 45===t?(e.consume(t),f):n(t)}function u(t){return null===t?n(t):45===t?(e.consume(t),h):fe(t)?(s=u,L(t)):(e.consume(t),u)}function h(t){return 45===t?(e.consume(t),f):u(t)}function f(e){return 62===e?D(e):45===e?h(e):u(e)}function d(t){const r="CDATA[";return t===r.charCodeAt(o++)?(e.consume(t),6===o?p:d):n(t)}function p(t){return null===t?n(t):93===t?(e.consume(t),g):fe(t)?(s=p,L(t)):(e.consume(t),p)}function g(t){return 93===t?(e.consume(t),m):p(t)}function m(t){return 62===t?D(t):93===t?(e.consume(t),m):p(t)}function y(t){return null===t||62===t?D(t):fe(t)?(s=y,L(t)):(e.consume(t),y)}function k(t){return null===t?n(t):63===t?(e.consume(t),x):fe(t)?(s=k,L(t)):(e.consume(t),k)}function x(e){return 62===e?D(e):k(e)}function b(t){return oe(t)?(e.consume(t),v):n(t)}function v(t){return 45===t||se(t)?(e.consume(t),v):w(t)}function w(t){return fe(t)?(s=w,L(t)):pe(t)?(e.consume(t),w):D(t)}function E(t){return 45===t||se(t)?(e.consume(t),E):47===t||62===t||de(t)?S(t):n(t)}function S(t){return 47===t?(e.consume(t),D):58===t||95===t||oe(t)?(e.consume(t),C):fe(t)?(s=S,L(t)):pe(t)?(e.consume(t),S):D(t)}function C(t){return 45===t||46===t||58===t||95===t||se(t)?(e.consume(t),C):_(t)}function _(t){return 61===t?(e.consume(t),A):fe(t)?(s=_,L(t)):pe(t)?(e.consume(t),_):S(t)}function A(t){return null===t||60===t||61===t||62===t||96===t?n(t):34===t||39===t?(e.consume(t),i=t,I):fe(t)?(s=A,L(t)):pe(t)?(e.consume(t),A):(e.consume(t),T)}function I(t){return t===i?(e.consume(t),i=void 0,O):null===t?n(t):fe(t)?(s=I,L(t)):(e.consume(t),I)}function T(t){return null===t||34===t||39===t||60===t||61===t||96===t?n(t):47===t||62===t||de(t)?S(t):(e.consume(t),T)}function O(e){return 47===e||62===e||de(e)?S(e):n(e)}function D(r){return 62===r?(e.consume(r),e.exit("htmlTextData"),e.exit("htmlText"),t):n(r)}function L(t){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),P}function P(t){return pe(t)?ke(e,M,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(t):M(t)}function M(t){return e.enter("htmlTextData"),s(t)}}};const nt={name:"labelEnd",resolveAll:function(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),"labelImage"===r.type||"labelLink"===r.type||"labelEnd"===r.type){const e="labelImage"===r.type?4:2;r.type="data",t+=e}}e.length!==n.length&&J(e,0,e.length,n);return e},resolveTo:function(e,t){let n,r,i,o,s=e.length,a=0;for(;s--;)if(n=e[s][1],r){if("link"===n.type||"labelLink"===n.type&&n._inactive)break;"enter"===e[s][0]&&"labelLink"===n.type&&(n._inactive=!0)}else if(i){if("enter"===e[s][0]&&("labelImage"===n.type||"labelLink"===n.type)&&!n._balanced&&(r=s,"labelLink"!==n.type)){a=2;break}}else"labelEnd"===n.type&&(i=s);const c={type:"labelLink"===e[r][1].type?"link":"image",start:{...e[r][1].start},end:{...e[e.length-1][1].end}},l={type:"label",start:{...e[r][1].start},end:{...e[i][1].end}},u={type:"labelText",start:{...e[r+a+2][1].end},end:{...e[i-2][1].start}};return o=[["enter",c,t],["enter",l,t]],o=G(o,e.slice(r+1,r+a+3)),o=G(o,[["enter",u,t]]),o=G(o,Ee(t.parser.constructs.insideSpan.null,e.slice(r+a+4,i-3),t)),o=G(o,[["exit",u,t],e[i-2],e[i-1],["exit",l,t]]),o=G(o,e.slice(i+1)),o=G(o,[["exit",c,t]]),J(e,r,e.length,o),e},tokenize:function(e,t,n){const r=this;let i,o,s=r.events.length;for(;s--;)if(("labelImage"===r.events[s][1].type||"labelLink"===r.events[s][1].type)&&!r.events[s][1]._balanced){i=r.events[s][1];break}return function(t){if(!i)return n(t);if(i._inactive)return u(t);return o=r.parser.defined.includes(ie(r.sliceSerialize({start:i.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(t),e.exit("labelMarker"),e.exit("labelEnd"),a};function a(t){return 40===t?e.attempt(rt,l,o?l:u)(t):91===t?e.attempt(it,l,o?c:u)(t):o?l(t):u(t)}function c(t){return e.attempt(ot,l,u)(t)}function l(e){return t(e)}function u(e){return i._balanced=!0,n(e)}}},rt={tokenize:function(e,t,n){return function(t){return e.enter("resource"),e.enter("resourceMarker"),e.consume(t),e.exit("resourceMarker"),r};function r(t){return de(t)?qe(e,i)(t):i(t)}function i(t){return 41===t?l(t):Ue(e,o,s,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(t)}function o(t){return de(t)?qe(e,a)(t):l(t)}function s(e){return n(e)}function a(t){return 34===t||39===t||40===t?He(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(t):l(t)}function c(t){return de(t)?qe(e,l)(t):l(t)}function l(r){return 41===r?(e.enter("resourceMarker"),e.consume(r),e.exit("resourceMarker"),e.exit("resource"),t):n(r)}}},it={tokenize:function(e,t,n){const r=this;return function(t){return Ve.call(r,e,i,o,"reference","referenceMarker","referenceString")(t)};function i(e){return r.parser.defined.includes(ie(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(e):n(e)}function o(e){return n(e)}}},ot={tokenize:function(e,t,n){return function(t){return e.enter("reference"),e.enter("referenceMarker"),e.consume(t),e.exit("referenceMarker"),r};function r(r){return 93===r?(e.enter("referenceMarker"),e.consume(r),e.exit("referenceMarker"),e.exit("reference"),t):n(r)}}};const st={name:"labelStartImage",resolveAll:nt.resolveAll,tokenize:function(e,t,n){const r=this;return function(t){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(t),e.exit("labelImageMarker"),i};function i(t){return 91===t?(e.enter("labelMarker"),e.consume(t),e.exit("labelMarker"),e.exit("labelImage"),o):n(t)}function o(e){return 94===e&&"_hiddenFootnoteSupport"in r.parser.constructs?n(e):t(e)}}};const at={name:"labelStartLink",resolveAll:nt.resolveAll,tokenize:function(e,t,n){const r=this;return function(t){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(t),e.exit("labelMarker"),e.exit("labelLink"),i};function i(e){return 94===e&&"_hiddenFootnoteSupport"in r.parser.constructs?n(e):t(e)}}};const ct={name:"lineEnding",tokenize:function(e,t){return function(n){return e.enter("lineEnding"),e.consume(n),e.exit("lineEnding"),ke(e,t,"linePrefix")}}};const lt={name:"thematicBreak",tokenize:function(e,t,n){let r,i=0;return function(t){return e.enter("thematicBreak"),function(e){return r=e,o(e)}(t)};function o(o){return o===r?(e.enter("thematicBreakSequence"),s(o)):i>=3&&(null===o||fe(o))?(e.exit("thematicBreak"),t(o)):n(o)}function s(t){return t===r?(e.consume(t),i++,s):(e.exit("thematicBreakSequence"),pe(t)?ke(e,o,"whitespace")(t):o(t))}}};const ut={continuation:{tokenize:function(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(Ae,i,o);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,ke(e,t,"listItemIndent",r.containerState.size+1)(n)}function o(n){return r.containerState.furtherBlankLines||!pe(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,s(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(ft,t,s)(n))}function s(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,ke(e,e.attempt(ut,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(i)}}},exit:function(e){e.exit(this.containerState.type)},name:"list",tokenize:function(e,t,n){const r=this,i=r.events[r.events.length-1];let o=i&&"linePrefix"===i[1].type?i[2].sliceSerialize(i[1],!0).length:0,s=0;return function(t){const i=r.containerState.type||(42===t||43===t||45===t?"listUnordered":"listOrdered");if("listUnordered"===i?!r.containerState.marker||t===r.containerState.marker:le(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),"listUnordered"===i)return e.enter("listItemPrefix"),42===t||45===t?e.check(lt,n,c)(t):c(t);if(!r.interrupt||49===t)return e.enter("listItemPrefix"),e.enter("listItemValue"),a(t)}return n(t)};function a(t){return le(t)&&++s<10?(e.consume(t),a):(!r.interrupt||s<2)&&(r.containerState.marker?t===r.containerState.marker:41===t||46===t)?(e.exit("listItemValue"),c(t)):n(t)}function c(t){return e.enter("listItemMarker"),e.consume(t),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||t,e.check(Ae,r.interrupt?n:l,e.attempt(ht,h,u))}function l(e){return r.containerState.initialBlankLine=!0,o++,h(e)}function u(t){return pe(t)?(e.enter("listItemPrefixWhitespace"),e.consume(t),e.exit("listItemPrefixWhitespace"),h):n(t)}function h(n){return r.containerState.size=o+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(n)}}},ht={partial:!0,tokenize:function(e,t,n){const r=this;return ke(e,(function(e){const i=r.events[r.events.length-1];return!pe(e)&&i&&"listItemPrefixWhitespace"===i[1].type?t(e):n(e)}),"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5)}},ft={partial:!0,tokenize:function(e,t,n){const r=this;return ke(e,(function(e){const i=r.events[r.events.length-1];return i&&"listItemIndent"===i[1].type&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}),"listItemIndent",r.containerState.size+1)}};const dt={name:"setextUnderline",resolveTo:function(e,t){let n,r,i,o=e.length;for(;o--;)if("enter"===e[o][0]){if("content"===e[o][1].type){n=o;break}"paragraph"===e[o][1].type&&(r=o)}else"content"===e[o][1].type&&e.splice(o,1),i||"definition"!==e[o][1].type||(i=o);const s={type:"setextHeading",start:{...e[n][1].start},end:{...e[e.length-1][1].end}};e[r][1].type="setextHeadingText",i?(e.splice(r,0,["enter",s,t]),e.splice(i+1,0,["exit",e[n][1],t]),e[n][1].end={...e[i][1].end}):e[n][1]=s;return e.push(["exit",s,t]),e},tokenize:function(e,t,n){const r=this;let i;return function(t){let s,a=r.events.length;for(;a--;)if("lineEnding"!==r.events[a][1].type&&"linePrefix"!==r.events[a][1].type&&"content"!==r.events[a][1].type){s="paragraph"===r.events[a][1].type;break}if(!r.parser.lazy[r.now().line]&&(r.interrupt||s))return e.enter("setextHeadingLine"),i=t,function(t){return e.enter("setextHeadingLineSequence"),o(t)}(t);return n(t)};function o(t){return t===i?(e.consume(t),o):(e.exit("setextHeadingLineSequence"),pe(t)?ke(e,s,"lineSuffix")(t):s(t))}function s(r){return null===r||fe(r)?(e.exit("setextHeadingLine"),t(r)):n(r)}}};const pt={tokenize:function(e){const t=this,n=e.attempt(Ae,(function(r){if(null===r)return void e.consume(r);return e.enter("lineEndingBlank"),e.consume(r),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}),e.attempt(this.parser.constructs.flowInitial,r,ke(e,e.attempt(this.parser.constructs.flow,r,e.attempt(Be,r)),"linePrefix")));return n;function r(r){if(null!==r)return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),t.currentConstruct=void 0,n;e.consume(r)}}};const gt={resolveAll:xt()},mt=kt("string"),yt=kt("text");function kt(e){return{resolveAll:xt("text"===e?bt:void 0),tokenize:function(t){const n=this,r=this.parser.constructs[e],i=t.attempt(r,o,s);return o;function o(e){return c(e)?i(e):s(e)}function s(e){if(null!==e)return t.enter("data"),t.consume(e),a;t.consume(e)}function a(e){return c(e)?(t.exit("data"),i(e)):(t.consume(e),a)}function c(e){if(null===e)return!0;const t=r[e];let i=-1;if(t)for(;++i<t.length;){const e=t[i];if(!e.previous||e.previous.call(n,n.previous))return!0}return!1}}}}function xt(e){return function(t,n){let r,i=-1;for(;++i<=t.length;)void 0===r?t[i]&&"data"===t[i][1].type&&(r=i,i++):t[i]&&"data"===t[i][1].type||(i!==r+2&&(t[r][1].end=t[i-1][1].end,t.splice(r+2,i-r-2),i=r+2),r=void 0);return e?e(t,n):t}}function bt(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||"lineEnding"===e[n][1].type)&&"data"===e[n-1][1].type){const r=e[n-1][1],i=t.sliceStream(r);let o,s=i.length,a=-1,c=0;for(;s--;){const e=i[s];if("string"==typeof e){for(a=e.length;32===e.charCodeAt(a-1);)c++,a--;if(a)break;a=-1}else if(-2===e)o=!0,c++;else if(-1!==e){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(c=0),c){const i={type:n===e.length||o||c<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?a:r.start._bufferIndex+a,_index:r.start._index+s,line:r.end.line,column:r.end.column-c,offset:r.end.offset-c},end:{...r.end}};r.end={...i.start},r.start.offset===r.end.offset?Object.assign(r,i):(e.splice(n,0,["enter",i,t],["exit",i,t]),n+=2)}n++}return e}const vt={42:ut,43:ut,45:ut,48:ut,49:ut,50:ut,51:ut,52:ut,53:ut,54:ut,55:ut,56:ut,57:ut,62:Ie},wt={91:Ye},Et={[-2]:Pe,[-1]:Pe,32:Pe},St={35:We,42:lt,45:[dt,lt],60:Ge,61:dt,95:lt,96:Le,126:Le},Ct={38:Oe,92:Te},_t={[-5]:ct,[-4]:ct,[-3]:ct,33:st,38:Oe,42:Se,60:[_e,tt],91:at,92:[Ke,Te],93:nt,95:Se,96:Re},At={null:[Se,gt]};var It=Object.freeze({__proto__:null,attentionMarkers:{null:[42,95]},contentInitial:wt,disable:{null:[]},document:vt,flow:St,flowInitial:Et,insideSpan:At,string:Ct,text:_t});function Tt(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},o=[];let s=[],a=[];const c={attempt:m((function(e,t){y(e,t.from)})),check:m(g),consume:function(e){fe(e)?(r.line++,r.column=1,r.offset+=-3===e?2:1,k()):-1!==e&&(r.column++,r.offset++);r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===s[r._index].length&&(r._bufferIndex=-1,r._index++));l.previous=e},enter:function(e,t){const n=t||{};return n.type=e,n.start=f(),l.events.push(["enter",n,l]),a.push(n),n},exit:function(e){const t=a.pop();return t.end=f(),l.events.push(["exit",t,l]),t},interrupt:m(g,{interrupt:!0})},l={code:null,containerState:{},defineSkip:function(e){i[e.line]=e.column,k()},events:[],now:f,parser:e,previous:null,sliceSerialize:function(e,t){return function(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const o=e[n];let s;if("string"==typeof o)s=o;else switch(o){case-5:s="\r";break;case-4:s="\n";break;case-3:s="\r\n";break;case-2:s=t?" ":"\t";break;case-1:if(!t&&i)continue;s=" ";break;default:s=String.fromCharCode(o)}i=-2===o,r.push(s)}return r.join("")}(h(e),t)},sliceStream:h,write:function(e){if(s=G(s,e),d(),null!==s[s.length-1])return[];return y(t,0),l.events=Ee(o,l.events,l),l.events}};let u=t.tokenize.call(l,c);return t.resolveAll&&o.push(t),l;function h(e){return function(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,o=t.end._bufferIndex;let s;if(n===i)s=[e[n].slice(r,o)];else{if(s=e.slice(n,i),r>-1){const e=s[0];"string"==typeof e?s[0]=e.slice(r):s.shift()}o>0&&s.push(e[i].slice(0,o))}return s}(s,e)}function f(){const{_bufferIndex:e,_index:t,line:n,column:i,offset:o}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:o}}function d(){let e;for(;r._index<s.length;){const t=s[r._index];if("string"==typeof t)for(e=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===e&&r._bufferIndex<t.length;)p(t.charCodeAt(r._bufferIndex));else p(t)}}function p(e){u=u(e)}function g(e,t){t.restore()}function m(e,t){return function(n,i,o){let s,u,h,d;return Array.isArray(n)?p(n):"tokenize"in n?p([n]):function(e){return t;function t(t){const n=null!==t&&e[t],r=null!==t&&e.null;return p([...Array.isArray(n)?n:n?[n]:[],...Array.isArray(r)?r:r?[r]:[]])(t)}}(n);function p(e){return s=e,u=0,0===e.length?o:g(e[u])}function g(e){return function(n){d=function(){const e=f(),t=l.previous,n=l.currentConstruct,i=l.events.length,o=Array.from(a);return{from:i,restore:s};function s(){r=e,l.previous=t,l.currentConstruct=n,l.events.length=i,a=o,k()}}(),h=e,e.partial||(l.currentConstruct=e);if(e.name&&l.parser.constructs.disable.null.includes(e.name))return y();return e.tokenize.call(t?Object.assign(Object.create(l),t):l,c,m,y)(n)}}function m(t){return e(h,d),i}function y(e){return d.restore(),++u<s.length?g(s[u]):o}}}function y(e,t){e.resolveAll&&!o.includes(e)&&o.push(e),e.resolve&&J(l.events,t,l.events.length-t,e.resolve(l.events.slice(t),l)),e.resolveTo&&(l.events=e.resolveTo(l.events,l))}function k(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}const Ot=/[\0\t\n\r]/g;const Dt=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function Lt(e,t,n){if(t)return t;if(35===n.charCodeAt(0)){const e=n.charCodeAt(1),t=120===e||88===e;return re(n.slice(t?2:1),t?16:10)}return X(n)||e}function Pt(e){return e&&"object"==typeof e?"position"in e||"type"in e?Rt(e.position):"start"in e||"end"in e?Rt(e):"line"in e||"column"in e?Mt(e):"":""}function Mt(e){return Ft(e&&e.line)+":"+Ft(e&&e.column)}function Rt(e){return Mt(e&&e.start)+"-"+Mt(e&&e.end)}function Ft(e){return e&&"number"==typeof e?e:1}const Nt={}.hasOwnProperty;function zt(e,t,n){return"string"!=typeof t&&(n=t,t=void 0),function(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:o(se),autolinkProtocol:C,autolinkEmail:C,atxHeading:o(ee),blockQuote:o(K),characterEscape:C,characterReference:C,codeFenced:o(W),codeFencedFenceInfo:s,codeFencedFenceMeta:s,codeIndented:o(W,s),codeText:o(J,s),codeTextData:C,data:C,codeFlowValue:C,definition:o(G),definitionDestinationString:s,definitionLabelString:s,definitionTitleString:s,emphasis:o(Z),hardBreakEscape:o(te),hardBreakTrailing:o(te),htmlFlow:o(ne,s),htmlFlowData:C,htmlText:o(ne,s),htmlTextData:C,image:o(oe),label:s,link:o(se),listItem:o(ce),listItemValue:f,listOrdered:o(ae,h),listUnordered:o(ae),paragraph:o(le),reference:j,referenceString:s,resourceDestinationString:s,resourceTitleString:s,setextHeading:o(ee),strong:o(ue),thematicBreak:o(fe)},exit:{atxHeading:c(),atxHeadingSequence:v,autolink:c(),autolinkEmail:q,autolinkProtocol:H,blockQuote:c(),characterEscapeValue:_,characterReferenceMarkerHexadecimal:$,characterReferenceMarkerNumeric:$,characterReferenceValue:U,characterReference:V,codeFenced:c(m),codeFencedFence:g,codeFencedFenceInfo:d,codeFencedFenceMeta:p,codeFlowValue:_,codeIndented:c(y),codeText:c(D),codeTextData:_,data:_,definition:c(),definitionDestinationString:b,definitionLabelString:k,definitionTitleString:x,emphasis:c(),hardBreakEscape:c(I),hardBreakTrailing:c(I),htmlFlow:c(T),htmlFlowData:_,htmlText:c(O),htmlTextData:_,image:c(P),label:R,labelText:M,lineEnding:A,link:c(L),listItem:c(),listOrdered:c(),listUnordered:c(),paragraph:c(),referenceString:B,resourceDestinationString:F,resourceTitleString:N,resource:z,setextHeading:c(S),setextHeadingLineSequence:E,setextHeadingText:w,strong:c(),thematicBreak:c()}};Bt(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(e){let r={type:"root",children:[]};const o={stack:[r],tokenStack:[],config:t,enter:a,exit:l,buffer:s,resume:u,data:n},c=[];let h=-1;for(;++h<e.length;)if("listOrdered"===e[h][1].type||"listUnordered"===e[h][1].type)if("enter"===e[h][0])c.push(h);else{h=i(e,c.pop(),h)}for(h=-1;++h<e.length;){const n=t[e[h][0]];Nt.call(n,e[h][1].type)&&n[e[h][1].type].call(Object.assign({sliceSerialize:e[h][2].sliceSerialize},o),e[h][1])}if(o.tokenStack.length>0){const e=o.tokenStack[o.tokenStack.length-1];(e[1]||Ut).call(o,void 0,e[0])}for(r.position={start:jt(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:jt(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},h=-1;++h<t.transforms.length;)r=t.transforms[h](r)||r;return r}function i(e,t,n){let r,i,o,s,a=t-1,c=-1,l=!1;for(;++a<=n;){const t=e[a];switch(t[1].type){case"listUnordered":case"listOrdered":case"blockQuote":"enter"===t[0]?c++:c--,s=void 0;break;case"lineEndingBlank":"enter"===t[0]&&(!r||s||c||o||(o=a),s=void 0);break;case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:s=void 0}if(!c&&"enter"===t[0]&&"listItemPrefix"===t[1].type||-1===c&&"exit"===t[0]&&("listUnordered"===t[1].type||"listOrdered"===t[1].type)){if(r){let s=a;for(i=void 0;s--;){const t=e[s];if("lineEnding"===t[1].type||"lineEndingBlank"===t[1].type){if("exit"===t[0])continue;i&&(e[i][1].type="lineEndingBlank",l=!0),t[1].type="lineEnding",i=s}else if("linePrefix"!==t[1].type&&"blockQuotePrefix"!==t[1].type&&"blockQuotePrefixWhitespace"!==t[1].type&&"blockQuoteMarker"!==t[1].type&&"listItemIndent"!==t[1].type)break}o&&(!i||o<i)&&(r._spread=!0),r.end=Object.assign({},i?e[i][1].start:t[1].end),e.splice(i||a,0,["exit",r,t[2]]),a++,n++}if("listItemPrefix"===t[1].type){const i={type:"listItem",_spread:!1,start:Object.assign({},t[1].start),end:void 0};r=i,e.splice(a,0,["enter",i,t[2]]),a++,n++,o=void 0,s=!0}}}return e[t][1]._spread=l,n}function o(e,t){return n;function n(n){a.call(this,e(n),n),t&&t.call(this,n)}}function s(){this.stack.push({type:"fragment",children:[]})}function a(e,t,n){this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n||void 0]),e.position={start:jt(t.start),end:void 0}}function c(e){return t;function t(t){e&&e.call(this,t),l.call(this,t)}}function l(e,t){const n=this.stack.pop(),r=this.tokenStack.pop();if(!r)throw new Error("Cannot close `"+e.type+"` ("+Pt({start:e.start,end:e.end})+"): it’s not open");if(r[0].type!==e.type)if(t)t.call(this,e,r[0]);else{(r[1]||Ut).call(this,e,r[0])}n.position.end=jt(e.end)}function u(){return function(e){return Q(e,"boolean"!=typeof Y.includeImageAlt||Y.includeImageAlt,"boolean"!=typeof Y.includeHtml||Y.includeHtml)}(this.stack.pop())}function h(){this.data.expectingFirstListItemValue=!0}function f(e){if(this.data.expectingFirstListItemValue){this.stack[this.stack.length-2].start=Number.parseInt(this.sliceSerialize(e),10),this.data.expectingFirstListItemValue=void 0}}function d(){const e=this.resume();this.stack[this.stack.length-1].lang=e}function p(){const e=this.resume();this.stack[this.stack.length-1].meta=e}function g(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function m(){const e=this.resume();this.stack[this.stack.length-1].value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function y(){const e=this.resume();this.stack[this.stack.length-1].value=e.replace(/(\r?\n|\r)$/g,"")}function k(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=ie(this.sliceSerialize(e)).toLowerCase()}function x(){const e=this.resume();this.stack[this.stack.length-1].title=e}function b(){const e=this.resume();this.stack[this.stack.length-1].url=e}function v(e){const t=this.stack[this.stack.length-1];if(!t.depth){const n=this.sliceSerialize(e).length;t.depth=n}}function w(){this.data.setextHeadingSlurpLineEnding=!0}function E(e){this.stack[this.stack.length-1].depth=61===this.sliceSerialize(e).codePointAt(0)?1:2}function S(){this.data.setextHeadingSlurpLineEnding=void 0}function C(e){const t=this.stack[this.stack.length-1].children;let n=t[t.length-1];n&&"text"===n.type||(n=he(),n.position={start:jt(e.start),end:void 0},t.push(n)),this.stack.push(n)}function _(e){const t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=jt(e.end)}function A(e){const n=this.stack[this.stack.length-1];if(this.data.atHardBreak){return n.children[n.children.length-1].position.end=jt(e.end),void(this.data.atHardBreak=void 0)}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(n.type)&&(C.call(this,e),_.call(this,e))}function I(){this.data.atHardBreak=!0}function T(){const e=this.resume();this.stack[this.stack.length-1].value=e}function O(){const e=this.resume();this.stack[this.stack.length-1].value=e}function D(){const e=this.resume();this.stack[this.stack.length-1].value=e}function L(){const e=this.stack[this.stack.length-1];if(this.data.inReference){const t=this.data.referenceType||"shortcut";e.type+="Reference",e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function P(){const e=this.stack[this.stack.length-1];if(this.data.inReference){const t=this.data.referenceType||"shortcut";e.type+="Reference",e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;this.data.referenceType=void 0}function M(e){const t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=function(e){return e.replace(Dt,Lt)}(t),n.identifier=ie(t).toLowerCase()}function R(){const e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];if(this.data.inReference=!0,"link"===n.type){const t=e.children;n.children=t}else n.alt=t}function F(){const e=this.resume();this.stack[this.stack.length-1].url=e}function N(){const e=this.resume();this.stack[this.stack.length-1].title=e}function z(){this.data.inReference=void 0}function j(){this.data.referenceType="collapsed"}function B(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=ie(this.sliceSerialize(e)).toLowerCase(),this.data.referenceType="full"}function $(e){this.data.characterReferenceType=e.type}function U(e){const t=this.sliceSerialize(e),n=this.data.characterReferenceType;let r;if(n)r=re(t,"characterReferenceMarkerNumeric"===n?10:16),this.data.characterReferenceType=void 0;else{r=X(t)}this.stack[this.stack.length-1].value+=r}function V(e){this.stack.pop().position.end=jt(e.end)}function H(e){_.call(this,e);this.stack[this.stack.length-1].url=this.sliceSerialize(e)}function q(e){_.call(this,e);this.stack[this.stack.length-1].url="mailto:"+this.sliceSerialize(e)}function K(){return{type:"blockquote",children:[]}}function W(){return{type:"code",lang:null,meta:null,value:""}}function J(){return{type:"inlineCode",value:""}}function G(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function Z(){return{type:"emphasis",children:[]}}function ee(){return{type:"heading",depth:0,children:[]}}function te(){return{type:"break"}}function ne(){return{type:"html",value:""}}function oe(){return{type:"image",title:null,url:"",alt:null}}function se(){return{type:"link",title:null,url:"",children:[]}}function ae(e){return{type:"list",ordered:"listOrdered"===e.type,start:null,spread:e._spread,children:[]}}function ce(e){return{type:"listItem",spread:e._spread,checked:null,children:[]}}function le(){return{type:"paragraph",children:[]}}function ue(){return{type:"strong",children:[]}}function he(){return{type:"text",value:""}}function fe(){return{type:"thematicBreak"}}}(n)(function(e){for(;!ze(e););return e}(function(e){const t={constructs:ee([It,...(e||{}).extensions||[]]),content:n(xe),defined:[],document:n(be),flow:n(pt),lazy:{},string:n(mt),text:n(yt)};return t;function n(e){return function(n){return Tt(t,e,n)}}}(n).document().write(function(){let e,t=1,n="",r=!0;return function(i,o,s){const a=[];let c,l,u,h,f;for(i=n+("string"==typeof i?i.toString():new TextDecoder(o||void 0).decode(i)),u=0,n="",r&&(65279===i.charCodeAt(0)&&u++,r=void 0);u<i.length;){if(Ot.lastIndex=u,c=Ot.exec(i),h=c&&void 0!==c.index?c.index:i.length,f=i.charCodeAt(h),!c){n=i.slice(u);break}if(10===f&&u===h&&e)a.push(-3),e=void 0;else switch(e&&(a.push(-5),e=void 0),u<h&&(a.push(i.slice(u,h)),t+=h-u),f){case 0:a.push(65533),t++;break;case 9:for(l=4*Math.ceil(t/4),a.push(-2);t++<l;)a.push(-1);break;case 10:a.push(-4),t=1;break;default:e=!0,t=1}u=h+1}return s&&(e&&a.push(-5),n&&a.push(n),a.push(null)),a}}()(e,t,!0))))}function jt(e){return{line:e.line,column:e.column,offset:e.offset}}function Bt(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Bt(e,r):$t(e,r)}}function $t(e,t){let n;for(n in t)if(Nt.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function Ut(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Pt({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Pt({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Pt({start:t.start,end:t.end})+") is still open")}const Vt={tokenize:function(e,t,n){let r=0;return function t(o){if((87===o||119===o)&&r<3)return r++,e.consume(o),t;if(46===o&&3===r)return e.consume(o),i;return n(o)};function i(e){return null===e?n(e):t(e)}},partial:!0},Ht={tokenize:function(e,t,n){let r,i,o;return s;function s(t){return 46===t||95===t?e.check(Yt,c,a)(t):null===t||de(t)||me(t)||45!==t&&ge(t)?c(t):(o=!0,e.consume(t),s)}function a(t){return 95===t?r=!0:(i=r,r=void 0),e.consume(t),s}function c(e){return i||r||!o?n(e):t(e)}},partial:!0},qt={tokenize:function(e,t){let n=0,r=0;return i;function i(s){return 40===s?(n++,e.consume(s),i):41===s&&r<n?o(s):33===s||34===s||38===s||39===s||41===s||42===s||44===s||46===s||58===s||59===s||60===s||63===s||93===s||95===s||126===s?e.check(Yt,t,o)(s):null===s||de(s)||me(s)?t(s):(e.consume(s),i)}function o(t){return 41===t&&r++,e.consume(t),i}},partial:!0},Yt={tokenize:function(e,t,n){return r;function r(s){return 33===s||34===s||39===s||41===s||42===s||44===s||46===s||58===s||59===s||63===s||95===s||126===s?(e.consume(s),r):38===s?(e.consume(s),o):93===s?(e.consume(s),i):60===s||null===s||de(s)||me(s)?t(s):n(s)}function i(e){return null===e||40===e||91===e||de(e)||me(e)?t(e):r(e)}function o(e){return oe(e)?s(e):n(e)}function s(t){return 59===t?(e.consume(t),r):oe(t)?(e.consume(t),s):n(t)}},partial:!0},Qt={tokenize:function(e,t,n){return function(t){return e.consume(t),r};function r(e){return se(e)?n(e):t(e)}},partial:!0},Kt={name:"wwwAutolink",tokenize:function(e,t,n){const r=this;return function(t){if(87!==t&&119!==t||!Zt.call(r,r.previous)||rn(r.events))return n(t);return e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Vt,e.attempt(Ht,e.attempt(qt,i),n),n)(t)};function i(n){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(n)}},previous:Zt},Wt={name:"protocolAutolink",tokenize:function(e,t,n){const r=this;let i="",o=!1;return function(t){if((72===t||104===t)&&en.call(r,r.previous)&&!rn(r.events))return e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(t),e.consume(t),s;return n(t)};function s(t){if(oe(t)&&i.length<5)return i+=String.fromCodePoint(t),e.consume(t),s;if(58===t){const n=i.toLowerCase();if("http"===n||"https"===n)return e.consume(t),a}return n(t)}function a(t){return 47===t?(e.consume(t),o?c:(o=!0,a)):n(t)}function c(t){return null===t||ce(t)||de(t)||me(t)||ge(t)?n(t):e.attempt(Ht,e.attempt(qt,l),n)(t)}function l(n){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(n)}},previous:en},Xt={name:"emailAutolink",tokenize:function(e,t,n){const r=this;let i,o;return function(t){if(!nn(t)||!tn.call(r,r.previous)||rn(r.events))return n(t);return e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),s(t)};function s(t){return nn(t)?(e.consume(t),s):64===t?(e.consume(t),a):n(t)}function a(t){return 46===t?e.check(Qt,l,c)(t):45===t||95===t||se(t)?(o=!0,e.consume(t),a):l(t)}function c(t){return e.consume(t),i=!0,a}function l(s){return o&&i&&oe(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(s)):n(s)}},previous:tn},Jt={};let Gt=48;for(;Gt<123;)Jt[Gt]=Xt,Gt++,58===Gt?Gt=65:91===Gt&&(Gt=97);function Zt(e){return null===e||40===e||42===e||95===e||91===e||93===e||126===e||de(e)}function en(e){return!oe(e)}function tn(e){return!(47===e||nn(e))}function nn(e){return 43===e||45===e||46===e||95===e||se(e)}function rn(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if(("labelLink"===r.type||"labelImage"===r.type)&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}Jt[43]=Xt,Jt[45]=Xt,Jt[46]=Xt,Jt[95]=Xt,Jt[72]=[Xt,Wt],Jt[104]=[Xt,Wt],Jt[87]=[Xt,Kt],Jt[119]=[Xt,Kt];const on={tokenize:function(e,t,n){const r=this;return ke(e,(function(e){const i=r.events[r.events.length-1];return i&&"gfmFootnoteDefinitionIndent"===i[1].type&&4===i[2].sliceSerialize(i[1],!0).length?t(e):n(e)}),"gfmFootnoteDefinitionIndent",5)},partial:!0};function sn(e,t,n){const r=this;let i=r.events.length;const o=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s;for(;i--;){const e=r.events[i][1];if("labelImage"===e.type){s=e;break}if("gfmFootnoteCall"===e.type||"labelLink"===e.type||"label"===e.type||"image"===e.type||"link"===e.type)break}return function(i){if(!s||!s._balanced)return n(i);const a=ie(r.sliceSerialize({start:s.end,end:r.now()}));if(94!==a.codePointAt(0)||!o.includes(a.slice(1)))return n(i);return e.enter("gfmFootnoteCallLabelMarker"),e.consume(i),e.exit("gfmFootnoteCallLabelMarker"),t(i)}}function an(e,t){let n=e.length;for(;n--;)if("labelImage"===e[n][1].type&&"enter"===e[n][0]){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const o={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},s={type:"chunkString",contentType:"string",start:Object.assign({},o.start),end:Object.assign({},o.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",o,t],["enter",s,t],["exit",s,t],["exit",o,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function cn(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o,s=0;return function(t){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(t),e.exit("gfmFootnoteCallLabelMarker"),a};function a(t){return 94!==t?n(t):(e.enter("gfmFootnoteCallMarker"),e.consume(t),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(a){if(s>999||93===a&&!o||null===a||91===a||de(a))return n(a);if(93===a){e.exit("chunkString");const o=e.exit("gfmFootnoteCallString");return i.includes(ie(r.sliceSerialize(o)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(a),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(a)}return de(a)||(o=!0),s++,e.consume(a),92===a?l:c}function l(t){return 91===t||92===t||93===t?(e.consume(t),s++,c):c(t)}}function ln(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o,s,a=0;return function(t){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(t),e.exit("gfmFootnoteDefinitionLabelMarker"),c};function c(t){return 94===t?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(t),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",l):n(t)}function l(t){if(a>999||93===t&&!s||null===t||91===t||de(t))return n(t);if(93===t){e.exit("chunkString");const n=e.exit("gfmFootnoteDefinitionLabelString");return o=ie(r.sliceSerialize(n)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(t),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return de(t)||(s=!0),a++,e.consume(t),92===t?u:l}function u(t){return 91===t||92===t||93===t?(e.consume(t),a++,l):l(t)}function h(t){return 58===t?(e.enter("definitionMarker"),e.consume(t),e.exit("definitionMarker"),i.includes(o)||i.push(o),ke(e,f,"gfmFootnoteDefinitionWhitespace")):n(t)}function f(e){return t(e)}}function un(e,t,n){return e.check(Ae,t,e.attempt(on,t,n))}function hn(e){e.exit("gfmFootnoteDefinition")}function fn(e){let t={}.singleTilde;const n={name:"strikethrough",tokenize:function(e,n,r){const i=this.previous,o=this.events;let s=0;return function(t){if(126===i&&"characterEscape"!==o[o.length-1][1].type)return r(t);return e.enter("strikethroughSequenceTemporary"),a(t)};function a(o){const c=we(i);if(126===o)return s>1?r(o):(e.consume(o),s++,a);if(s<2&&!t)return r(o);const l=e.exit("strikethroughSequenceTemporary"),u=we(o);return l._open=!u||2===u&&Boolean(c),l._close=!c||2===c&&Boolean(u),n(o)}},resolveAll:function(e,t){let n=-1;for(;++n<e.length;)if("enter"===e[n][0]&&"strikethroughSequenceTemporary"===e[n][1].type&&e[n][1]._close){let r=n;for(;r--;)if("exit"===e[r][0]&&"strikethroughSequenceTemporary"===e[r][1].type&&e[r][1]._open&&e[n][1].end.offset-e[n][1].start.offset===e[r][1].end.offset-e[r][1].start.offset){e[n][1].type="strikethroughSequence",e[r][1].type="strikethroughSequence";const i={type:"strikethrough",start:Object.assign({},e[r][1].start),end:Object.assign({},e[n][1].end)},o={type:"strikethroughText",start:Object.assign({},e[r][1].end),end:Object.assign({},e[n][1].start)},s=[["enter",i,t],["enter",e[r][1],t],["exit",e[r][1],t],["enter",o,t]],a=t.parser.constructs.insideSpan.null;a&&J(s,s.length,0,Ee(a,e.slice(r+1,n),t)),J(s,s.length,0,[["exit",o,t],["enter",e[n][1],t],["exit",e[n][1],t],["exit",i,t]]),J(e,r-1,n-r+3,s),n=r+s.length-2;break}}n=-1;for(;++n<e.length;)"strikethroughSequenceTemporary"===e[n][1].type&&(e[n][1].type="data");return e}};return null==t&&(t=!0),{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}}}class dn{constructor(){this.map=[]}add(e,t,n){!function(e,t,n,r){let i=0;if(0===n&&0===r.length)return;for(;i<e.map.length;){if(e.map[i][0]===t)return e.map[i][1]+=n,void e.map[i][2].push(...r);i+=1}e.map.push([t,n,r])}(this,e,t,n)}consume(e){if(this.map.sort((function(e,t){return e[0]-t[0]})),0===this.map.length)return;let t=this.map.length;const n=[];for(;t>0;)t-=1,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(const t of r)e.push(t);r=n.pop()}this.map.length=0}}function pn(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if("enter"===i[0])"tableContent"===i[1].type&&r.push("tableDelimiterMarker"===e[t+1][1].type?"left":"none");else if("tableContent"===i[1].type){if("tableDelimiterMarker"===e[t-1][1].type){const e=r.length-1;r[e]="left"===r[e]?"center":"right"}}else if("tableDelimiterRow"===i[1].type)break}else"enter"===i[0]&&"tableDelimiterRow"===i[1].type&&(n=!0);t+=1}return r}function gn(e,t,n){const r=this;let i,o=0,s=0;return function(e){let t=r.events.length-1;for(;t>-1;){const e=r.events[t][1].type;if("lineEnding"!==e&&"linePrefix"!==e)break;t--}const i=t>-1?r.events[t][1].type:null,o="tableHead"===i||"tableRow"===i?b:a;if(o===b&&r.parser.lazy[r.now().line])return n(e);return o(e)};function a(t){return e.enter("tableHead"),e.enter("tableRow"),function(e){if(124===e)return c(e);return i=!0,s+=1,c(e)}(t)}function c(t){return null===t?n(t):fe(t)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),h):n(t):pe(t)?ke(e,c,"whitespace")(t):(s+=1,i&&(i=!1,o+=1),124===t?(e.enter("tableCellDivider"),e.consume(t),e.exit("tableCellDivider"),i=!0,c):(e.enter("data"),l(t)))}function l(t){return null===t||124===t||de(t)?(e.exit("data"),c(t)):(e.consume(t),92===t?u:l)}function u(t){return 92===t||124===t?(e.consume(t),l):l(t)}function h(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter("tableDelimiterRow"),i=!1,pe(t)?ke(e,f,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(t):f(t))}function f(t){return 45===t||58===t?p(t):124===t?(i=!0,e.enter("tableCellDivider"),e.consume(t),e.exit("tableCellDivider"),d):x(t)}function d(t){return pe(t)?ke(e,p,"whitespace")(t):p(t)}function p(t){return 58===t?(s+=1,i=!0,e.enter("tableDelimiterMarker"),e.consume(t),e.exit("tableDelimiterMarker"),g):45===t?(s+=1,g(t)):null===t||fe(t)?k(t):x(t)}function g(t){return 45===t?(e.enter("tableDelimiterFiller"),m(t)):x(t)}function m(t){return 45===t?(e.consume(t),m):58===t?(i=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(t),e.exit("tableDelimiterMarker"),y):(e.exit("tableDelimiterFiller"),y(t))}function y(t){return pe(t)?ke(e,k,"whitespace")(t):k(t)}function k(n){return 124===n?f(n):(null===n||fe(n))&&i&&o===s?(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(n)):x(n)}function x(e){return n(e)}function b(t){return e.enter("tableRow"),v(t)}function v(n){return 124===n?(e.enter("tableCellDivider"),e.consume(n),e.exit("tableCellDivider"),v):null===n||fe(n)?(e.exit("tableRow"),t(n)):pe(n)?ke(e,v,"whitespace")(n):(e.enter("data"),w(n))}function w(t){return null===t||124===t||de(t)?(e.exit("data"),v(t)):(e.consume(t),92===t?E:w)}function E(t){return 92===t||124===t?(e.consume(t),w):w(t)}}function mn(e,t){let n,r,i,o=-1,s=!0,a=0,c=[0,0,0,0],l=[0,0,0,0],u=!1,h=0;const f=new dn;for(;++o<e.length;){const d=e[o],p=d[1];"enter"===d[0]?"tableHead"===p.type?(u=!1,0!==h&&(kn(f,t,h,n,r),r=void 0,h=0),n={type:"table",start:Object.assign({},p.start),end:Object.assign({},p.end)},f.add(o,0,[["enter",n,t]])):"tableRow"===p.type||"tableDelimiterRow"===p.type?(s=!0,i=void 0,c=[0,0,0,0],l=[0,o+1,0,0],u&&(u=!1,r={type:"tableBody",start:Object.assign({},p.start),end:Object.assign({},p.end)},f.add(o,0,[["enter",r,t]])),a="tableDelimiterRow"===p.type?2:r?3:1):!a||"data"!==p.type&&"tableDelimiterMarker"!==p.type&&"tableDelimiterFiller"!==p.type?"tableCellDivider"===p.type&&(s?s=!1:(0!==c[1]&&(l[0]=l[1],i=yn(f,t,c,a,void 0,i)),c=l,l=[c[1],o,0,0])):(s=!1,0===l[2]&&(0!==c[1]&&(l[0]=l[1],i=yn(f,t,c,a,void 0,i),c=[0,0,0,0]),l[2]=o)):"tableHead"===p.type?(u=!0,h=o):"tableRow"===p.type||"tableDelimiterRow"===p.type?(h=o,0!==c[1]?(l[0]=l[1],i=yn(f,t,c,a,o,i)):0!==l[1]&&(i=yn(f,t,l,a,o,i)),a=0):!a||"data"!==p.type&&"tableDelimiterMarker"!==p.type&&"tableDelimiterFiller"!==p.type||(l[3]=o)}for(0!==h&&kn(f,t,h,n,r),f.consume(t.events),o=-1;++o<t.events.length;){const e=t.events[o];"enter"===e[0]&&"table"===e[1].type&&(e[1]._align=pn(t.events,o))}return e}function yn(e,t,n,r,i,o){const s=1===r?"tableHeader":2===r?"tableDelimiter":"tableData";0!==n[0]&&(o.end=Object.assign({},xn(t.events,n[0])),e.add(n[0],0,[["exit",o,t]]));const a=xn(t.events,n[1]);if(o={type:s,start:Object.assign({},a),end:Object.assign({},a)},e.add(n[1],0,[["enter",o,t]]),0!==n[2]){const i=xn(t.events,n[2]),o=xn(t.events,n[3]),s={type:"tableContent",start:Object.assign({},i),end:Object.assign({},o)};if(e.add(n[2],0,[["enter",s,t]]),2!==r){const r=t.events[n[2]],i=t.events[n[3]];if(r[1].end=Object.assign({},i[1].end),r[1].type="chunkText",r[1].contentType="text",n[3]>n[2]+1){const t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[["exit",s,t]])}return void 0!==i&&(o.end=Object.assign({},xn(t.events,i)),e.add(i,0,[["exit",o,t]]),o=void 0),o}function kn(e,t,n,r,i){const o=[],s=xn(t.events,n);i&&(i.end=Object.assign({},s),o.push(["exit",i,t])),r.end=Object.assign({},s),o.push(["exit",r,t]),e.add(n+1,0,o)}function xn(e,t){const n=e[t],r="enter"===n[0]?"start":"end";return n[1][r]}const bn={name:"tasklistCheck",tokenize:function(e,t,n){const r=this;return function(t){if(null!==r.previous||!r._gfmTasklistFirstContentOfListItem)return n(t);return e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(t),e.exit("taskListCheckMarker"),i};function i(t){return de(t)?(e.enter("taskListCheckValueUnchecked"),e.consume(t),e.exit("taskListCheckValueUnchecked"),o):88===t||120===t?(e.enter("taskListCheckValueChecked"),e.consume(t),e.exit("taskListCheckValueChecked"),o):n(t)}function o(t){return 93===t?(e.enter("taskListCheckMarker"),e.consume(t),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),s):n(t)}function s(r){return fe(r)?t(r):pe(r)?e.check({tokenize:vn},t,n)(r):n(r)}}};function vn(e,t,n){return ke(e,(function(e){return null===e?n(e):t(e)}),"whitespace")}function wn(e){return ee([{text:Jt},{document:{91:{name:"gfmFootnoteDefinition",tokenize:ln,continuation:{tokenize:un},exit:hn}},text:{91:{name:"gfmFootnoteCall",tokenize:cn},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:sn,resolveTo:an}}},fn(),{flow:{null:{name:"table",tokenize:gn,resolveAll:mn}}},{text:{91:bn}}])}function En(e,t){const n=String(e);if("string"!=typeof t)throw new TypeError("Expected character");let r=0,i=n.indexOf(t);for(;-1!==i;)r++,i=n.indexOf(t,i+t.length);return r}const Sn=function(e){if(null==e)return _n;if("function"==typeof e)return Cn(e);if("object"==typeof e)return Array.isArray(e)?function(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=Sn(e[n]);return Cn(r);function r(...e){let n=-1;for(;++n<t.length;)if(t[n].apply(this,e))return!0;return!1}}(e):function(e){const t=e;return Cn(n);function n(n){const r=n;let i;for(i in e)if(r[i]!==t[i])return!1;return!0}}(e);if("string"==typeof e)return function(e){return Cn(t);function t(t){return t&&t.type===e}}(e);throw new Error("Expected function, string, or object as test")};function Cn(e){return function(t,n,r){return Boolean(function(e){return null!==e&&"object"==typeof e&&"type"in e}(t)&&e.call(this,t,"number"==typeof n?n:void 0,r||void 0))}}function _n(){return!0}const An=[],In=!0,Tn=!1;function On(e,t,n,r){let i;i=t;const o=Sn(i);!function e(t,r,i){const s=t&&"object"==typeof t?t:{};if("string"==typeof s.type){const e="string"==typeof s.tagName?s.tagName:"string"==typeof s.name?s.name:void 0;Object.defineProperty(a,"name",{value:"node ("+t.type+(e?"<"+e+">":"")+")"})}return a;function a(){let s,a,c,l=An;if(o(t,r,i[i.length-1]||void 0)&&(l=function(e){if(Array.isArray(e))return e;if("number"==typeof e)return[In,e];return null==e?An:[e]}(n(t,i)),l[0]===Tn))return l;if("children"in t&&t.children){const n=t;if(n.children&&"skip"!==l[0])for(a=0,c=i.concat(n);a>-1&&a<n.children.length;){const t=n.children[a];if(s=e(t,a,c)(),s[0]===Tn)return s;a="number"==typeof s[1]?s[1]:a+1}}return l}}(e,void 0,[])()}function Dn(e,t,n){const r=Sn((n||{}).ignore||[]),i=function(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const e=n[r];t.push([Ln(e[0]),Pn(e[1])])}return t}(t);let o=-1;for(;++o<i.length;)On(e,"text",s);function s(e,t){let n,s=-1;for(;++s<t.length;){const e=t[s],i=n?n.children:void 0;if(r(e,i?i.indexOf(e):void 0,n))return;n=e}if(n)return function(e,t){const n=t[t.length-1],r=i[o][0],s=i[o][1];let a=0;const c=n.children.indexOf(e);let l=!1,u=[];r.lastIndex=0;let h=r.exec(e.value);for(;h;){const n=h.index,i={index:h.index,input:h.input,stack:[...t,e]};let o=s(...h,i);if("string"==typeof o&&(o=o.length>0?{type:"text",value:o}:void 0),!1===o?r.lastIndex=n+1:(a!==n&&u.push({type:"text",value:e.value.slice(a,n)}),Array.isArray(o)?u.push(...o):o&&u.push(o),a=n+h[0].length,l=!0),!r.global)break;h=r.exec(e.value)}l?(a<e.value.length&&u.push({type:"text",value:e.value.slice(a)}),n.children.splice(c,1,...u)):u=[e];return c+u.length}(e,t)}}function Ln(e){return"string"==typeof e?new RegExp(function(e){if("string"!=typeof e)throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}(e),"g"):e}function Pn(e){return"function"==typeof e?e:function(){return e}}function Mn(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function Rn(e){this.config.enter.autolinkProtocol.call(this,e)}function Fn(e){this.config.exit.autolinkProtocol.call(this,e)}function Nn(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function zn(e){this.config.exit.autolinkEmail.call(this,e)}function jn(e){this.exit(e)}function Bn(e){Dn(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,$n],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,Un]],{ignore:["link","linkReference"]})}function $n(e,t,n,r,i){let o="";if(!Vn(i))return!1;if(/^w/i.test(t)&&(n=t+n,t="",o="http://"),!function(e){const t=e.split(".");if(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))return!1;return!0}(n))return!1;const s=function(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const i=En(e,"(");let o=En(e,")");for(;-1!==r&&i>o;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),o++;return[e,n]}(n+r);if(!s[0])return!1;const a={type:"link",title:null,url:o+t+s[0],children:[{type:"text",value:t+s[0]}]};return s[1]?[a,{type:"text",value:s[1]}]:a}function Un(e,t,n,r){return!(!Vn(r,!0)||/[-\d_]$/.test(n))&&{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function Vn(e,t){const n=e.input.charCodeAt(e.index-1);return(0===e.index||me(n)||ge(n))&&(!t||47!==n)}function Hn(){this.buffer()}function qn(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function Yn(){this.buffer()}function Qn(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function Kn(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=ie(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Wn(e){this.exit(e)}function Xn(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=ie(this.sliceSerialize(e)).toLowerCase(),n.label=t}function Jn(e){this.exit(e)}function Gn(e){this.enter({type:"delete",children:[]},e)}function Zn(e){this.exit(e)}function er(e){const t=e._align;this.enter({type:"table",align:t.map((function(e){return"none"===e?null:e})),children:[]},e),this.data.inTable=!0}function tr(e){this.exit(e),this.data.inTable=void 0}function nr(e){this.enter({type:"tableRow",children:[]},e)}function rr(e){this.exit(e)}function ir(e){this.enter({type:"tableCell",children:[]},e)}function or(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,sr));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function sr(e,t){return"|"===t?t:e}function ar(e){const t=this.stack[this.stack.length-2];t.type,t.checked="taskListCheckValueChecked"===e.type}function cr(e){const t=this.stack[this.stack.length-2];if(t&&"listItem"===t.type&&"boolean"==typeof t.checked){const e=this.stack[this.stack.length-1];e.type;const n=e.children[0];if(n&&"text"===n.type){const r=t.children;let i,o=-1;for(;++o<r.length;){const e=r[o];if("paragraph"===e.type){i=e;break}}i===e&&(n.value=n.value.slice(1),0===n.value.length?e.children.shift():e.position&&n.position&&"number"==typeof n.position.start.offset&&(n.position.start.column++,n.position.start.offset++,e.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function lr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ur,hr={exports:{}};var fr=(ur||(ur=1,function(e){!function(){var t;function n(e){for(var t,n,r,i,o=1,s=[].slice.call(arguments),a=0,c=e.length,l="",u=!1,h=!1,f=function(){return s[o++]},d=function(){for(var n="";/\d/.test(e[a]);)n+=e[a++],t=e[a];return n.length>0?parseInt(n):null};a<c;++a)if(t=e[a],u)switch(u=!1,"."==t?(h=!1,t=e[++a]):"0"==t&&"."==e[a+1]?(h=!0,t=e[a+=2]):h=!0,i=d(),t){case"b":l+=parseInt(f(),10).toString(2);break;case"c":l+="string"==typeof(n=f())||n instanceof String?n:String.fromCharCode(parseInt(n,10));break;case"d":l+=parseInt(f(),10);break;case"f":r=String(parseFloat(f()).toFixed(i||6)),l+=h?r:r.replace(/^0/,"");break;case"j":l+=JSON.stringify(f());break;case"o":l+="0"+parseInt(f(),10).toString(8);break;case"s":l+=f();break;case"x":l+="0x"+parseInt(f(),10).toString(16);break;case"X":l+="0x"+parseInt(f(),10).toString(16).toUpperCase();break;default:l+=t}else"%"===t?u=!0:l+=t;return l}(t=e.exports=n).format=n,t.vsprintf=function(e,t){return n.apply(null,[e].concat(t))},"undefined"!=typeof console&&"function"==typeof console.log&&(t.printf=function(){console.log(n.apply(null,arguments))})}()}(hr)),hr.exports),dr=lr(fr);const pr=Object.assign(gr(Error),{eval:gr(EvalError),range:gr(RangeError),reference:gr(ReferenceError),syntax:gr(SyntaxError),type:gr(TypeError),uri:gr(URIError)});function gr(e){return t.displayName=e.displayName||e.name,t;function t(t,...n){const r=t?dr(t,...n):t;return new e(r)}}const mr={}.hasOwnProperty,yr={yaml:"-",toml:"+"};function kr(e){const t=[];let n=-1;const r=Array.isArray(e)?e:e?[e]:["yaml"];for(;++n<r.length;)t[n]=xr(r[n]);return t}function xr(e){let t=e;if("string"==typeof t){if(!mr.call(yr,t))throw pr("Missing matter definition for `%s`",t);t={type:t,marker:yr[t]}}else if("object"!=typeof t)throw pr("Expected matter to be an object, not `%j`",t);if(!mr.call(t,"type"))throw pr("Missing `type` in matter `%j`",t);if(!mr.call(t,"fence")&&!mr.call(t,"marker"))throw pr("Missing `marker` or `fence` in matter `%j`",t);return t}function br(e){const t=kr(e),n={};let r=-1;for(;++r<t.length;){const e=t[r],i=wr(e,"open").charCodeAt(0),o=vr(e),s=n[i];Array.isArray(s)?s.push(o):n[i]=[o]}return{flow:n}}function vr(e){const t=e.anywhere,n=e.type,r=n+"Fence",i=r+"Sequence",o=n+"Value",s={tokenize:function(e,t,n){let o=0;return function(t){if(t===a.charCodeAt(o))return e.enter(r),e.enter(i),s(t);return n(t)};function s(t){return o===a.length?(e.exit(i),pe(t)?(e.enter("whitespace"),c(t)):l(t)):t===a.charCodeAt(o++)?(e.consume(t),s):n(t)}function c(t){return pe(t)?(e.consume(t),c):(e.exit("whitespace"),l(t))}function l(i){return null===i||fe(i)?(e.exit(r),t(i)):n(i)}},partial:!0};let a,c=0;return{tokenize:function(l,u,h){const f=this;return function(o){const s=f.now();if(1===s.column&&(1===s.line||t)&&(a=wr(e,"open"),c=0,o===a.charCodeAt(c)))return l.enter(n),l.enter(r),l.enter(i),d(o);return h(o)};function d(e){return c===a.length?(l.exit(i),pe(e)?(l.enter("whitespace"),p(e)):g(e)):e===a.charCodeAt(c++)?(l.consume(e),d):h(e)}function p(e){return pe(e)?(l.consume(e),p):(l.exit("whitespace"),g(e))}function g(t){return fe(t)?(l.exit(r),l.enter("lineEnding"),l.consume(t),l.exit("lineEnding"),a=wr(e,"close"),c=0,l.attempt(s,x,m)):h(t)}function m(e){return null===e||fe(e)?k(e):(l.enter(o),y(e))}function y(e){return null===e||fe(e)?(l.exit(o),k(e)):(l.consume(e),y)}function k(e){return null===e?h(e):(l.enter("lineEnding"),l.consume(e),l.exit("lineEnding"),l.attempt(s,x,m))}function x(e){return l.exit(n),u(e)}},concrete:!0}}function wr(e,t){return e.marker?Er(e.marker,t).repeat(3):Er(e.fence,t)}function Er(e,t){return"string"==typeof e?e:e[t]}function Sr(e){const t=kr(e),n={},r={};let i=-1;for(;++i<t.length;){const e=t[i];n[e.type]=Cr(e),r[e.type]=_r,r[e.type+"Value"]=Ar}return{enter:n,exit:r}}function Cr(e){return function(t){this.enter({type:e.type,value:""},t),this.buffer()}}function _r(e){const t=this.resume(),n=this.stack[this.stack.length-1];this.exit(e),n.value=t.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,"")}function Ar(e){this.config.enter.data.call(this,e),this.config.exit.data.call(this,e)}class Ir{annotations;constructor(e=[]){this.annotations=e}pushText(e){e.length>0&&this.annotations.push({text:e})}pushMarkup(e,t){this.annotations.push({markup:e,interpretAs:t})}extend(e){for(const t of e.annotations)"text"in t?this.pushText(t.text):this.pushMarkup(t.markup,t.interpretAs)}optimize(){const e=[];for(const t of this.annotations){if("text"in t&&0===t.text.length||"markup"in t&&0===t.markup.length&&!t.interpretAs)continue;const n=e.at(-1);void 0===n?e.push(t):"text"in n&&"text"in t?n.text+=t.text:"markup"in n&&"markup"in t?(n.markup+=t.markup,n.interpretAs&&t.interpretAs?n.interpretAs+=t.interpretAs:t.interpretAs&&(n.interpretAs=t.interpretAs)):e.push(t)}for(const t of e)"markup"in t&&t.interpretAs&&(t.interpretAs=t.interpretAs.replace(/\n{3,}/g,"\n\n"));for(let t=e.at(-1);t&&"markup"in t;t=e.at(-1))e.pop();let t=0;for(let n=e.at(0);n&&"markup"in n;n=e.at(0))t+=n.markup.length,e.shift();return this.annotations=e,t}extractSlice(e,t){let n=0;for(;n<this.annotations.length;n++){const r=this.annotations[n],i="text"in r?r.text:r.markup;if(!(i.length<e))break;e-=i.length,t-=i.length}let r="";for(;n<this.annotations.length;n++){const i=this.annotations[n];if("text"in i?r+=i.text:(r.length<e&&(e-=i.markup.length,e+=i.interpretAs?.length||0),r+=i.interpretAs??"",t-=i.markup.length,t+=i.interpretAs?.length||0),r.length>=t)return r.slice(e,t).trim()}return null}length(){return this.annotations.reduce(((e,t)=>"text"in t?e+t.text.length:"markup"in t?e+t.markup.length:e),0)}stringify(){return JSON.stringify({annotation:this.annotations})}}const Tr=-2,Or=0,Dr=null,Lr=32,Pr=91;function Mr(e){return null!=e&&(e<Or||e===Lr)}function Rr(e){return null!=e&&e<Tr}function Fr(e={}){const t=e.aliasDivider||"|",n="[[",r="]]";return{text:{[Pr]:{name:"wikilink",tokenize:function(e,i,o){let s=!1,a=!1,c=0,l=0,u=0;return function(t){return t!==n.charCodeAt(l)?o(t):(e.enter("wikiLink"),e.enter("wikiLinkMarker"),h(t))};function h(t){return 2===l?(e.exit("wikiLinkMarker"),function(t){if(Rr(t)||t===Dr)return o(t);return e.enter("wikiLinkData"),e.enter("wikiLinkTarget"),f(t)}(t)):t!==n.charCodeAt(l)?o(t):(e.consume(t),l++,h)}function f(n){return n===t.charCodeAt(c)?s?(e.exit("wikiLinkTarget"),e.enter("wikiLinkAliasMarker"),d(n)):o(n):n===r.charCodeAt(u)?s?(e.exit("wikiLinkTarget"),e.exit("wikiLinkData"),e.enter("wikiLinkMarker"),g(n)):o(n):Rr(n)||n===Dr?o(n):(Mr(n)||(s=!0),e.consume(n),f)}function d(n){return c===t.length?(e.exit("wikiLinkAliasMarker"),e.enter("wikiLinkAlias"),p(n)):n!==t.charCodeAt(c)?o(n):(e.consume(n),c++,d)}function p(t){return t===r.charCodeAt(u)?a?(e.exit("wikiLinkAlias"),e.exit("wikiLinkData"),e.enter("wikiLinkMarker"),g(t)):o(t):Rr(t)||t===Dr?o(t):(Mr(t)||(a=!0),e.consume(t),p)}function g(t){return 2===u?(e.exit("wikiLinkMarker"),e.exit("wikiLink"),i(t)):t!==r.charCodeAt(u)?o(t):(e.consume(t),u++,g)}}}}}}function Nr(e={}){let t;function n(e){const t=e.at(-1);if(t&&"wikiLink"===t.type)return t;throw new Error("Expected wikiLink node")}return{enter:{wikiLink:function(e){t={type:"wikiLink",children:[]},this.enter(t,e)}},exit:{wikiLinkTarget:function(e){const t=this.sliceSerialize(e),r=n(this.stack);var i;r.data={value:t,link:(i=t,i.replace(/ /g,"_").toLowerCase())},r.children=[{type:"text",value:t,position:{start:e.start,end:e.end}}]},wikiLinkAlias:function(e){const t=this.sliceSerialize(e),r=n(this.stack);null!=r.data&&(r.data.value=t),r.children=[{type:"text",value:t,position:{start:e.start,end:e.end}}]},wikiLink:function(e){this.exit(e)}}}}const zr=/\\[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]/g;class jr{raw;output;output_start;output_end;offset;range;constructor(e,t){this.raw=e,this.output=new Ir,this.offset=0,this.range=t}visitText(e){const t=e?.position?.start.offset,n=e?.position?.end.offset;if(null==t||null==n)throw Error("Markdown parsing: unknown position for text node");if(function(e,t,n){const[r,...i]=e.replace(/\n$/,"").split("\n"),[o,...s]=t.replace(/\n$/,"").split("\n");if(i.length!==s.length)throw console.error("Invalid number of lines",i.length,s.length,e,t),Error("Markdown parsing: invalid number of lines");Br(r,n);for(let e=0;e<i.length;e++){const t=i[e],r=s[e];let o=t.length-r.length;for(const e of t.matchAll(zr))o-=1;if(o<0)throw console.error("Invalid indent",o,t,r),Error("Markdown parsing: invalid indent");n.pushText("\n"),n.pushMarkup(" ".repeat(o)),Br(t.substring(o),n)}e.endsWith("\n")&&n.pushText("\n")}(this.raw.slice(t,n),e.value,this.output),this.output.length()!==n-(this.output_start||0))throw console.error("Invalid output length",this.output.length(),n,JSON.stringify(e,void 0," ")),Error("Markdown parsing: invalid output length");this.offset=n}visitRoot(e){if(null==e.position)throw Error("Markdown parsing: unknown position");const t=e?.position?.start.offset,n=e?.position?.end.offset;if(null==t||null==n)throw Error("Markdown parsing: unknown position for text node");if(this.range&&function(e){return["blockquote","code","heading","html","list","paragraph","table","thematicBreak"].contains(e.type)}(e)){if(n<=this.range.from-1)return;if(t>=this.range.to+1)return;t<=this.range.from&&this.range.from<=n&&(this.output=new Ir,this.offset=t,this.output_start=this.offset,console.debug("Start from",this.output_start)),t<=this.range.to&&this.range.to<=n&&(this.output_end=n,console.debug("End at",this.output_end))}switch(this.offset<t&&(this.output.pushMarkup(" ".repeat(t-this.offset)),this.offset=t),e.type){case"text":this.visitText(e);break;case"yaml":case"code":case"html":case"image":case"imageReference":case"footnoteReference":case"definition":break;case"strong":case"emphasis":case"delete":case"footnoteDefinition":case"linkReference":e.children.forEach((e=>this.visitRoot(e)));break;case"list":case"heading":case"tableRow":e.children.forEach((e=>this.visitRoot(e))),this.output.pushMarkup("","\n\n");break;case"inlineCode":this.output.pushMarkup($r(t,n),e.value),this.offset=n;break;case"break":this.output.pushMarkup($r(t,n),"\n"),this.offset=n;break;case"blockquote":case"paragraph":e.children.length>0&&(e.children.forEach((e=>this.visitRoot(e))),this.output.pushMarkup("","\n\n"));break;case"listItem":e.children.length>0&&(this.output.pushMarkup("","• "),e.children.forEach((e=>this.visitRoot(e))));break;case"link":case"wikiLink":e.children?e.children.forEach((e=>this.visitRoot(e))):(this.output.pushMarkup($r(t,n),"DUMMY"),this.offset=n);break;case"table":this.output.pushMarkup("","\n"),e.children.forEach((e=>this.visitRoot(e)));break;case"tableCell":e.children.forEach((e=>this.visitRoot(e))),this.output.pushMarkup("","\n");break;case"thematicBreak":this.output.pushMarkup($r(t,n),"\n\n"),this.offset=n}this.offset<n&&(this.output.pushMarkup(" ".repeat(n-this.offset)),this.offset=n)}}function Br(e,t){let n=0;for(const r of e.matchAll(zr)){const i=r.index;t.pushText(e.slice(n,i)),t.pushMarkup(" ",""),t.pushText(e.slice(i+1,i+2)),n=i+2}t.pushText(e.slice(n))}function $r(e,t){return" ".repeat(t-e)}class Ur extends e.Plugin{settings;statusBarItem;isLoading=!1;logs=[];settingTab;async onload(){await this.loadSettings(),this.settingTab=new L(this.app,this),this.addSettingTab(this.settingTab),this.statusBarItem=this.addStatusBarItem(),this.statusBarItem.addClass("status-bar-item-icon","lt-status-bar-btn"),this.statusBarItem.onclick=()=>this.handleStatusBarClick(),this.setStatusBarReady(),this.registerEditorExtension(function(e){return[$,M(e),H(e),q]}(this)),this.registerCommands(),this.registerMenuItems();try{let e=this.app.metadataTypeManager;e.setType("lt-language","text"),e.setType("lt-picky","checkbox"),e.setType("lt-autoCheck","checkbox"),e.setType("lt-dictionary","multitext"),e.setType("lt-disabledRules","multitext"),e.setType("lt-disabledCategories","multitext")}catch{console.error("Failed to set metadata types")}const e=new Set(this.settings.dictionary.map((e=>e.trim())));e.delete(""),this.settings.dictionary=[...e].sort(_),this.syncDictionary(),await this.saveSettings()}onunload(){this.logs=[],this.isLoading=!1}registerCommands(){this.addCommand({id:"check",name:"Check text",icon:"spell-check",editorCallback:(t,n)=>{const r=t.cm;this.runDetection(r).catch((e=>console.error(e))).then((t=>{t||new e.Notice("No suggestions found.")}))}}),this.addCommand({id:"toggle-auto-check",name:"Toggle automatic checking",icon:"uppercase-lowercase-a",callback:async()=>{this.settings.shouldAutoCheck=!this.settings.shouldAutoCheck,await this.saveSettings()}}),this.addCommand({id:"clear",name:"Clear suggestions",icon:"cross",editorCallback:e=>{e.cm.dispatch({effects:[N.of(null)]})}}),this.addCommand({id:"accept-all",name:"Accept all suggestions",icon:"circle-check-big",editorCallback:e=>{const t=e.cm,n=[],r=[];t.state.field($).between(0,1/0,((e,t,i)=>{i.spec?.underline?.replacements?.length&&(n.push({from:e,to:t,insert:i.spec.underline.replacements[0]}),r.push(z.of({from:e,to:t})))})),t.dispatch({changes:n,effects:r})}}),this.addCommand({id:"next",name:"Jump to next suggestion",icon:"chevron-right",editorCheckCallback:(e,t)=>{const n=t.cm,r=t.posToOffset(t.getCursor());let i=null;if(n.state.field($).between(r+1,1/0,((e,t)=>{(!i||i.from>e)&&(i={from:e,to:t})})),e)return null!=i;null!=i&&n.dispatch({selection:{anchor:i.from,head:i.to}})}});for(let e=1;e<=8;e++)this.addCommand(this.applySuggestionCommand(e));this.addCommand({id:"synonyms",name:"Show synonyms",icon:"square-stack",editorCheckCallback:(e,t)=>this.showSynonyms(t,e)})}applySuggestionCommand(e){return{id:`accept-${e}`,name:`Accept suggestion ${e}`,icon:"circle-check",editorCheckCallback(t,n){const r=n.cm,i=n.posToOffset(n.getCursor()),o=[];r.state.field($).between(i,i,((e,t,n)=>{o.push({from:e,to:t,value:n})}));const s=1===o.length&&o[0].value.spec?.underline?.replacements?.length>=e;if(t)return s;if(!s)return;const{from:a,to:c,value:l}=o[0],u={from:a,to:c,insert:l.spec.underline.replacements[e-1]};r.dispatch({changes:[u],effects:[z.of({from:a,to:c})]})}}}registerMenuItems(){this.registerEvent(this.app.workspace.on("editor-menu",((e,t,n)=>{console.debug(e);const r=t.cm;this.populateSuggestionMenu(e,r),this.showSynonyms(t,!0)&&e.addItem((e=>{e.setTitle("Synonyms"),e.setIcon("square-stack"),e.setSection("spellcheck"),e.onClick((()=>this.showSynonyms(t)))}))})))}populateSuggestionMenu(e,t){const n=t.state.field($),r=t.state.selection.main;let i=!1;const o=n.iter(r.from);for(;null!=o.value&&o.from<=r.to;){i=!0;const n=o.value.spec.underline;e.addItem((e=>{e.setTitle(`LanguageTool (${n.text})`),e.setIcon("spell-check"),e.setSection("spellcheck");const r=e.setSubmenu();this.populateSuggestionSubmenu(r,n,o,t)})),o.next()}return i}populateSuggestionSubmenu(t,n,r,i){(n.message||n.title)&&(t.addItem((e=>{let t=new DocumentFragment;t.appendChild(createDiv({cls:"lt-menu-info"},(e=>{n.title&&e.createDiv({text:n.title,cls:"lt-menu-title"}),n.message&&e.createDiv({text:n.message,cls:"lt-menu-message"})}))),e.setIsLabel(!0),e.setTitle(t)})),t.addSeparator());for(const e of n.replacements.slice(0,8))t.addItem((t=>{t.setTitle(e?JSON.stringify(e):"(delete)"),t.onClick((()=>{i.dispatch({changes:{...r,insert:e},effects:[z.of(r)]})}))}));t.addSeparator(),"TYPOS"===n.categoryId?t.addItem((e=>{e.setTitle("Add to dictionary"),e.setIcon("plus-with-circle"),e.onClick((async()=>{this.settings.dictionary.push(n.text),await this.syncDictionary(),i.dispatch({effects:[j.of((e=>e.text===n.text))]})}))})):(t.addItem((e=>{e.setTitle("Ignore suggestion"),e.setIcon("cross"),e.onClick((()=>{i.dispatch({effects:[z.of(r)]})}))})),n.ruleId&&"SYNONYMS"!==n.ruleId&&t.addItem((t=>{t.setTitle("Disable rule"),t.setIcon("circle-off"),t.onClick((()=>{this.settings.disabledRules?this.settings.disabledRules+=","+n.ruleId:this.settings.disabledRules=n.ruleId,this.saveSettings(),i.dispatch({effects:[j.of((e=>e.ruleId===n.ruleId))]})}));const r=t.dom;e.setTooltip(r,`${n.categoryId} > ${n.ruleId}`)})))}showSynonyms(t,n=!1){if(!this.settings.synonyms||!(this.settings.synonyms in x))return!1;const r=x[this.settings.synonyms];if(!r)return!1;const i=t.cm,o=i.state.selection.main;if(o.empty)return!1;const s=i.state.sliceDoc(i.state.selection.main.from,i.state.selection.main.to);if(s.match(/[\s\.]/))return!1;if(n)return!0;const a=i.state.doc.lineAt(o.from),c=a.text.slice(0,o.from-a.from).lastIndexOf(".")+1,l=a.text.slice(c);let u=l.trimStart();const h=a.from+c+l.length-u.length,f={from:o.from-h,to:o.to-h};u=u.trimEnd();const d=u.indexOf(".");return-1!==d&&(u=u.slice(0,d+1)),r.query(u,f).then((e=>i.dispatch({effects:[F.of({text:s,range:o,title:"Synonyms",message:"",categoryId:"SYNONYMS",ruleId:"SYNONYMS",replacements:e})]}))).catch((t=>{console.error(t),this.pushLogs(t),new e.Notice(t.message,3e4)})),!0}setStatusBarReady(){this.isLoading=!1,e.setIcon(this.statusBarItem,"spell-check")}setStatusBarWorking(){this.isLoading||(this.isLoading=!0,e.setIcon(this.statusBarItem,"sync-small"))}handleStatusBarClick(){const t=this.statusBarItem.getBoundingClientRect(),n=this.statusBarItem.getBoundingClientRect();(new e.Menu).addItem((t=>{t.setTitle("Check text"),t.setIcon("spell-check"),t.onClick((async()=>{const t=this.app.workspace.getActiveViewOfType(e.MarkdownView);if(t&&"source"===t.getMode()){const n=t.editor.cm;await this.runDetection(n)||new e.Notice("No suggestions found.")}}))})).addItem((e=>{e.setTitle(this.settings.shouldAutoCheck?"Disable automatic checking":"Enable automatic checking"),e.setIcon("uppercase-lowercase-a"),e.onClick((async()=>{this.settings.shouldAutoCheck=!this.settings.shouldAutoCheck,await this.saveSettings()}))})).addItem((t=>{t.setTitle("Clear suggestions"),t.setIcon("cross"),t.onClick((()=>{const t=this.app.workspace.getActiveViewOfType(e.MarkdownView);if(!t)return;t.editor.cm.dispatch({effects:[N.of(null)]})}))})).showAtPosition({x:n.right+5,y:(t?.top||0)-5})}getActiveFileSettings(){const e=this.app.workspace.getActiveFile(),t=e&&this.app.metadataCache.getFileCache(e);if(null!=t?.frontmatter){const e=t.frontmatter["lt-language"]??t.frontmatter.lt_language,n=t.frontmatter["lt-picky"],r=t.frontmatter["lt-autoCheck"],i=t.frontmatter["lt-dictionary"],o=t.frontmatter["lt-disabledRules"],s=t.frontmatter["lt-disabledCategories"];let a={...this.settings};return"string"==typeof e&&(a.staticLanguage=e),"boolean"==typeof r&&(a.shouldAutoCheck=r),"boolean"==typeof n&&(a.pickyMode=n),Array.isArray(i)&&(a.dictionary=i),Array.isArray(o)&&o.length&&(a.disabledRules+=","+o.join(",")),Array.isArray(s)&&s.length&&(a.disabledCategories+=","+s.join(",")),a}return this.settings}async runDetection(t,n){let r=this.getActiveFileSettings();const i=t.state.selection.main;n||i.empty||(n={...i});const o=t.state.sliceDoc();if(!o.trim())return!1;let s,a;try{this.setStatusBarWorking();let{offset:t,annotations:i}=await async function(e,t){const n=zt(e,{extensions:[wn(),br(["yaml"]),Fr({aliasDivider:"|"})],mdastExtensions:[[{transforms:[Bn],enter:{literalAutolink:Mn,literalAutolinkEmail:Rn,literalAutolinkHttp:Rn,literalAutolinkWww:Rn},exit:{literalAutolink:jn,literalAutolinkEmail:zn,literalAutolinkHttp:Fn,literalAutolinkWww:Nn}},{enter:{gfmFootnoteCallString:Hn,gfmFootnoteCall:qn,gfmFootnoteDefinitionLabelString:Yn,gfmFootnoteDefinition:Qn},exit:{gfmFootnoteCallString:Kn,gfmFootnoteCall:Wn,gfmFootnoteDefinitionLabelString:Xn,gfmFootnoteDefinition:Jn}},{canContainEols:["delete"],enter:{strikethrough:Gn},exit:{strikethrough:Zn}},{enter:{table:er,tableData:ir,tableHeader:ir,tableRow:nr},exit:{codeText:or,table:tr,tableData:rr,tableHeader:rr,tableRow:rr}},{exit:{taskListCheckValueChecked:ar,taskListCheckValueUnchecked:ar,paragraph:cr}}],Sr(["yaml"]),Nr()]}),r=new jr(e,t);try{n.children.forEach((e=>r.visitRoot(e)))}catch(e){throw console.error("Error while parsing markdown:\n",JSON.stringify(n,void 0," ")),e}return{offset:r.output_start??0,annotations:r.output}}(o,n);if(t+=i.optimize(),0===i.length())return!1;i.length()>500&&(a=new e.Notice("Checking spelling...",3e4)),console.info(`Checking ${i.length()} characters...`),console.debug("Text",JSON.stringify(i,void 0," ")),s=await async function(e,t,n){const r=n.stringify(),i=e.staticLanguage??"auto",o={data:r,language:i,enabledOnly:"false",level:e.pickyMode?"picky":"default"};e.motherTongue&&(o.motherTongue=e.motherTongue),e.enabledCategories&&(o.enabledCategories=e.enabledCategories),e.disabledCategories&&(o.disabledCategories=e.disabledCategories),e.enabledRules&&(o.enabledRules=e.enabledRules),e.disabledRules&&(o.disabledRules=e.disabledRules),"auto"==i&&(o.preferredVariants=Object.values(e.languageVariety).join(",")),"standard"!==T(e.serverUrl)&&e.apikey&&e.username&&(o.username=e.username,o.apiKey=e.apikey);const s=await b({url:`${e.serverUrl}/v2/check`,method:"POST",body:new URLSearchParams(o).toString(),headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}});if(null==s.json)throw new Error("Error processing response from LanguageTool.");return w("$.matches[*]",s.json).map((e=>{const r=v("$.offset@number()",e),i=r+v("$.length@number()",e);return{range:{from:t+r,to:t+i},text:n.extractSlice(r,i)||"",title:v("$.shortMessage@string()",e),message:v("$.message@string()",e),replacements:w("$.replacements[*].value@string()",e),categoryId:v("$.rule.category.id@string()",e),ruleId:v("$.rule.id@string()",e)}}))}(r,t,i),n&&(n={from:t,to:t+i.length()})}catch(t){return console.error(t),t instanceof Error&&(this.pushLogs(t),new e.Notice(t.message,3e4)),!0}finally{this.setStatusBarReady(),a&&a.hide()}const c=[];if(n?c.push(z.of(n)):c.push(N.of(null)),s){const e=r.dictionary;for(const n of s)n.range.to>t.state.doc.length||"TYPOS"===n.categoryId&&e.includes(n.text)||c.push(F.of(n))}return c.length&&t.dispatch({effects:c}),console.info(`Found ${c.length-1} suggestions.`),c.length>1}async pushLogs(e){const t=`${(new Date).toLocaleString()}:\nError: '${e.message}'\nSettings: ${JSON.stringify({...this.settings,username:"REDACTED",apikey:"REDACTED"})}\n`;this.logs.push(t),this.logs.length>10&&this.logs.shift()}async loadSettings(){this.settings=Object.assign({},O,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}async onExternalSettingsChange(){this.settingTab.notifyEndpointChange(this.settings)}async syncDictionary(){if(!this.settings.syncDictionary||"premium"!==T(this.settings.serverUrl))return await this.saveSettings(),!1;try{const e=new Set(this.settings.remoteDictionary);let t=new Set(this.settings.dictionary),n=new Set(await async function(e){if(null==e.username||null==e.apikey)throw Error("Syncing words is only supported for premium users");try{return w("$.words[*]@string()",(await b({url:E(`${e.serverUrl}/v2/words`,{username:e.username,apiKey:e.apikey,limit:"1000"}).href})).json)}catch(e){throw new Error(`Requesting words failed\n${e}`)}}(this.settings)),r=C(e,t);r=function(e,t){const n=new Set;for(const r of t)e.has(r)&&n.add(r);return n}(r,n);for(const e of r)await k(this.settings,e);const i=C(e,n);n=C(n,r),t=C(t,i);const o=C(t,n);for(const e of o)await y(this.settings,e);const s=function(e,t){const n=new Set(e);for(const e of t)n.add(e);return n}(n,t),a=new Set(this.settings.dictionary).size!==s.size;return this.settings.dictionary=[...s].sort(_),this.settings.remoteDictionary=[...s].sort(_),await this.saveSettings(),a}catch(t){this.pushLogs(t),new e.Notice(t.message,3e4),console.error("Failed sync spellcheck with LanguageTool",t)}return await this.saveSettings(),!1}}module.exports=Ur;
|
||
|
||
|
||
/* nosourcemap */ |