PHP and Javascript implementations of a simple markdown parser
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

spreadsheet.min.js 39KB

1
  1. class CellException extends Error{errorSymbol;constructor(e,t="#ERROR"){super(e),this.errorSymbol=t}}class CellSyntaxException extends CellException{constructor(e,t="#SYNTAX"){super(e,t)}}class CellEvaluationException extends CellException{}class CellDependencyException extends CellException{constructor(e,t="#REF"){super(e,t)}}class CellExpressionTokenType{static Name=new this("Name");static Address=new this("Address");static NameOrAddress=new this("NameOrAddress");static String=new this("String");static Number=new this("Number");static OpenParen=new this("OpenParen");static CloseParen=new this("CloseParen");static Colon=new this("Colon");static Plus=new this("Plus");static Minus=new this("Minus");static Multiply=new this("Multiply");static Divide=new this("Divide");static Comma=new this("Comma");static Semicolon=new this("Semicolon");static Ampersand=new this("Ampersand");static LessThan=new this("LessThan");static LessThanEqual=new this("LessThanEqual");static GreaterThan=new this("GreaterThan");static GreaterThanEqual=new this("GreaterThanEqual");static Equal=new this("Equal");static Unequal=new this("Unequal");static Not=new this("Not");name;constructor(e){this.name=e}isPotentialName(){return this===CellExpressionTokenType.Name||this===CellExpressionTokenType.NameOrAddress}isPotentialAddress(){return this===CellExpressionTokenType.Address||this===CellExpressionTokenType.NameOrAddress}toString(){return this.name}equals(e){return e instanceof CellExpressionTokenType&&e.name===this.name}}class CellExpressionOperation{static Number=new this("Number");static String=new this("String");static Boolean=new this("Boolean");static Reference=new this("Reference");static Range=new this("Range");static Add=new this("Add");static Subtract=new this("Subtract");static Multiply=new this("Multiply");static Divide=new this("Divide");static Concatenate=new this("Concatenate");static UnaryMinus=new this("UnaryMinus");static GreaterThan=new this("GreaterThan");static GreaterThanEqual=new this("GreaterThanEqual");static LessThan=new this("LessThan");static LessThanEqual=new this("LessThanEqual");static Equal=new this("Equal");static Unequal=new this("Unequal");static UnaryNot=new this("UnaryNot");static Function=new this("Function");name;constructor(e){this.name=e}toString(){return`${this.constructor.name}.${this.name}`}equals(e){return e instanceof CellExpressionOperation&&e.name==this.name}}class CellExpressionSet{#e;constructor(e){this.#e=e}calculateCells(){const e=this.#e.rowCount,t=this.#e.columnCount;var n=[],l=new CellAddressRange(new CellAddress(0,0),new CellAddress(t-1,e-1));for(const e of l.cellsIn(this.#e)){const t=this.#e.cellAt(e),l=t.originalValue;if(l.type==CellValue.TYPE_FORMULA)try{const r=CellExpression.parse(l.formattedValue,e);if(!r)throw new CellSyntaxException("Invalid expression");t.parsedExpression=r,t.isCalculated=!0,n.push(e),this.#t(r,n)}catch(e){if(!(e instanceof CellSyntaxException||e instanceof CellEvaluationException))throw e;t.outputValue=CellValue.fromValue(e)}else t.outputValue=l,t.isCalculated=!1}this.#n(n),this.#l(n)}#n(e){for(var t=0;e.length>0&&t<e.length;){const n=e[0];e.splice(0,1);const l=this.#e.cellAt(n);try{const e=this.#r(l.parsedExpression,n);if(l.isCalculated=!0,e instanceof CellValue)l.outputValue=e,t=0;else{if(!Array.isArray(e))throw new CellEvaluationException(`Expression resolved to ${e&&e.constructor?e.constructor.name:typeof e}, expected CellValue`);if(1!=e.length)throw new CellEvaluationException(`Expression resolved to ${e.length} values, single value expected`);l.outputValue=e[0],t=0}}catch(r){if(r instanceof CellDependencyException)e.push(n),t++;else{if(!(r instanceof CellSyntaxException||r instanceof CellEvaluationException))throw r;l.outputValue=CellValue.fromValue(r),t=0}}}}#t(e,t){for(const n of e.fillRanges??[])for(const l of n.cellsIn(this.#e)){const n=this.#e.cellAt(l);n.originalValue.type!=CellValue.TYPE_BLANK||n.outputValue&&n.outputValue.type!=CellValue.TYPE_BLANK||(n.parsedExpression=e.transpose(e.location,l),n.isCalculated=!0,t.push(l))}}#l(e){for(const t of e){this.#e.cellAt(t).outputValue=CellValue.fromValue(new CellDependencyException(`Circular reference at ${t.name}`))}}#r(e,t){const n=this.#s(e,t);return n instanceof CellValue&&null!==e.outputType?CellValue.fromValue(n.value,e.outputType??n.type,e.outputDecimals):n}#s(e,t){switch(e.op){case CellExpressionOperation.Number:case CellExpressionOperation.String:case CellExpressionOperation.Boolean:return e.arguments[0];case CellExpressionOperation.Reference:{const t=e.arguments[0],n=this.#e.cellAt(t);if(null===n)throw new CellEvaluationException(`No cell at ${t.name}`,"#REF");if(null===n.outputValue)throw new CellDependencyException(`Need calculated value for ${t} to evaluate`);return n.outputValue}case CellExpressionOperation.Range:{const l=e.arguments[0];var n=[];for(const e of l.cellsIn(this.#e)){this.#e.cellAt(e);if(e.equals(t))continue;const l=this.#e.outputValueAt(e);if(null===l)throw new CellDependencyException(`Need calculated value for ${e.name} to evaluate`);n.push(l)}return n}case CellExpressionOperation.Add:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.add(l)}case CellExpressionOperation.Subtract:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.subtract(l)}case CellExpressionOperation.Multiply:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.multiply(l)}case CellExpressionOperation.Divide:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.divide(l)}case CellExpressionOperation.UnaryMinus:{const n=this.#r(e.arguments[0],t);return CellValue.fromValue(0).subtract(n)}case CellExpressionOperation.GreaterThan:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.gt(l)}case CellExpressionOperation.GreaterThanEqual:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.gte(l)}case CellExpressionOperation.LessThan:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.lt(l)}case CellExpressionOperation.LessThanEqual:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.lte(l)}case CellExpressionOperation.Equal:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.eq(l)}case CellExpressionOperation.Unequal:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.neq(l)}case CellExpressionOperation.UnaryNot:return this.#r(e.arguments[0],t).not();case CellExpressionOperation.Concatenate:{const n=this.#r(e.arguments[0],t),l=this.#r(e.arguments[1],t);return n.concatenate(l)}case CellExpressionOperation.Function:return this.#i(e.qualifier,e.arguments,t)}throw new CellSyntaxException(`Unhandled operation ${e.op.name}`)}#i(e,t,n){switch(e.toUpperCase()){case"ABS":return this.#a(t,n);case"AND":return this.#o(t,n);case"AVERAGE":return this.#u(t,n);case"CEILING":return this.#c(t,n);case"EXP":return this.#p(t,n);case"FLOOR":return this.#h(t,n);case"IF":return this.#E(t,n);case"IFS":return this.#C(t,n);case"ISBLANK":return this.#m(t,n);case"LN":return this.#f(t,n);case"LOG":return this.#d(t,n);case"LOWER":return this.#x(t,n);case"MAX":return this.#T(t,n);case"MIN":return this.#y(t,n);case"MOD":return this.#g(t,n);case"NOT":return this.#v(t,n);case"OR":return this.#w(t,n);case"POWER":return this.#V(t,n);case"ROUND":return this.#N(t,n);case"SQRT":return this.#R(t,n);case"SUBSTITUTE":return this.#P(t,n);case"SUM":return this.#A(t,n);case"UPPER":return this.#O(t,n);case"XOR":return this.#Y(t,n);default:throw new CellSyntaxException(`Unknown function "${e}"`)}}#_(e,t,n,l,r){const s=l.length;if(s<t||s>n){if(t==n)throw new CellSyntaxException(`${e}() expects ${t} arguments, got ${s}`);throw new CellSyntaxException(`${e}() expects between ${t} and ${n} arguments, got ${s}`)}var i=[];for(const t of l){const n=this.#r(t,r);if(!(n instanceof CellValue&&n.isNumeric()))throw new CellEvaluationException(`${e}() expects numeric arguments`);i.push(n)}return i}#k(e,t,n,l=!0){var r=[];for(const s of t){const t=this.#r(s,n);if(t instanceof CellValue){if(!t.isNumeric()){if(l)throw new CellEvaluationException(`${e} requires numeric arguments`);continue}r.push(t)}else if(Array.isArray(t)){const n=t;for(const t of n)if(t instanceof CellValue){if(!t.isNumeric()){if(l)throw new CellEvaluationException(`${e} requires numeric arguments`);continue}r.push(t)}}}return r}#a(e,t){const n=this.#_("ABS",1,1,e,t)[0];return n.value<0?CellValue.fromValue(0).subtract(n):n}#o(e,t){if(0==e.length)throw new CellEvaluationException("AND requires one or more arguments");const n=this.#k("AND",e,t,!1);for(const e of n){const t=e.booleanValue();if(null===t)throw new CellEvaluationException("AND requires boolean arguments");if(!t)return CellValue.fromValue(!1)}return CellValue.fromValue(!0)}#u(e,t){var n=CellValue.fromValue(0),l=0;for(const r of e){const e=this.#r(r,t);if(Array.isArray(e))for(const t of e)t.isNumeric()&&(n=n.add(t),l++);else e.isNumeric()&&(n=n.add(e),l++)}return l>0?n.divide(CellValue.fromValue(l)):CellValue.fromValue(0)}#c(e,t){const n=this.#_("CEILING",1,1,e,t)[0],l=Math.ceil(n.value);return CellValue.fromValue(l,n.type)}#p(e,t){const n=this.#_("EXP",1,1,e,t)[0],l=Math.exp(n.value);return CellValue.fromValue(l,n.type)}#h(e,t){const n=this.#_("FLOOR",1,1,e,t)[0],l=Math.floor(n.value);return CellValue.fromValue(l,n.type)}#E(e,t){if(3!=e.length)throw new CellEvaluationException("IF expects three arguments");const n=e.map((e=>this.#r(e,t))),l=n[0].booleanValue();if(null===l)throw new CellEvaluationException("IF expects a boolean for the first argument");return l?n[1]:n[2]}#C(e,t){if(e.length<3)throw new CellEvaluationException("IFS expects at least 3 arguments");if(e.length%2!=1)throw new CellEvaluationException("IFS expects an odd number of arguments");const n=e.map((e=>this.#r(e,t)));for(var l=0;l<n.length-1;l+=2){const e=n[l].booleanValue();if(null===e)throw new CellEvaluationException(`IFS expects a boolean for argument ${l+1}`);if(e)return n[l+1]}return n[n.length-1]}#m(e,t){if(1!==e.length)throw new CellEvaluationException("IFBLANK expects 1 argument");const n=this.#r(e[0],t);if(!(n instanceof CellValue))throw new CellEvaluationException("IFBLANK expcts 1 argument");return CellValue.fromValue(n.type===CellValue.TYPE_BLANK)}#f(e,t){const n=this.#_("LN",1,1,e,t)[0],l=Math.log(n.value);return CellValue.fromValue(l,n.type)}#d(e,t){const n=this.#_("LOG",1,2,e,t),l=n[0],r=n.length>1?n[1].value:10,s=Math.log(l.value)/Math.log(r);return CellValue.fromValue(s,l.type)}#x(e,t){if(1!=e.length)throw new CellEvaluationException("LOWER requires one argument");const n=e.map((e=>this.#r(e,t)))[0].stringValue(!0);if(null===n)throw new CellEvaluationException("LOWER requires one string argument");return CellValue.fromValue(n.toLowerCase())}#T(e,t){var n=null;const l=this.#k("MAX",e,t);if(0==l.length)throw new CellEvaluationException("MAX requires at least one numeric argument");for(const e of l)(null===n||e.value>n.value)&&(n=e);return n??CellValue.fromValue(0)}#y(e,t){var n=null;const l=this.#k("MIN",e,t);if(0==l.length)throw new CellEvaluationException("MIN requires at least one numeric argument");for(const e of l)(null===n||e.value<n.value)&&(n=e);return n??CellValue.fromValue(0)}#g(e,t){if(2!=e.length)throw new CellEvaluationException("MOD requires two numeric arguments");const n=e.map((e=>this.#r(e,t)));return n[0].modulo(n[1])}#v(e,t){if(1!=e.length)throw new CellEvaluationException("NOT expects one argument");const n=e.map((e=>this.#r(e,t)))[0].booleanValue();if(null===n)throw new CellEvaluationException("NOT expects boolean argument");return CellValue.fromValue(!n)}#w(e,t){if(0==e.length)throw new CellEvaluationException("OR requires one or more arguments");const n=this.#k("OR",e,t,!1);for(const e of n){const t=e.booleanValue();if(null===t)throw new CellEvaluationException("OR requires boolean arguments");if(t)return CellValue.fromValue(!0)}return CellValue.fromValue(!1)}#V(e,t){const n=this.#_("POWER",2,2,e,t),l=n[0],r=n[1],s=Math.pow(l.value,r.value);return CellValue.fromValue(s,l.type)}#N(e,t){const n=this.#_("ROUND",1,2,e,t),l=n[0],r=n.length>1?n[1].value:0,s=Math.pow(10,r),i=Math.round(l.value*s)/s;return CellValue.fromValue(i,l.type)}#R(e,t){const n=this.#_("SQRT",1,1,e,t)[0].numericValue();return CellValue.fromValue(Math.sqrt(n))}#P(e,t){if(3!=e.length)throw new CellEvaluationException("SUBSTITUTE expects 3 string arguments");const n=e.map((e=>this.#r(e,t))),l=n[0].stringValue(),r=n[1].stringValue(),s=n[2].stringValue();if(null===l||null===r||null===s)throw new CellEvaluationException("SUBSTITUTE expects 3 string arguments");const i=l.replace(new RegExp(MDUtils.escapeRegex(r),"gi"),s);return CellValue.fromValue(i)}#A(e,t){var n=CellValue.fromValue(0);for(const l of e){const e=this.#r(l,t);if(Array.isArray(e))for(const t of e)t.isNumeric()&&(n=n.add(t));else e.isNumeric()&&(n=n.add(e))}return n}#O(e,t){if(1!=e.length)throw new CellEvaluationException("UPPER requires one argument");const n=e.map((e=>this.#r(e,t)))[0].stringValue(!0);if(null===n)throw new CellEvaluationException("UPPER requires one string argument");return CellValue.fromValue(n.toUpperCase())}#Y(e,t){if(0==e.length)throw new CellEvaluationException("XOR requires one or more arguments");const n=this.#k("XOR",e,t,!1);var l=null;for(const e of n){const t=e.booleanValue();if(null===t)throw new CellEvaluationException("XOR requires boolean arguments");l=null===l?t:l^t}return CellValue.fromValue(0!=l)}}class CellExpression{op;arguments;qualifier;outputType=null;outputDecimals=null;fillRanges=null;location=null;constructor(e,t,n=null){this.op=e,this.arguments=t,this.qualifier=n}static parse(e,t){const n=this.expressionToTokens(e);if(0==n.length)return null;const l=this.expressionFromTokens(n,t);return l.location=t,l}static dumpExpression(e,t=""){if(0==e.arguments.length)console.error(t+"expr "+e.op.name+"()");else{console.error(t+e.op.name+"(");for(const n of e.arguments)"number"==typeof n?console.error(t+`\t${n}`):"string"==typeof n?console.error(t+`\t"${n}"`):"boolean"==typeof n?console.error(t+"\t"+(n?"true":"false")):n instanceof CellAddress||n instanceof CellAddressRange?console.error(t+"\t"+n.name):n instanceof CellValue?console.error(t+"\t"+n.type+" "+n.formattedValue):n instanceof CellExpression?this.dumpExpression(n,t+"\t"):console.error(t+"\t"+typeof n);console.error(t+")")}}#S(){const e=new CellExpression;return e.op=this.op,e.arguments=this.arguments.slice(),e.qualifier=this.qualifier,e.outputType=this.outputType,e.outputDecimals=this.outputDecimals,e.fillRanges=null!==this.fillRanges?this.fillRanges.slice():null,e.location=this.location,e}transpose(e,t){var n=this.#S();n.arguments=[];for(const l of this.arguments)l instanceof CellExpression||l instanceof CellAddress||l instanceof CellAddressRange?n.arguments.push(l.transpose(e,t)):n.arguments.push(l);return n}static expressionToTokens(e){var t=[],n=[0];this.#I(e,n),"="==e.substring(n[0],n[0]+1)&&n[0]++,this.#I(e,n);for(var l=e.length;n[0]<l;)t.push(this.#L(e,n)),this.#I(e,n);return t}static#L(e,t){var n;if(n=this.#U(e,t,"==",CellExpressionTokenType.Equal))return n;if(n=this.#U(e,t,"!=",CellExpressionTokenType.Unequal))return n;if(n=this.#U(e,t,"<=",CellExpressionTokenType.LessThanEqual))return n;if(n=this.#U(e,t,">=",CellExpressionTokenType.GreaterThanEqual))return n;if(n=this.#U(e,t,"<",CellExpressionTokenType.LessThan))return n;if(n=this.#U(e,t,">",CellExpressionTokenType.GreaterThan))return n;if(n=this.#U(e,t,"!",CellExpressionTokenType.Not))return n;if(n=this.#U(e,t,"+",CellExpressionTokenType.Plus))return n;if(n=this.#U(e,t,"-",CellExpressionTokenType.Minus))return n;if(n=this.#U(e,t,"*",CellExpressionTokenType.Multiply))return n;if(n=this.#U(e,t,"/",CellExpressionTokenType.Divide))return n;if(n=this.#U(e,t,",",CellExpressionTokenType.Comma))return n;if(n=this.#U(e,t,"(",CellExpressionTokenType.OpenParen))return n;if(n=this.#U(e,t,")",CellExpressionTokenType.CloseParen))return n;if(n=this.#U(e,t,":",CellExpressionTokenType.Colon))return n;if(n=this.#U(e,t,";",CellExpressionTokenType.Semicolon))return n;if(n=this.#U(e,t,"&",CellExpressionTokenType.Ampersand))return n;if(n=this.#b(e,t))return n;if(n=this.#M(e,t))return n;if(n=this.#B(e,t))return n;if(n=this.#F(e,t))return n;throw new CellSyntaxException(`Unexpected character "${e.substring(t[0],t[0]+1)}" at ${t[0]}`)}static#I(e,t){const n=e.length;for(;t[0]<n;){const n=e.substring(t[0],t[0]+1);if(" "!=n&&"\t"!=n&&"\n"!=n&&"\r"!=n)return;t[0]++}}static#U(e,t,n,l){const r=e.length-t[0],s=n.length;if(s>r)return null;const i=e.substring(t[0],t[0]+s);return i.toUpperCase()!=n.toUpperCase()?null:(t[0]+=s,new CellExpressionToken(l,i))}static#b(e,t){var n=[t[0]],l=e.substring(n[0],n[0]+1),r="",s=!0;"$"==l&&(r+=l,s=!1,n[0]++);var i=this.#q(e,n,(e=>this.#$(e)),1,2);if(null===i)return null;if(r+=i,"$"==(l=e.substring(n[0],n[0]+1))){r+=l,s=!1,n[0]++;const t=this.#q(e,n,this.#D,1);if(null===t)return null;r+=t}else{const t=this.#q(e,n,this.#D,0);if(null===t)return null;r+=t}return t[0]=n[0],new CellExpressionToken(s?CellExpressionTokenType.NameOrAddress:CellExpressionTokenType.Address,r)}static#M(e,t){var n=[t[0]];const l=this.#q(e,n,(e=>this.#$(e)),1);return null===l?null:(t[0]=n[0],CellAddress.isAddress(l)?new CellExpressionToken(CellExpressionTokenType.NameOrAddress,l):new CellExpressionToken(CellExpressionTokenType.Name,l))}static#B(e,t){var n=e.substring(t[0],t[0]+1);if(!this.#D(n))return null;const l=e.length;var r=n;for(t[0]++;t[0]<l&&(n=e.substring(t[0],t[0]+1),this.#D(n));)t[0]++,r+=n;if(t[0]<l&&"."==(n=e.substring(t[0],t[0]+1)))for(r+=n,t[0]++;t[0]<l&&(n=e.substring(t[0],t[0]+1),this.#D(n));)t[0]++,r+=n;return new CellExpressionToken(CellExpressionTokenType.Number,r)}static#F(e,t){var n=e.substring(t[0],t[0]+1);if('"'!==n)return null;var l="";t[0]++;const r=e.length;for(var s=!1;t[0]<r;)if(n=e.substring(t[0],t[0]+1),t[0]++,s){if(s=!1,"\\"!=n&&'"'!=n)throw new CellSyntaxException(`Bad string escape sequence "\\${n}"`);l+=n}else if("\\"==n)s=!0;else{if('"'==n)return new CellExpressionToken(CellExpressionTokenType.String,l);l+=n}throw new CellSyntaxException("Unterminated string")}static#q(e,t,n,l=null,r=null){var s=t[0];const i=e.length;for(var a="",o=0;s<i&&(null===r||o<r);){const t=e.substring(s,s+1);if(!n(t))break;a+=t,o++,s++}return s<i&&n(e.substring(s,s+1))||null!==l&&o<l?null:(t[0]=s,a)}static#$(e){const t=e.codePointAt(0);return t>=65&&t<=90||t>=97&&t<=122}static#D(e){const t=e.codePointAt(0);return t>=48&&t<=57}static expressionFromTokens(e,t){var n;return(n=this.#G(e,0,e.length-1,t))||(n=this.#K(e,0,e.length-1,t))||(n=this.#W(e,0,e.length-1,t))?n:null}static#G(e,t,n,l){for(var r=t+1;r<n;r++)if(e[r].type==CellExpressionTokenType.Semicolon){const s=this.#K(e,t,r-1,l)??this.#W(e,t,r-1,l);if(null===s)return null;const i=this.#X(e,r+1,n,l);return null===i?null:([s.outputType,s.outputDecimals]=i,s)}return null}static#K(e,t,n,l){if(n-t+1<2)return null;if(!e[n].type.isPotentialName())return null;if("FILL"!=e[n].content.toUpperCase())return null;const r=this.#W(e,t,n-1,l),s=l.columnIndex;return r.fillRanges=[new CellAddressRange(new CellAddress(s,-1),new CellAddress(s,-1))],r}static#X(e,t,n,l){const r=n-t+1;if(r<0||r>2)return null;if(!e[t].type.isPotentialName())return null;const s=e[t].content.toLowerCase();if(!CellValue.isTypeNumeric(s))return null;var i;if(r>1){if(e[t+1].type!=CellExpressionTokenType.Number)return null;i=parseInt(e[t+1].content)}else i=null;return[s,i]}static#W(e,t,n,l){var r;if(r=this.#Q(e,t,n,l))return r;if(r=this.#z(e,t,n,l))return r;if(r=this.#Z(e,t,n,l))return r;if(r=this.#j(e,t,n,l))return r;if(r=this.#H(e,t,n,l))return r;if(r=this.#J(e,t,n,l))return r;if(r=this.#ee(e,t,n,l))return r;if(r=this.#te(e,t,n,l))return r;if(r=this.#ne(e,t,n,l))return r;throw new CellSyntaxException("Invalid expression")}static#Q(e,t,n,l){if(e[t].type!=CellExpressionTokenType.OpenParen)return null;if(e[n].type!=CellExpressionTokenType.CloseParen)return null;for(var r=0,s=t+1;s<n;s++)if(e[s].type==CellExpressionTokenType.OpenParen?r++:e[s].type==CellExpressionTokenType.CloseParen&&r--,r<0)return null;return 0!=r?null:this.#W(e,t+1,n-1,l)}static#z(e,t,n,l){if(e[n].type!=CellExpressionTokenType.Number)return null;if(n>t+1)return null;const r=CellValue.fromCellString(e[n].content);if(n>t){if(e[t].type!=CellExpressionTokenType.Minus)return null;r.value=-r.value}return new CellExpression(CellExpressionOperation.Number,[r])}static#Z(e,t,n,l){if(t!=n)return null;if(e[t].type!=CellExpressionTokenType.String)return null;const r=e[t].content;return new CellExpression(CellExpressionOperation.String,[new CellValue(r,r,CellValue.TYPE_STRING,0)])}static#j(e,t,n,l){if(t!=n)return null;if(!e[t].type.isPotentialName())return null;const r=e[t].content.toUpperCase();return"TRUE"!=r&&"FALSE"!=r?null:new CellExpression(CellExpressionOperation.Boolean,[new CellValue(r,"TRUE"==r,CellValue.TYPE_BOOLEAN)])}static#H(e,t,n,l){if(n-t+1<3)return null;if(!e[t].type.isPotentialName())return null;const r=e[t].content;if(e[t+1].type!=CellExpressionTokenType.OpenParen)return null;if(e[n].type!=CellExpressionTokenType.CloseParen)return null;const s=this.#le(e,t+2,n-1,l);return null===s?null:new CellExpression(CellExpressionOperation.Function,s,r)}static#le(e,t,n,l){if(0==n-t+1)return[];var r=0;for(var s=[],i=t,a=t;a<=n;a++)if(e[a].type==CellExpressionTokenType.OpenParen)r++;else if(e[a].type==CellExpressionTokenType.CloseParen)r--;else if(e[a].type==CellExpressionTokenType.Comma&&0==r){const e=a-1;s.push([i,e]),i=a+1}s.push([i,n]);var o=[];for(const t of s){const n=this.#W(e,t[0],t[1],l);if(null===n)return null;o.push(n)}return o}static#J(e,t,n,l){if(3!=n-t+1)return null;if(!e[t].type.isPotentialAddress())return null;const r=e[t].content.toUpperCase();if(e[t+1].type!=CellExpressionTokenType.Colon)return null;if(!e[n].type.isPotentialAddress())return null;const s=e[n].content.toUpperCase(),i=CellAddress.fromString(r),a=CellAddress.fromString(s),o=new CellAddressRange(i,a);return new CellExpression(CellExpressionOperation.Range,[o])}static#ee(e,t,n,l){if(t!=n)return null;if(!e[t].type.isPotentialAddress())return null;const r=e[t].content.toUpperCase(),s=CellAddress.fromString(r,l,!0);return new CellExpression(CellExpressionOperation.Reference,[s])}static#re={};static{this.#re[CellExpressionTokenType.Minus.name]=1,this.#re[CellExpressionTokenType.Plus.name]=2,this.#re[CellExpressionTokenType.Divide.name]=3,this.#re[CellExpressionTokenType.Multiply.name]=4,this.#re[CellExpressionTokenType.Ampersand.name]=10,this.#re[CellExpressionTokenType.GreaterThan.name]=20,this.#re[CellExpressionTokenType.GreaterThanEqual.name]=20,this.#re[CellExpressionTokenType.LessThan.name]=20,this.#re[CellExpressionTokenType.LessThanEqual.name]=20,this.#re[CellExpressionTokenType.Equal.name]=20,this.#re[CellExpressionTokenType.Unequal.name]=20}static#te(e,t,n,l){if(n-t+1<3)return null;var r,s=[],i=0;for(r=t;r<=n;r++)if(e[r].type==CellExpressionTokenType.OpenParen)i++;else if(e[r].type==CellExpressionTokenType.CloseParen)i--;else if(0==i&&r>t&&r<n){const t=e[r].type.name,n=this.#re[t]??!1;if(!1===n)continue;s.push({priority:n,i:r})}s.sort(((e,t)=>e.priority-t.priority));var a,o,u=null;for(const i of s)try{if(r=i.i,null===(a=this.#W(e,t,r-1,l)))continue;if(null===(o=this.#W(e,r+1,n,l)))continue;u=i;break}catch(e){if(!(e instanceof CellSyntaxException))throw e}if(null===u)return null;switch(r=u.i,e[u.i].type){case CellExpressionTokenType.Plus:return new CellExpression(CellExpressionOperation.Add,[a,o]);case CellExpressionTokenType.Minus:return new CellExpression(CellExpressionOperation.Subtract,[a,o]);case CellExpressionTokenType.Multiply:return new CellExpression(CellExpressionOperation.Multiply,[a,o]);case CellExpressionTokenType.Divide:return new CellExpression(CellExpressionOperation.Divide,[a,o]);case CellExpressionTokenType.GreaterThan:return new CellExpression(CellExpressionOperation.GreaterThan,[a,o]);case CellExpressionTokenType.GreaterThanEqual:return new CellExpression(CellExpressionOperation.GreaterThanEqual,[a,o]);case CellExpressionTokenType.LessThan:return new CellExpression(CellExpressionOperation.LessThan,[a,o]);case CellExpressionTokenType.LessThanEqual:return new CellExpression(CellExpressionOperation.LessThanEqual,[a,o]);case CellExpressionTokenType.Equal:return new CellExpression(CellExpressionOperation.Equal,[a,o]);case CellExpressionTokenType.Unequal:return new CellExpression(CellExpressionOperation.Unequal,[a,o]);case CellExpressionTokenType.Ampersand:return new CellExpression(CellExpressionOperation.Concatenate,[a,o])}return null}static#ne(e,t,n,l){if(n-t+1<2)return null;const r=[[CellExpressionTokenType.Minus,CellExpressionOperation.UnaryMinus],[CellExpressionTokenType.Not,CellExpressionOperation.UnaryNot]];for(const s of r){if(e[t].type!=s[0])continue;const r=this.#W(e,t+1,n,l);return null===r?null:new CellExpression(s[1],[r])}return null}}class CellExpressionToken{type;content;constructor(e,t){this.type=e,this.content=t}}class CellAddress{get name(){return this.#se}#se;get isColumnFixed(){return this.#ie}#ie=!1;get columnIndex(){return this.#ae}#ae=-1;get columnLetter(){return CellAddress.#oe(this.#ae)}get isRowFixed(){return this.#ue}#ue=!1;get rowIndex(){return this.#ce}#ce=-1;get rowNumber(){return this.#ce+1}get isResolved(){return this.columnIndex>=0&&this.rowIndex>=0}constructor(e,t,n=!1,l=!1){if("number"!=typeof e)throw new Error("columnIndex must be number, got "+typeof e);if("number"!=typeof t)throw new Error("rowIndex must be number, got "+typeof t);this.#ae=e,this.#ce=t,this.#ie=n,this.#ue=l,this.#se=CellAddress.#pe(e,t,n,l)}static isAddress(e){return null!=this.fromString(e)}transpose(e,t,n=!0){if(!e.isResolved||!t.isResolved)throw new CellEvaluationException("Can only transpose to and from resolved addresses");var l=this.columnIndex;if(!this.isColumnFixed){l+=t.columnIndex-e.columnIndex}var r=this.rowIndex;if(!this.isResolved&&n&&(r=e.rowIndex),-1!=r&&!this.isRowFixed){r+=t.rowIndex-e.rowIndex}return l<0||r<0?null:new CellAddress(l,r)}equals(e){return e instanceof CellAddress&&(e.columnIndex==this.columnIndex&&e.rowIndex==this.rowIndex)}exactlyEquals(e){return e instanceof CellAddress&&e.name==this.name}toString(){return this.name}static#he(e){const t="A".codePointAt(0);for(var n=0,l=e.length-1;l>=0;l--){n=26*n+(e.codePointAt(l)-t)}return n}static#oe(e){var t="";if(e>=0){const l="A".codePointAt(0);var n=e;do{t=String.fromCodePoint(l+n%26)+t,n=Math.floor(n/26)}while(n>0)}return t}static#pe(e,t,n,l){var r="";return n&&e>=0&&(r+="$"),e>=0&&(r+=this.#oe(e)),l&&t>=0&&(r+="$"),t>=0&&(r+=`${t+1}`),r}static fromString(e,t=null,n=!1){const l=/^(\$?)([A-Z]{1,2}?)((?:\$(?=[0-9]))?)([0-9]*)$/i.exec(e);if(null===l){if(n)throw new CellEvaluationException(`Bad address "${e}"`,"#REF");return null}const r="$"==l[1],s=l[2].toUpperCase(),i="$"==l[3],a=l[4];var o=this.#he(s),u=0==a.length?-1:parseInt(a)-1;return o<0&&null!=t&&(o=t.columnIndex),u<0&&null!=t&&(u=t.rowIndex),new CellAddress(o,u,r,i)}}class CellAddressRange{isResolved;minColumnIndex;maxColumnIndex;minRowIndex;maxRowIndex;name;constructor(e,t){if(e.isResolved!=t.isResolved)throw new CellEvaluationException(`Cannot mix resolved and unresolved cell addresses in range: ${e.name} and ${t.name}`);this.minColumnIndex=Math.min(e.columnIndex,t.columnIndex),this.maxColumnIndex=Math.max(e.columnIndex,t.columnIndex),this.minRowIndex=Math.min(e.rowIndex,t.rowIndex),this.maxRowIndex=Math.max(e.rowIndex,t.rowIndex),this.isResolved=e.isResolved,this.name=new CellAddress(this.minColumnIndex,this.minRowIndex).name+":"+new CellAddress(this.maxColumnIndex,this.maxRowIndex).name}cellsIn(e){const t=this.minColumnIndex<0?0:this.minColumnIndex,n=this.maxColumnIndex<0?e.columnCount-1:Math.min(this.maxColumnIndex,e.columnCount-1),l=this.minRowIndex<0?0:this.minRowIndex,r=this.maxRowIndex<0?e.rowCount-1:Math.min(this.maxRowIndex,e.rowCount-1),s={};return s[Symbol.iterator]=function(){var e=t,s=l;return{next(){const t=e,i=s++;return s>r&&(s=l,e++),{value:new CellAddress(t,i),done:t>n||i>r}}}},s}}class CellValue{static TYPE_BLANK="blank";static TYPE_CURRENCY="currency";static TYPE_NUMBER="number";static TYPE_PERCENT="percent";static TYPE_STRING="string";static TYPE_BOOLEAN="boolean";static TYPE_ERROR="error";static TYPE_FORMULA="formula";static BLANK=new CellValue("",null,CellValue.TYPE_BLANK);type=CellValue.TYPE_STRING;decimals=0;formattedValue="";value=null;constructor(e,t=null,n=CellValue.TYPE_STRING,l=0){this.formattedValue=e,this.value=t,this.type=n,this.decimals=l}isNumeric(){return CellValue.isTypeNumeric(this.type)}static fromCellString(e){const t=new CellValue(e);return t.#Ee(e),t}static fromValue(e,t=null,n=null){if(null===e)return new CellValue("",null,CellValue.TYPE_BLANK);if(e instanceof Error)return new CellValue(e instanceof CellException?e.errorSymbol:"#ERROR",e.message,CellValue.TYPE_ERROR);if("boolean"==typeof e){const t=CellValue.formatType(e,CellValue.TYPE_BOOLEAN,0);return new CellValue(t,e,CellValue.TYPE_BOOLEAN)}if("number"==typeof e){const l=t||CellValue.TYPE_NUMBER,r=null!==n?n:l==CellValue.TYPE_CURRENCY?2:CellValue.#Ce(l==CellValue.TYPE_PERCENT?100*e:e),s=CellValue.formatType(e,l,r);return new CellValue(s,e,l,r)}if("string"!=typeof e)throw new CellEvaluationException(`Value of type ${typeof e} unsupported`);const l=e.trim();return l.startsWith("=")?new CellValue(l,l,CellValue.TYPE_FORMULA):new CellValue(l,l,CellValue.TYPE_STRING)}#Ee(e){if(e=null!==e?e.trim():null,this.formattedValue=e,null===e||""==e)return this.type=CellValue.TYPE_BLANK,void(this.value=null);if(e.startsWith("'")){const t=e.substring(1).trim();return this.type=CellValue.TYPE_STRING,this.formattedValue=t,void(this.value=t)}const t=e.toUpperCase();if("TRUE"==t)return this.type=CellValue.TYPE_BOOLEAN,this.formattedValue=t,this.value=!0,void(this.formattedValue="TRUE");if("FALSE"==t)return this.type=CellValue.TYPE_BOOLEAN,this.formattedValue=t,this.value=!1,void(this.formattedValue="FALSE");if(e.startsWith("="))return this.type=CellValue.TYPE_FORMULA,void(this.value=e);var n;if(n=/^([-]?)\$(-?[0-9,]*\.)([0-9]+)$/.exec(e)){const e=n[1],t=n[2].replace(/,/g,""),l=n[3];return this.type=CellValue.TYPE_CURRENCY,this.decimals=2,this.value=parseFloat(e+t+l),void(this.formattedValue=CellValue.#me(this.value,this.decimals))}if(n=/^([-]?)\$(-?[0-9,]+)$/.exec(e)){const e=n[1],t=n[2].replace(/,/g,"");return this.type=CellValue.TYPE_CURRENCY,this.decimals=0,this.value=parseFloat(e+t),void(this.formattedValue=CellValue.#me(this.value,this.decimals))}if(n=/^([-]?[0-9,]*\.)([0-9,]+)%$/.exec(e)){const e=n[1].replace(/,/,""),t=n[2];return this.type=CellValue.TYPE_PERCENT,this.decimals=t.length,this.value=parseFloat(e+t)/100,void(this.formattedValue=CellValue.#fe(this.value,this.decimals))}if(n=/^([-]?[0-9,]+)%$/.exec(e)){const e=n[1].replace(/,/g,"");return this.type=CellValue.TYPE_PERCENT,this.decimals=0,this.value=parseFloat(e)/100,void(this.formattedValue=CellValue.#fe(this.value,this.decimals))}if(n=/^([-]?[0-9,]*\.)([0-9]+)$/.exec(e)){const e=n[1].replace(/,/g,""),t=n[2];return this.type=CellValue.TYPE_NUMBER,this.decimals=t.length,this.value=parseFloat(e+t),void(this.formattedValue=CellValue.#de(this.value,this.decimals))}if(n=/^([-]?[0-9,]+)$/.exec(e)){const e=n[1].replace(/,/g,"");return this.type=CellValue.TYPE_NUMBER,this.decimals=0,this.value=parseFloat(e),void(this.formattedValue=CellValue.#de(this.value,this.decimals))}this.type=CellValue.TYPE_STRING,this.value=e}booleanValue(){switch(this.type){case CellValue.TYPE_BLANK:return!1;case CellValue.TYPE_BOOLEAN:return this.value;case CellValue.TYPE_CURRENCY:case CellValue.TYPE_NUMBER:case CellValue.TYPE_PERCENT:return 0!=this.value;case CellValue.TYPE_ERROR:case CellValue.TYPE_FORMULA:case CellValue.TYPE_STRING:return null}}numericValue(){switch(this.type){case CellValue.TYPE_BLANK:return 0;case CellValue.TYPE_BOOLEAN:return this.value?1:0;case CellValue.TYPE_CURRENCY:case CellValue.TYPE_NUMBER:case CellValue.TYPE_PERCENT:return this.value;case CellValue.TYPE_ERROR:case CellValue.TYPE_FORMULA:case CellValue.TYPE_STRING:return null}}stringValue(e=!1){switch(this.type){case CellValue.TYPE_BLANK:return"";case CellValue.TYPE_BOOLEAN:return this.value?"TRUE":"FALSE";case CellValue.TYPE_CURRENCY:case CellValue.TYPE_NUMBER:case CellValue.TYPE_PERCENT:return e?this.formattedValue:`${this.value}`;case CellValue.TYPE_STRING:return e?this.formattedValue:this.value;case CellValue.TYPE_ERROR:case CellValue.TYPE_FORMULA:return null}}add(e){return CellValue.#xe(this,e,"+",((e,t)=>e+t))}subtract(e){return CellValue.#xe(this,e,"-",((e,t)=>e-t))}multiply(e){return CellValue.#xe(this,e,"*",((e,t)=>e*t))}divide(e){return CellValue.#xe(this,e,"/",((e,t)=>{if(0==t)throw new CellEvaluationException("Division by zero","#NAN");return e/t}))}modulo(e){return CellValue.#xe(this,e,"%",((e,t)=>{if(0==t)throw new CellEvaluationException("Division by zero","#NAN");return e%t}))}gt(e){return CellValue.fromValue(CellValue.#Te(this,e)>0)}gte(e){return CellValue.fromValue(CellValue.#Te(this,e)>=0)}lt(e){return CellValue.fromValue(CellValue.#Te(this,e)<0)}lte(e){return CellValue.fromValue(CellValue.#Te(this,e)<=0)}eq(e){return CellValue.fromValue(0==CellValue.#Te(this,e))}neq(e){return CellValue.fromValue(0!=CellValue.#Te(this,e))}not(){switch(this.type){case CellValue.TYPE_BLANK:return CellValue.fromValue(!0);case CellValue.TYPE_CURRENCY:case CellValue.TYPE_NUMBER:case CellValue.TYPE_PERCENT:return CellValue.fromValue(0==this.value);case CellValue.TYPE_STRING:throw new CellEvaluationException("Cannot perform NOT on string");case CellValue.TYPE_BOOLEAN:return CellValue.fromValue(!this.value);case CellValue.TYPE_ERROR:throw this.value;case CellValue.TYPE_FORMULA:throw new CellEvaluationException("Cannot perform NOT on expression")}}concatenate(e){const t=this.stringValue(!0),n=e.stringValue(!0);if(null===t||null===n)throw new CellEvaluationException("Concatenation requires string arguments");return CellValue.fromValue(`${t}${n}`)}static#xe(e,t,n,l){const r=this.#ye(e,t,n),s=r[0],i=r[1],a=r[2],o=l(s,i);return CellValue.fromValue(o,a)}static#ye(e,t,n){if(e.type==this.TYPE_ERROR)throw e.value;if(t.type==this.TYPE_ERROR)throw t.value;if(e.type==this.TYPE_STRING||t.type==this.TYPE_STRING)throw new CellEvaluationException("Cannot perform math on text values");if(e.type==this.TYPE_BLANK)return t.type==this.TYPE_BLANK?[0,0,this.TYPE_NUMBER,0]:[0,t.value,t.type];if(t.type==this.TYPE_BLANK)return[e.value,0,e.type];const l="*"==n||"/"==n||"%"==n;if(e.type==t.type)return[e.value,t.value,e.type];switch(e.type+t.type){case this.TYPE_CURRENCY+this.TYPE_NUMBER:case this.TYPE_CURRENCY+this.TYPE_PERCENT:return[e.value,t.value,this.TYPE_CURRENCY];case this.TYPE_PERCENT+this.TYPE_CURRENCY:return[e.value,t.value,l?this.TYPE_CURRENCY:this.TYPE_PERCENT];case this.TYPE_PERCENT+this.TYPE_NUMBER:return[e.value,t.value,l?this.TYPE_NUMBER:this.TYPE_PERCENT];case this.TYPE_NUMBER+this.TYPE_CURRENCY:return[e.value,t.value,t.type];case this.TYPE_NUMBER+this.TYPE_PERCENT:return[e.value,t.value,l?this.TYPE_NUMBER:t.type];case this.TYPE_BOOLEAN+this.TYPE_CURRENCY:case this.TYPE_BOOLEAN+this.TYPE_NUMBER:case this.TYPE_BOOLEAN+this.TYPE_PERCENT:return[e.value?1:0,t.value,t.type];case this.TYPE_CURRENCY+this.TYPE_BOOLEAN:case this.TYPE_NUMBER+this.TYPE_BOOLEAN:case this.TYPE_PERCENT+this.TYPE_BOOLEAN:return[e.value,t.value?1:0,e.type]}throw new CellEvaluationException(`Unhandled operand types "${e.type}" and "${t.type}"`)}static#Te(e,t){const n=CellValue.#ge(e,t),l=n[0],r=n[1];return"string"==typeof l?l.localeCompare(r,void 0,{sensitivity:"accent"}):l<r?-1:l>r?1:0}static#ge(e,t){if(e.type==CellValue.TYPE_ERROR)throw e.value;if(t.type==CellValue.TYPE_ERROR)throw t.value;if(e.type==CellValue.TYPE_FORMULA)throw new CellEvaluationException("Can't compare formula values");if(t.type==CellValue.TYPE_FORMULA)throw new CellEvaluationException("Can't compare formula values");const n=e.value,l=t.value,r=`${e.value}`,s=`${t.value}`;switch(e.type){case CellValue.TYPE_BLANK:n=0,r="";break;case CellValue.TYPE_BOOLEAN:n=n?1:0}switch(t.type){case CellValue.TYPE_BLANK:l=0,s="";break;case CellValue.TYPE_BOOLEAN:l=l?1:0}return e.type==CellValue.TYPE_STRING||t.type==CellValue.TYPE_STRING?[r,s]:[n,l]}static formatType(e,t,n){switch(t){case CellValue.TYPE_BLANK:return"";case CellValue.TYPE_CURRENCY:return CellValue.#me(e,n);case CellValue.TYPE_NUMBER:return CellValue.#de(e,n);case CellValue.TYPE_PERCENT:return CellValue.#fe(e,n);case CellValue.TYPE_BOOLEAN:return e?"TRUE":"FALSE";case CellValue.TYPE_STRING:case CellValue.TYPE_FORMULA:return`${e}`}}static#de(e,t){return e.toLocaleString(void 0,{minimumFractionDigits:t,maximumFractionDigits:t})}static#me(e,t){var n=e.toLocaleString(void 0,{minimumFractionDigits:t,maximumFractionDigits:t});return n.startsWith("-")?"-$"+n.substring(1):"$"+n}static#fe(e,t){return(100*e).toLocaleString(void 0,{minimumFractionDigits:t,maximumFractionDigits:t})+"%"}static#Ce(e,t=6){if(e instanceof CellValue)return CellValue.#Ce(e.value);if("number"==typeof e){var n=e.toLocaleString(void 0,{maximumFractionDigits:t});if(null===/\./.exec(n))return 0;var l=n.split(".")[1];return Math.min(t,l.length)}return 0}static isTypeNumeric(e){return e==CellValue.TYPE_NUMBER||e==CellValue.TYPE_PERCENT||e==CellValue.TYPE_CURRENCY||e==CellValue.TYPE_BOOLEAN}toString(){return`[CellValue type=${this.type} value=${this.value} "${this.formattedValue}"]`}}class SpreadsheetGrid{cells;columnCount;rowCount;constructor(e,t){this.columnCount=e,this.rowCount=t,this.cells=new Array(e);for(var n=0;n<e;n++){this.cells[n]=new Array(t);for(var l=0;l<t;l++)this.cells[n][l]=new SpreadsheetCell}}cellAt(e){const t=e.columnIndex,n=e.rowIndex;if(t<0||t>=this.cells.length)throw new CellEvaluationException(`Unresolved cell address ${e.name}`,"#REF");const l=this.cells[t];if(n<0||n>=l.length)throw new CellEvaluationException(`Unresolved cell address ${e.name}`,"#REF");return l[n]}valueAt(e){return this.cellAt(e)?.originalValue}outputValueAt(e){return this.cellAt(e)?.outputValue}}class SpreadsheetCell{originalValue=CellValue.BLANK;outputValue=null;isCalculated=!1;parsedExpression=null;get resolvedValue(){return this.outputValue??this.originalValue}}class MDSpreadsheetReader extends MDReader{preProcess(e){for(const t of e.readersByBlockPriority)t instanceof MDTableReader&&(t.preferFormulas=!0)}postProcess(e,t){for(const n of t)n instanceof MDTableNode&&this.#ve(n,e)}#ve(e,t){const n=e.bodyRows.length;var l=0;for(const t of e.bodyRows)l=Math.max(l,t.children.length);const r=new SpreadsheetGrid(l,n);for(var s=0;s<l;s++)for(var i=0;i<n;i++){const n=e.bodyCellAt(s,i);if(null===n)continue;const l=n.toPlaintext(t);r.cells[s][i].originalValue=CellValue.fromCellString(l)}new CellExpressionSet(r).calculateCells();var a=!1;for(s=0;s<l&&!a;s++)for(i=0;i<n;i++)if(r.cellAt(new CellAddress(s,i)).isCalculated){a=!0;break}if(a)for(s=0;s<l;s++)for(i=0;i<n;i++){const n=e.bodyCellAt(s,i),l=r.cellAt(new CellAddress(s,i));null!==n&&null!==l&&this.#we(n,l,t,s,i)}}#we(e,t,n,l,r){const s=t.outputValue;if(null===s)return;const i=e.toPlaintext(n).trim(),a=s.formattedValue;a!=i&&(this.#Ve(e,i,a)||(e.children=[new MDTextNode(a)])),t.isCalculated&&e.cssClasses.push("calculated"),e.cssClasses.push(`spreadsheet-type-${s.type}`),s.type==CellValue.TYPE_ERROR&&(e.attributes.title=s.value);const o=s.numericValue();null!==o&&(e.attributes["data-numeric-value"]=`${o}`);const u=s.stringValue(!1);null!==u&&(e.attributes["data-string-value"]=u)}#Ve(e,t,n){if(e instanceof MDTextNode&&e.text.trim()===t.trim())return e.text=n,!0;for(const l of e.children)if(this.#Ve(l,t,n))return!0;return!1}}